Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat(infra): add method for disposing the notify icon from system tray

Lars Berger0cab72c6a869
diff --git a/GlazeWM.Infrastructure/WindowsApi/SystemTrayService.cs b/GlazeWM.Infrastructure/WindowsApi/SystemTrayService.cs
index 3104d444..d8e429e4 100644
--- a/GlazeWM.Infrastructure/WindowsApi/SystemTrayService.cs
+++ b/GlazeWM.Infrastructure/WindowsApi/SystemTrayService.cs
@@ -1,16 +1,17 @@
-using GlazeWM.Infrastructure.Bussing;
-using System;
+using System;
using System.Drawing;
-using System.Windows.Forms;
+using System.Reflection;
using System.Threading;
+using System.Windows.Forms;
+using GlazeWM.Infrastructure.Bussing;
using GlazeWM.Infrastructure.WindowsApi.Events;
-using System.Reflection;
namespace GlazeWM.Infrastructure.WindowsApi
{
public class SystemTrayService
{
private readonly Bus _bus;
+ private NotifyIcon _notifyIcon { get; set; }
public SystemTrayService(Bus bus)
{
@@ -38,7 +39,7 @@ namespace GlazeWM.Infrastructure.WindowsApi
// Get the embedded icon resource from the entry assembly.
using (var stream = assembly.GetManifestResourceStream(iconResourceName))
{
- var notificationIcon = new NotifyIcon
+ _notifyIcon = new NotifyIcon
{
Icon = new Icon(stream),
ContextMenuStrip = contextMenuStrip,
@@ -53,8 +54,12 @@ namespace GlazeWM.Infrastructure.WindowsApi
private void SignalApplicationExit(object sender, EventArgs e)
{
- // TODO: Call `Dispose()` on `notificationIcon`.
_bus.RaiseEvent(new ApplicationExitingEvent());
}
+
+ public void RemoveFromSystemTray()
+ {
+ _notifyIcon?.Dispose();
+ }
}
}