diff --git a/UPDATELOG.md b/UPDATELOG.md index 8ab3adc..c085612 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -12,6 +12,8 @@ ## v1.5.2 +--- + ### Features - 支持自定义延迟测试超时时间 diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 518cea9..3eab496 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -39,7 +39,7 @@ serde = { version = "1.0", features = ["derive"] } reqwest = { version = "0.11", features = ["json", "rustls-tls"] } sysproxy = { git="https://github.com/zzzgydi/sysproxy-rs", branch = "main" } auto-launch = { git="https://github.com/zzzgydi/auto-launch", branch = "main" } -tauri = { version = "1.5", features = [ "dialog-open", "notification-all", "icon-png", "clipboard-all", "global-shortcut-all", "process-all", "shell-all", "system-tray", "updater", "window-all"] } +tauri = { version = "1.5", features = [ "protocol-asset", "dialog-open", "notification-all", "icon-png", "clipboard-all", "global-shortcut-all", "process-all", "shell-all", "system-tray", "updater", "window-all"] } [target.'cfg(windows)'.dependencies] runas = "=1.0.0" # 高版本会返回错误 Status diff --git a/src-tauri/src/config/verge.rs b/src-tauri/src/config/verge.rs index 0cdf678..8899552 100644 --- a/src-tauri/src/config/verge.rs +++ b/src-tauri/src/config/verge.rs @@ -36,6 +36,13 @@ pub struct IVerge { /// show memory info (only for Clash Meta) pub enable_memory_usage: Option, + /// common tray icon + pub common_tray_icon: Option, + + pub sysproxy_tray_icon: Option, + + pub tun_tray_icon: Option, + /// clash tun mode pub enable_tun_mode: Option, @@ -204,6 +211,9 @@ impl IVerge { patch!(startup_script); patch!(traffic_graph); patch!(enable_memory_usage); + patch!(common_tray_icon); + patch!(sysproxy_tray_icon); + patch!(tun_tray_icon); patch!(enable_tun_mode); patch!(enable_service_mode); diff --git a/src-tauri/src/core/tray.rs b/src-tauri/src/core/tray.rs index 193830a..aeb74f7 100644 --- a/src-tauri/src/core/tray.rs +++ b/src-tauri/src/core/tray.rs @@ -129,26 +129,47 @@ impl Tray { let verge = verge.latest(); let system_proxy = verge.enable_system_proxy.as_ref().unwrap_or(&false); let tun_mode = verge.enable_tun_mode.as_ref().unwrap_or(&false); + let common_tray_icon = verge.common_tray_icon.clone().unwrap_or("".to_string()); + let sysproxy_tray_icon = verge.sysproxy_tray_icon.clone().unwrap_or("".to_string()); + let tun_tray_icon = verge.tun_tray_icon.clone().unwrap_or("".to_string()); let mut indication_icon = if *system_proxy { #[cfg(not(target_os = "macos"))] - let icon = include_bytes!("../../icons/tray-icon-sys.png").to_vec(); + let mut icon = include_bytes!("../../icons/tray-icon-sys.png").to_vec(); #[cfg(target_os = "macos")] - let icon = include_bytes!("../../icons/mac-tray-icon-sys.png").to_vec(); + let mut icon = include_bytes!("../../icons/mac-tray-icon-sys.png").to_vec(); + if !sysproxy_tray_icon.is_empty() { + let path = std::path::Path::new(&sysproxy_tray_icon); + if path.exists() { + icon = std::fs::read(path).unwrap(); + } + } icon } else { #[cfg(not(target_os = "macos"))] - let icon = include_bytes!("../../icons/tray-icon.png").to_vec(); + let mut icon = include_bytes!("../../icons/tray-icon.png").to_vec(); #[cfg(target_os = "macos")] - let icon = include_bytes!("../../icons/mac-tray-icon.png").to_vec(); + let mut icon = include_bytes!("../../icons/mac-tray-icon.png").to_vec(); + if !common_tray_icon.is_empty() { + let path = std::path::Path::new(&common_tray_icon); + if path.exists() { + icon = std::fs::read(path).unwrap(); + } + } icon }; if *tun_mode { #[cfg(not(target_os = "macos"))] - let icon = include_bytes!("../../icons/tray-icon-tun.png").to_vec(); + let mut icon = include_bytes!("../../icons/tray-icon-tun.png").to_vec(); #[cfg(target_os = "macos")] - let icon = include_bytes!("../../icons/mac-tray-icon-tun.png").to_vec(); + let mut icon = include_bytes!("../../icons/mac-tray-icon-tun.png").to_vec(); + if !tun_tray_icon.is_empty() { + let path = std::path::Path::new(&tun_tray_icon); + if path.exists() { + icon = std::fs::read(path).unwrap(); + } + } indication_icon = icon } diff --git a/src-tauri/src/feat.rs b/src-tauri/src/feat.rs index f85dae4..36f6f3c 100644 --- a/src-tauri/src/feat.rs +++ b/src-tauri/src/feat.rs @@ -230,6 +230,9 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> { let proxy_bypass = patch.system_proxy_bypass; let language = patch.language; let port = patch.verge_mixed_port; + let common_tray_icon = patch.common_tray_icon; + let sysproxy_tray_icon = patch.sysproxy_tray_icon; + let tun_tray_icon = patch.tun_tray_icon; match { #[cfg(target_os = "windows")] @@ -269,7 +272,12 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> { if language.is_some() { handle::Handle::update_systray()?; - } else if system_proxy.or(tun_mode).is_some() { + } else if system_proxy.is_some() + || tun_mode.is_some() + || common_tray_icon.is_some() + || sysproxy_tray_icon.is_some() + || tun_tray_icon.is_some() + { handle::Handle::update_systray_part()?; } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index ad8a546..86ef23e 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -58,11 +58,15 @@ "dialog": { "all": false, "open": true + }, + "protocol": { + "asset": true, + "assetScope": ["**"] } }, "windows": [], "security": { - "csp": "script-src 'unsafe-eval' 'self'; default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; img-src http: https: data: 'self';" + "csp": "script-src 'unsafe-eval' 'self'; default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; img-src asset: http: https: data: 'self';" } } } diff --git a/src/components/setting/mods/layout-viewer.tsx b/src/components/setting/mods/layout-viewer.tsx index 2a11523..e97cc18 100644 --- a/src/components/setting/mods/layout-viewer.tsx +++ b/src/components/setting/mods/layout-viewer.tsx @@ -1,10 +1,12 @@ import { forwardRef, useImperativeHandle, useState } from "react"; import { useTranslation } from "react-i18next"; -import { List, Switch } from "@mui/material"; +import { List, Switch, Button } from "@mui/material"; import { useVerge } from "@/hooks/use-verge"; import { BaseDialog, DialogRef, Notice } from "@/components/base"; import { SettingItem } from "./setting-comp"; import { GuardState } from "./guard-state"; +import { open as openDialog } from "@tauri-apps/api/dialog"; +import { convertFileSrc } from "@tauri-apps/api/tauri"; export const LayoutViewer = forwardRef((props, ref) => { const { t } = useTranslation(); @@ -61,6 +63,141 @@ export const LayoutViewer = forwardRef((props, ref) => { + + + onChangeData({ common_tray_icon: e })} + onGuard={(e) => patchVerge({ common_tray_icon: e })} + > + + + + + + onChangeData({ sysproxy_tray_icon: e })} + onGuard={(e) => patchVerge({ sysproxy_tray_icon: e })} + > + + + + + + onChangeData({ tun_tray_icon: e })} + onGuard={(e) => patchVerge({ tun_tray_icon: e })} + > + + + ); diff --git a/src/locales/en.json b/src/locales/en.json index 3425947..c986a84 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -110,6 +110,9 @@ "Hotkey Setting": "Hotkey Setting", "Traffic Graph": "Traffic Graph", "Memory Usage": "Memory Usage", + "Common Tray Icon": "Common Tray Icon", + "System Proxy Tray Icon": "System Proxy Tray Icon", + "Tun Tray Icon": "Tun Tray Icon", "Language": "Language", "Open App Dir": "Open App Dir", "Open Core Dir": "Open Core Dir", diff --git a/src/locales/zh.json b/src/locales/zh.json index 6d54ba8..5831c20 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -110,6 +110,9 @@ "Hotkey Setting": "热键设置", "Traffic Graph": "流量图显", "Memory Usage": "内存使用", + "Common Tray Icon": "常规托盘图标", + "System Proxy Tray Icon": "系统代理托盘图标", + "Tun Tray Icon": "Tun模式托盘图标", "Language": "语言设置", "Open App Dir": "应用目录", "Open Core Dir": "内核目录", diff --git a/src/services/types.d.ts b/src/services/types.d.ts index 18a8448..8d63e40 100644 --- a/src/services/types.d.ts +++ b/src/services/types.d.ts @@ -200,6 +200,9 @@ interface IVergeConfig { theme_mode?: "light" | "dark" | "system"; traffic_graph?: boolean; enable_memory_usage?: boolean; + common_tray_icon?: string; + sysproxy_tray_icon?: string; + tun_tray_icon?: string; enable_tun_mode?: boolean; enable_auto_launch?: boolean; enable_service_mode?: boolean;