added reload config, and show config buttons to the context menu

This commit is contained in:
2026-01-19 03:39:12 +01:00
parent 81d6bced05
commit 3fc15c85d3

View File

@@ -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();