From 97df0fb5ed49e37d1c8e0e62057bb72ba5c9eb6a Mon Sep 17 00:00:00 2001
From: chunhualin1 <chunhualin1@lenovo.com>
Date: 星期三, 12 八月 2026 17:24:49 +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