瀏覽代碼

feat: Support different tray icon for linux

MystiPanda 1 年之前
父節點
當前提交
9af1f90990

+ 0 - 0
src-tauri/icons/win-tray-icon-activated.png → src-tauri/icons/tray-icon-activated.png


+ 0 - 0
src-tauri/icons/win-tray-icon-tun.png → src-tauri/icons/tray-icon-tun.png


二進制
src-tauri/icons/tray-icon.png


二進制
src-tauri/icons/win-tray-icon.png


+ 9 - 14
src-tauri/src/core/tray.rs

@@ -135,21 +135,18 @@ impl Tray {
         let system_proxy = verge.enable_system_proxy.as_ref().unwrap_or(&false);
         let tun_mode = verge.enable_tun_mode.as_ref().unwrap_or(&false);
 
-        #[cfg(target_os = "windows")]
-        {
-            let mut indication_icon = if *system_proxy {
-                include_bytes!("../../icons/win-tray-icon-activated.png").to_vec()
-            } else {
-                include_bytes!("../../icons/win-tray-icon.png").to_vec()
-            };
-
-            if *tun_mode {
-                indication_icon = include_bytes!("../../icons/win-tray-icon-tun.png").to_vec();
-            }
+        let mut indication_icon = if *system_proxy {
+            include_bytes!("../../icons/tray-icon-activated.png").to_vec()
+        } else {
+            include_bytes!("../../icons/tray-icon.png").to_vec()
+        };
 
-            let _ = tray.set_icon(tauri::Icon::Raw(indication_icon));
+        if *tun_mode {
+            indication_icon = include_bytes!("../../icons/tray-icon-tun.png").to_vec();
         }
 
+        let _ = tray.set_icon(tauri::Icon::Raw(indication_icon));
+
         let _ = tray.get_item("system_proxy").set_selected(*system_proxy);
         let _ = tray.get_item("tun_mode").set_selected(*tun_mode);
 
@@ -160,7 +157,6 @@ impl Tray {
             map
         };
 
-        #[cfg(not(target_os = "linux"))]
         let _ = tray.set_tooltip(&format!(
             "Clash Verge {version}\n{}: {}\n{}: {}",
             t!("System Proxy", "系统代理"),
@@ -185,7 +181,6 @@ impl Tray {
 
     pub fn on_system_tray_event(app_handle: &AppHandle, event: SystemTrayEvent) {
         match event {
-            #[cfg(not(target_os = "linux"))]
             SystemTrayEvent::LeftClick { .. } => Tray::on_left_click(app_handle),
             SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
                 mode @ ("rule_mode" | "global_mode" | "direct_mode" | "script_mode") => {

+ 1 - 31
src-tauri/tauri.conf.json

@@ -10,13 +10,8 @@
     "beforeBuildCommand": "pnpm run web:build"
   },
   "tauri": {
-    "systemTray": {
-      "iconPath": "icons/tray-icon.ico",
-      "iconAsTemplate": true
-    },
     "bundle": {
       "active": true,
-      "targets": ["deb", "appimage", "nsis", "app", "dmg", "updater"],
       "identifier": "io.github.clash-verge-rev.clash-verge-rev",
       "icon": [
         "icons/32x32.png",
@@ -30,32 +25,7 @@
       "copyright": "© 2022 zzzgydi All Rights Reserved",
       "category": "DeveloperTool",
       "shortDescription": "A Clash Meta GUI based on tauri.",
-      "longDescription": "A Clash Meta GUI based on tauri.",
-      "deb": {
-        "depends": ["openssl"]
-      },
-      "macOS": {
-        "frameworks": [],
-        "minimumSystemVersion": "",
-        "exceptionDomain": "",
-        "signingIdentity": null,
-        "entitlements": null
-      },
-      "windows": {
-        "certificateThumbprint": null,
-        "digestAlgorithm": "sha256",
-        "timestampUrl": "",
-        "webviewInstallMode": {
-          "type": "embedBootstrapper",
-          "silent": true
-        },
-        "nsis": {
-          "displayLanguageSelector": true,
-          "installerIcon": "icons/icon.ico",
-          "languages": ["SimpChinese", "English"],
-          "license": "../LICENSE"
-        }
-      }
+      "longDescription": "A Clash Meta GUI based on tauri."
     },
     "updater": {
       "active": true,

+ 13 - 0
src-tauri/tauri.linux.conf.json

@@ -0,0 +1,13 @@
+{
+  "tauri": {
+    "systemTray": {
+      "iconPath": "icons/tray-icon.png"
+    },
+    "bundle": {
+      "targets": ["deb", "appimage", "updater"],
+      "deb": {
+        "depends": ["openssl"]
+      }
+    }
+  }
+}

+ 18 - 0
src-tauri/tauri.macos.conf.json

@@ -0,0 +1,18 @@
+{
+  "tauri": {
+    "systemTray": {
+      "iconPath": "icons/tray-icon.ico",
+      "iconAsTemplate": true
+    },
+    "bundle": {
+      "targets": ["app", "dmg", "updater"],
+      "macOS": {
+        "frameworks": [],
+        "minimumSystemVersion": "",
+        "exceptionDomain": "",
+        "signingIdentity": null,
+        "entitlements": null
+      }
+    }
+  }
+}

+ 25 - 0
src-tauri/tauri.windows.conf.json

@@ -0,0 +1,25 @@
+{
+  "tauri": {
+    "systemTray": {
+      "iconPath": "icons/tray-icon.png"
+    },
+    "bundle": {
+      "targets": ["nsis", "updater"],
+      "windows": {
+        "certificateThumbprint": null,
+        "digestAlgorithm": "sha256",
+        "timestampUrl": "",
+        "webviewInstallMode": {
+          "type": "embedBootstrapper",
+          "silent": true
+        },
+        "nsis": {
+          "displayLanguageSelector": true,
+          "installerIcon": "icons/icon.ico",
+          "languages": ["SimpChinese", "English"],
+          "license": "../LICENSE"
+        }
+      }
+    }
+  }
+}