GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
fix(infra): use icon resource from entry assembly as system tray icon
Lars Berger013dbab2f381
diff --git a/GlazeWM.Bootstrapper/Startup.cs b/GlazeWM.Bootstrapper/Startup.csindex 0d3b9874..1a80a76e 100644--- a/GlazeWM.Bootstrapper/Startup.cs+++ b/GlazeWM.Bootstrapper/Startup.cs@@ -67,7 +67,7 @@ namespace GlazeWM.Bootstrapper// Listen for window events (eg. close, focus)._windowEventService.Start();- _systemTrayService.AddToSystemTray("icon.ico");+ _systemTrayService.AddToSystemTray();_bus.Events.Where(@event => @event is ApplicationExitingEvent).Subscribe((@event) => OnApplicationExit());diff --git a/GlazeWM.Infrastructure/WindowsApi/SystemTrayService.cs b/GlazeWM.Infrastructure/WindowsApi/SystemTrayService.csindex 79d7d155..e5d25fc0 100644--- a/GlazeWM.Infrastructure/WindowsApi/SystemTrayService.cs+++ b/GlazeWM.Infrastructure/WindowsApi/SystemTrayService.cs@@ -4,6 +4,8 @@ using System.Drawing;using System.Windows.Forms;using System.Threading;using GlazeWM.Infrastructure.WindowsApi.Events;+using System.Reflection;+using System.IO;namespace GlazeWM.Infrastructure.WindowsApi{@@ -16,27 +18,34 @@ namespace GlazeWM.Infrastructure.WindowsApi_bus = bus;}- public void AddToSystemTray(string iconPath)+ public void AddToSystemTray(){- var thread = new Thread(() => PopulateSystemTray(iconPath));+ var thread = new Thread(() => PopulateSystemTray());thread.Name = "GlazeWMSystemTray";thread.Start();}- private void PopulateSystemTray(string iconPath)+ private void PopulateSystemTray(){var contextMenuStrip = new ContextMenuStrip();contextMenuStrip.Items.Add("Exit", null, SignalApplicationExit);- var notificationIcon = new NotifyIcon()- {- Icon = new Icon(iconPath),- ContextMenuStrip = contextMenuStrip,- Text = "GlazeWM"- };+ var assembly = Assembly.GetEntryAssembly();+ var iconResourceName = "GlazeWM.Bootstrapper.icon.ico";- notificationIcon.Visible = true;+ // Get the embedded icon resource from the entry assembly.+ using (Stream stream = assembly.GetManifestResourceStream(iconResourceName))+ {+ var notificationIcon = new NotifyIcon()+ {+ Icon = new Icon(stream),+ ContextMenuStrip = contextMenuStrip,+ Text = "GlazeWM"+ };++ notificationIcon.Visible = true;+ }// System tray requires a message loop within the thread that is executing the code.Application.Run();