2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-07-01 16:33:43 -04:00

Add event-based LogMonitor state changes to better handle batch reads (#59)

* Add event-based LogMonitor state changes to better handle batch reads

Pre-reading hackily used read-all to suppress notifications. But that broke some assumptions about what read-all meant. Furthermore, the Core UI told plugins about read-all rather than the log monitor telling them -- which is really what should be telling them.

To address these concerns, LogMonitor now provides an event that both the PluginCore and PluginEventHandler listens to or tracking logging state allowing more granular information about the activities of LogMonitor, including distinguishing between ReadAll and Pre-read batches. Plugins no longer need to track if LogMonitor is in batch-read mode or not -- PluginCore now provides it. 

I've also converted all built-in plugins to use the new event-based system. The old system is marked deprecated and will go away once other known contributed plugins have converted to the new system.

* Change LogMonitorState enum to [Flags], drop 'None' state

As requested, and did associated simplifications and cleanup that followed.
This commit is contained in:
F K
2022-03-03 15:09:49 -05:00
committed by GitHub
parent 7c54d6dd65
commit 4f4ba88878
9 changed files with 150 additions and 43 deletions

View File

@ -29,7 +29,6 @@ namespace Observatory.Botanist
> BioPlanets;
ObservableCollection<object> GridCollection;
private PluginUI pluginUI;
private bool readAllInProgress = false;
private Guid? samplerStatusNotification = null;
private BotanistSettings botanistSettings = new()
{
@ -102,7 +101,7 @@ namespace Observatory.Botanist
{
case ScanOrganicType.Log:
case ScanOrganicType.Sample:
if (!readAllInProgress && botanistSettings.OverlayEnabled)
if (!Core.IsLogMonitorBatchReading && botanistSettings.OverlayEnabled)
{
NotificationArgs args = new()
{
@ -171,22 +170,24 @@ namespace Observatory.Botanist
Core = observatoryCore;
}
public void ReadAllStarted()
public void LogMonitorStateChanged(LogMonitorStateChangedEventArgs args)
{
readAllInProgress = true;
Core.ClearGrid(this, new BotanistGrid());
}
public void ReadAllFinished()
{
readAllInProgress = false;
UpdateUIGrid();
if (LogMonitorStateChangedEventArgs.IsBatchRead(args.NewState))
{
// Beginning a batch read. Clear grid.
Core.ClearGrid(this, new BotanistGrid());
}
else if (LogMonitorStateChangedEventArgs.IsBatchRead(args.PreviousState))
{
// Batch read is complete. Show data.
UpdateUIGrid();
}
}
private void UpdateUIGrid()
{
// Suppress repainting the entire contents of the grid on every ScanOrganic record we read.
if (readAllInProgress) return;
if (Core.IsLogMonitorBatchReading) return;
BotanistGrid uiObject = new();
Core.ClearGrid(this, uiObject);