From 574a6a769115034f37bdecf3284545d74843816a Mon Sep 17 00:00:00 2001
From: chunhualin1 <chunhualin1@lenovo.com>
Date: 星期三, 12 八月 2026 15:21:41 +0800
Subject: [PATCH] 添加显示器切换兼容处理
---
src/Moli.Desktop/Tray/TrayShell.cs | 33 ++++++++++++++++++++++++++++++++-
1 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/src/Moli.Desktop/Tray/TrayShell.cs b/src/Moli.Desktop/Tray/TrayShell.cs
index 8590d6f..8d86d03 100644
--- a/src/Moli.Desktop/Tray/TrayShell.cs
+++ b/src/Moli.Desktop/Tray/TrayShell.cs
@@ -44,7 +44,7 @@
{
_notifyIcon = new Forms.NotifyIcon
{
- Icon = Drawing.SystemIcons.Application,
+ Icon = LoadTrayIcon(),
Text = "Moli Desktop",
Visible = true,
ContextMenuStrip = BuildMenu()
@@ -157,4 +157,35 @@
}
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;
+ }
}
--
Gitblit v1.9.1