diff --git a/analog_system_monitor_dotnet/TrayApp.cs b/analog_system_monitor_dotnet/TrayApp.cs index 0995cb0..6394f7d 100644 --- a/analog_system_monitor_dotnet/TrayApp.cs +++ b/analog_system_monitor_dotnet/TrayApp.cs @@ -1,7 +1,9 @@ #nullable enable using System; +using System.Diagnostics; using System.Drawing; +using System.IO; using System.Windows.Forms; using Microsoft.Win32; @@ -25,7 +27,19 @@ public class TrayApp : ApplicationContext }; var menu = new ContextMenuStrip(); + + // Show config.json + menu.Items.Add("Show Config", null, OnShowConfig); + + // Reload config + menu.Items.Add("Reload Config", null, OnReloadConfig); + + // Separator + menu.Items.Add(new ToolStripSeparator()); + + // Exit menu.Items.Add("Exit", null, OnExit); + trayIcon.ContextMenuStrip = menu; // Main telemetry timer @@ -65,6 +79,66 @@ public class TrayApp : ApplicationContext } } + // Show config.json in Explorer + private void OnShowConfig(object? sender, EventArgs e) + { + try + { + string exeDir = AppContext.BaseDirectory; + string cfgPath = Path.Combine(exeDir, "config.json"); + + if (File.Exists(cfgPath)) + { + Process.Start("explorer.exe", $"/select,\"{cfgPath}\""); + } + else + { + MessageBox.Show( + "config.json not found.", + "Show Config", + MessageBoxButtons.OK, + MessageBoxIcon.Warning + ); + } + } + catch (Exception ex) + { + MessageBox.Show( + $"Failed to open config.json:\n{ex.Message}", + "Show Config Error", + MessageBoxButtons.OK, + MessageBoxIcon.Error + ); + } + } + + // Reload config handler + private void OnReloadConfig(object? sender, EventArgs e) + { + try + { + telemetry.Dispose(); + telemetry = new Telemetry(); + telemetry.Initialize(); + + MessageBox.Show( + "Configuration reloaded successfully.", + "Reload Config", + MessageBoxButtons.OK, + MessageBoxIcon.Information + ); + } + catch (Exception ex) + { + MessageBox.Show( + $"Failed to reload configuration:\n{ex.Message}", + "Reload Config Error", + MessageBoxButtons.OK, + MessageBoxIcon.Error + ); + } + } + private void OnExit(object? sender, EventArgs e) { telemetry.Dispose();