| | |
| | | { |
| | | _notifyIcon = new Forms.NotifyIcon |
| | | { |
| | | Icon = Drawing.SystemIcons.Application, |
| | | Icon = LoadTrayIcon(), |
| | | Text = "Moli Desktop", |
| | | Visible = true, |
| | | ContextMenuStrip = BuildMenu() |
| | |
| | | } |
| | | |
| | | private static string TrimForTray(string text) => text.Length <= 63 ? text : text[..63]; |
| | | |
| | | private static Drawing.Icon LoadTrayIcon() |
| | | { |
| | | try |
| | | { |
| | | var iconPath = Path.Combine(AppContext.BaseDirectory, "Assets", "Moli.Desktop.ico"); |
| | | if (File.Exists(iconPath)) |
| | | { |
| | | return new Drawing.Icon(iconPath); |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | // Fall back to the embedded executable icon below. |
| | | } |
| | | |
| | | try |
| | | { |
| | | var executablePath = Environment.ProcessPath; |
| | | if (!string.IsNullOrWhiteSpace(executablePath) && File.Exists(executablePath)) |
| | | { |
| | | return Drawing.Icon.ExtractAssociatedIcon(executablePath) ?? Drawing.SystemIcons.Application; |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | // Last resort keeps the tray available even if icon loading fails. |
| | | } |
| | | |
| | | return Drawing.SystemIcons.Application; |
| | | } |
| | | } |