From bc45d28f264bdedfd307baf2340fcd6cc22c6d26 Mon Sep 17 00:00:00 2001 From: beo3000 Date: Fri, 26 Jun 2026 08:29:54 +0200 Subject: [PATCH] fix(tray): load icon from embedded resource stream so it actually shows icon.ico is a WPF embedded in the assembly, but the code loaded it from the filesystem (AppContext.BaseDirectory) where no copy exists -> FileNotFoundException, silently swallowed by the catch -> blank tray icon. Load via pack:// resource stream instead. Also log the failure to Debug output instead of swallowing it silently. Co-Authored-By: Claude Opus 4.8 --- tools/JournalBot.Tray/App.xaml.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/JournalBot.Tray/App.xaml.cs b/tools/JournalBot.Tray/App.xaml.cs index e4bda34..174eba8 100644 --- a/tools/JournalBot.Tray/App.xaml.cs +++ b/tools/JournalBot.Tray/App.xaml.cs @@ -33,12 +33,18 @@ public partial class App : Application _tray = new TaskbarIcon { ToolTipText = "JournalBot" }; try { - _tray.Icon = new System.Drawing.Icon( - Path.Combine(AppContext.BaseDirectory, "icon.ico")); + // icon.ico is embedded as a WPF Resource (see .csproj), so load it + // from the resource stream — not the filesystem, which would fail + // because no icon.ico is copied next to the EXE. + var uri = new Uri("pack://application:,,,/icon.ico", UriKind.Absolute); + using var stream = Application.GetResourceStream(uri).Stream; + _tray.Icon = new System.Drawing.Icon(stream); } - catch + catch (Exception ex) { // Missing/corrupt icon must not prevent startup; tray still works. + // Don't swallow silently — a blank tray icon is otherwise a mystery. + System.Diagnostics.Debug.WriteLine($"Tray icon load failed: {ex}"); } _tray.TrayLeftMouseUp += (_, _) => ToggleWindow(); _tray.ContextMenu = BuildMenu();