diff --git a/ObservatoryCore/LogMonitor.cs b/ObservatoryCore/LogMonitor.cs index fd57421..7282314 100644 --- a/ObservatoryCore/LogMonitor.cs +++ b/ObservatoryCore/LogMonitor.cs @@ -146,7 +146,9 @@ namespace Observatory // We found an FSD jump, buffered the lines for that system (possibly including startup logs // over a file boundary). Pump these through the plugins. + readall = true; ReportErrors(ProcessLines(lastSystemLines, "Pre-read")); + readall = false; } #endregion diff --git a/ObservatoryCore/UI/ViewModels/CoreViewModel.cs b/ObservatoryCore/UI/ViewModels/CoreViewModel.cs index 3b8f166..62458e0 100644 --- a/ObservatoryCore/UI/ViewModels/CoreViewModel.cs +++ b/ObservatoryCore/UI/ViewModels/CoreViewModel.cs @@ -55,21 +55,15 @@ namespace Observatory.UI.ViewModels public void ReadAll() { - foreach (var worker in workers) - { - worker.ReadAllStarted(); - } + SetWorkerReadAllState(true); LogMonitor.GetInstance.ReadAllJournals(); - foreach (var worker in workers) - { - worker.ReadAllFinished(); - } + SetWorkerReadAllState(false); } public void ToggleMonitor() { var logMonitor = LogMonitor.GetInstance; - + if (logMonitor.IsMonitoring()) { logMonitor.Stop(); @@ -77,7 +71,10 @@ namespace Observatory.UI.ViewModels } else { + // HACK: Find a better way of suppressing notifications when pre-reading. + SetWorkerReadAllState(true); logMonitor.Start(); + SetWorkerReadAllState(false); ToggleButtonText = "Stop Monitor"; } } @@ -123,5 +120,20 @@ namespace Observatory.UI.ViewModels { get { return tabs; } } + private void SetWorkerReadAllState(bool isReadingAll) + { + foreach (var worker in workers) + { + if (isReadingAll) + { + worker.ReadAllStarted(); + } + else + { + worker.ReadAllFinished(); + } + } + } + } } diff --git a/ObservatoryCore/UI/Views/BasicUIView.axaml.cs b/ObservatoryCore/UI/Views/BasicUIView.axaml.cs index 7d407b0..05378c8 100644 --- a/ObservatoryCore/UI/Views/BasicUIView.axaml.cs +++ b/ObservatoryCore/UI/Views/BasicUIView.axaml.cs @@ -10,6 +10,7 @@ using Avalonia.Interactivity; using Avalonia.VisualTree; using System; using System.Collections.ObjectModel; +using System.Collections.Generic; namespace Observatory.UI.Views { @@ -252,6 +253,12 @@ namespace Observatory.UI.Views Binding = new Binding("Name") }); + pluginList.Columns.Add(new DataGridTextColumn() + { + Header = "Types", + Binding = new Binding("TypesString") + }); + pluginList.Columns.Add(new DataGridTextColumn() { Header = "Version", @@ -264,19 +271,29 @@ namespace Observatory.UI.Views Binding = new Binding("Status") }); - System.Collections.Generic.List allPlugins = new(); - + Dictionary uniquePlugins = new(); foreach(var (plugin, signed) in pluginManager.workerPlugins) { - allPlugins.Add(new PluginView() { Name = plugin.Name, Version = plugin.Version, Status = GetStatusText(signed) }); + if (!uniquePlugins.ContainsKey(plugin.Name)) + { + uniquePlugins.Add(plugin.Name, + new PluginView() { Name = plugin.Name, Types = new() { PluginType.Worker }, Version = plugin.Version, Status = GetStatusText(signed) }); + } } foreach (var (plugin, signed) in pluginManager.notifyPlugins) { - allPlugins.Add(new PluginView() { Name = plugin.Name, Version = plugin.Version, Status = GetStatusText(signed) }); + if (!uniquePlugins.ContainsKey(plugin.Name)) + { + uniquePlugins.Add(plugin.Name, + new PluginView() { Name = plugin.Name, Types = new() { PluginType.Notifier }, Version = plugin.Version, Status = GetStatusText(signed) }); + } else + { + uniquePlugins[plugin.Name].Types.Add(PluginType.Notifier); + } } - pluginList.Items = allPlugins; + pluginList.Items = uniquePlugins.Values; corePanel.AddControl(pluginList, SettingRowTracker.PLUGIN_LIST_ROW_INDEX, 0, 2); #endregion @@ -324,10 +341,13 @@ namespace Observatory.UI.Views { if (setting.Key.PropertyType != typeof(bool) || settingsGrid.Children.Count % 2 == 0) { - settingsGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(21) }); + settingsGrid.RowDefinitions.Add(new RowDefinition() + { + Height = new GridLength(setting.Key.PropertyType != typeof(bool) ? 32 : 25), + }); } - TextBlock label = new() { Text = setting.Value }; + TextBlock label = new() { Text = setting.Value, VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center }; switch (setting.Key.GetValue(plugin.Settings)) { @@ -351,13 +371,30 @@ namespace Observatory.UI.Views break; case string stringSetting: TextBox textBox = new() { Text = stringSetting }; - settingsGrid.Children.Add(label); - settingsGrid.Children.Add(textBox); + settingsGrid.AddControl(label, settingsGrid.RowDefinitions.Count - 1, 0); + settingsGrid.AddControl(textBox, settingsGrid.RowDefinitions.Count - 1, 1); + textBox.TextInput += (object sender, Avalonia.Input.TextInputEventArgs e) => + { + setting.Key.SetValue(plugin.Settings, e.Text); + PluginManagement.PluginManager.GetInstance.SaveSettings(plugin, plugin.Settings); + }; break; case int intSetting: - NumericUpDown numericUpDown = new() { Text = intSetting.ToString(), AllowSpin = true }; - settingsGrid.Children.Add(label); - settingsGrid.Children.Add(numericUpDown); + NumericUpDown numericUpDown = new() { Value = intSetting, AllowSpin = true }; + SettingNumericBounds attr = (SettingNumericBounds)System.Attribute.GetCustomAttribute(setting.Key, typeof(SettingNumericBounds)); + if (attr != null) + { + numericUpDown.Minimum = attr.Minimum; + numericUpDown.Maximum = attr.Maximum; + numericUpDown.Increment = attr.Increment; + } + settingsGrid.AddControl(label, settingsGrid.RowDefinitions.Count - 1, 0); + settingsGrid.AddControl(numericUpDown, settingsGrid.RowDefinitions.Count - 1, 1); + numericUpDown.ValueChanged += (object sender, NumericUpDownValueChangedEventArgs e) => + { + setting.Key.SetValue(plugin.Settings, Convert.ToInt32(e.NewValue)); + PluginManagement.PluginManager.GetInstance.SaveSettings(plugin, plugin.Settings); + }; break; case System.IO.FileInfo fileSetting: label.Text += ": "; @@ -404,7 +441,7 @@ namespace Observatory.UI.Views stackPanel.Children.Add(label); stackPanel.Children.Add(settingPath); - settingsGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(21) }); + settingsGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(32) }); settingsGrid.AddControl(stackPanel, settingsGrid.RowDefinitions.Count - 1, 0, 2); settingsGrid.AddControl(settingBrowse, settingsGrid.RowDefinitions.Count - 1, 2); @@ -415,6 +452,11 @@ namespace Observatory.UI.Views } } + private void TextBox_TextInput(object sender, Avalonia.Input.TextInputEventArgs e) + { + throw new NotImplementedException(); + } + private string GetStatusText(PluginManagement.PluginManager.PluginStatus status) { string statusText; @@ -462,12 +504,22 @@ namespace Observatory.UI.Views internal class PluginView { public string Name { get; set; } + public HashSet Types { get; set; } + public string TypesString { + get + { + return string.Join(", ", Types); + } + set { } } public string Version { get; set; } public string Status { get; set; } } - - + enum PluginType + { + Worker, + Notifier, + } internal static class GridExtention {