diff --git a/SoraV2Utils_Agent/Program.cs b/SoraV2Utils_Agent/Program.cs index 8938e16..fc70e56 100644 --- a/SoraV2Utils_Agent/Program.cs +++ b/SoraV2Utils_Agent/Program.cs @@ -28,7 +28,7 @@ namespace SoraV2Utils_Agent System.Environment.Exit(1); }; ; - var trayicon = new TrayIcon(); + var trayicon = new TrayIconForm(); trayicon.Display(); } } diff --git a/SoraV2Utils_Agent/TrayIcon.cs b/SoraV2Utils_Agent/TrayIcon.cs deleted file mode 100644 index 925ec65..0000000 --- a/SoraV2Utils_Agent/TrayIcon.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Drawing; -using System.Threading; - -namespace SoraV2Utils_Agent -{ - public class TrayIcon - { - public TrayIcon() - { - // Create a NotifyIcon instance - using (NotifyIcon trayIcon = new NotifyIcon()) - { - // Set up the tray icon properties - trayIcon.Icon = new Icon(SystemIcons.WinLogo, 40, 40); // Choose your own icon - trayIcon.Visible = true; - - // Create a context menu - var contextMenu = new ContextMenu(); - - // Add a non-clickable dynamic text item - var batteryLevelItem = new MenuItem("Battery Level: Loading..."); - var batteryRuntimeItem = new MenuItem("Battery Runtime: Loading..."); - batteryLevelItem.Enabled = false; - batteryRuntimeItem.Enabled = false; - - contextMenu.MenuItems.Add("Exit", (sender, e) => ServiceIPC.Instance.Exit()); - contextMenu.MenuItems.Add("Check for Update ", (sender, e) => UpdateCheck.CheckUpdate()); - - contextMenu.MenuItems.Add(batteryLevelItem); - contextMenu.MenuItems.Add(batteryRuntimeItem); - - trayIcon.ContextMenu = contextMenu; - - // Update the dynamic text in the context menu - ThreadPool.QueueUserWorkItem(state => - { - while (true) - { - // Format battery level with charging status - string batteryLevelText = ServiceIPC.DeviceStatus.Charging == 1 - ? $"Battery Level: {ServiceIPC.DeviceStatus.Battery} (Charging...)" - : $"Battery Level: {ServiceIPC.DeviceStatus.Battery}"; - - // Format battery runtime (convert minutes to hours and minutes) - string batteryRuntimeText = FormatBatteryRuntime(ServiceIPC.BatteryRuntime); - - // Update the context menu items - batteryLevelItem.Text = batteryLevelText; - batteryRuntimeItem.Text = $"Battery Runtime: {batteryRuntimeText}"; - batteryRuntimeItem.Text = $"Battery Runtime: {batteryRuntimeText}"; - - // Update every second - Thread.Sleep(1000); - } - }); - - Application.Run(); - } - } - - // Formats the runtime in hours and minutes. - private string FormatBatteryRuntime(double runtimeInMinutes) - { - if(runtimeInMinutes < 0) - { - return "No data yet"; - } - - int hours = (int)(runtimeInMinutes / 60); - int minutes = (int)(runtimeInMinutes % 60); - - // If runtime is greater than 1 hour, display hours and minutes - if (hours > 0) - { - return $"{hours} hour{(hours > 1 ? "s" : "")} {minutes} minute{(minutes > 1 ? "s" : "")}"; - } - else - { - return $"{minutes} minute{(minutes > 1 ? "s" : "")}"; - } - } - - public void Display() - { - } - } -}