fix(tray): load icon from embedded resource stream so it actually shows

icon.ico is a WPF <Resource> 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 <noreply@anthropic.com>
This commit is contained in:
beo3000 2026-06-26 08:29:54 +02:00
parent d2f8319772
commit bc45d28f26
1 changed files with 9 additions and 3 deletions

View File

@ -33,12 +33,18 @@ public partial class App : Application
_tray = new TaskbarIcon { ToolTipText = "JournalBot" }; _tray = new TaskbarIcon { ToolTipText = "JournalBot" };
try try
{ {
_tray.Icon = new System.Drawing.Icon( // icon.ico is embedded as a WPF Resource (see .csproj), so load it
Path.Combine(AppContext.BaseDirectory, "icon.ico")); // 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. // 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.TrayLeftMouseUp += (_, _) => ToggleWindow();
_tray.ContextMenu = BuildMenu(); _tray.ContextMenu = BuildMenu();