feat: support monochrome tray icon

This commit is contained in:
MystiPanda 2024-05-15 12:00:38 +08:00
parent 224c65438f
commit 21176d2fd3
13 changed files with 71 additions and 7 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -42,6 +42,10 @@ pub struct IVerge {
/// common tray icon /// common tray icon
pub common_tray_icon: Option<bool>, pub common_tray_icon: Option<bool>,
/// tray icon
#[cfg(target_os = "macos")]
pub tray_icon: Option<String>,
/// menu icon /// menu icon
pub menu_icon: Option<String>, pub menu_icon: Option<String>,
@ -198,6 +202,8 @@ impl IVerge {
traffic_graph: Some(true), traffic_graph: Some(true),
enable_memory_usage: Some(true), enable_memory_usage: Some(true),
enable_group_icon: Some(true), enable_group_icon: Some(true),
#[cfg(target_os = "macos")]
tray_icon: Some("monochrome".into()),
menu_icon: Some("monochrome".into()), menu_icon: Some("monochrome".into()),
common_tray_icon: Some(false), common_tray_icon: Some(false),
sysproxy_tray_icon: Some(false), sysproxy_tray_icon: Some(false),
@ -255,6 +261,8 @@ impl IVerge {
patch!(traffic_graph); patch!(traffic_graph);
patch!(enable_memory_usage); patch!(enable_memory_usage);
patch!(enable_group_icon); patch!(enable_group_icon);
#[cfg(target_os = "macos")]
patch!(tray_icon);
patch!(menu_icon); patch!(menu_icon);
patch!(common_tray_icon); patch!(common_tray_icon);
patch!(sysproxy_tray_icon); patch!(sysproxy_tray_icon);

View File

@ -172,14 +172,31 @@ impl Tray {
let verge = verge.latest(); let verge = verge.latest();
let system_proxy = verge.enable_system_proxy.as_ref().unwrap_or(&false); 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 tun_mode = verge.enable_tun_mode.as_ref().unwrap_or(&false);
#[cfg(target_os = "macos")]
let tray_icon = verge.tray_icon.clone().unwrap_or("monochrome".to_string());
let common_tray_icon = verge.common_tray_icon.as_ref().unwrap_or(&false); let common_tray_icon = verge.common_tray_icon.as_ref().unwrap_or(&false);
let sysproxy_tray_icon = verge.sysproxy_tray_icon.as_ref().unwrap_or(&false); let sysproxy_tray_icon = verge.sysproxy_tray_icon.as_ref().unwrap_or(&false);
let tun_tray_icon = verge.tun_tray_icon.as_ref().unwrap_or(&false); let tun_tray_icon = verge.tun_tray_icon.as_ref().unwrap_or(&false);
#[cfg(target_os = "macos")]
match tray_icon.as_str() {
"monochrome" => {
let _ = tray.set_icon_as_template(true);
}
"colorful" => {
let _ = tray.set_icon_as_template(false);
}
_ => {}
}
let mut indication_icon = if *system_proxy { let mut indication_icon = if *system_proxy {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
let _ = tray.set_icon_as_template(false); let mut icon = match tray_icon.as_str() {
"monochrome" => include_bytes!("../../icons/tray-icon-sys-mono.ico").to_vec(),
"colorful" => include_bytes!("../../icons/tray-icon-sys.ico").to_vec(),
_ => include_bytes!("../../icons/tray-icon-sys-mono.ico").to_vec(),
};
#[cfg(not(target_os = "macos"))]
let mut icon = include_bytes!("../../icons/tray-icon-sys.ico").to_vec(); let mut icon = include_bytes!("../../icons/tray-icon-sys.ico").to_vec();
if *sysproxy_tray_icon { if *sysproxy_tray_icon {
let icon_dir_path = dirs::app_home_dir()?.join("icons"); let icon_dir_path = dirs::app_home_dir()?.join("icons");
let png_path = icon_dir_path.join("sysproxy.png"); let png_path = icon_dir_path.join("sysproxy.png");
@ -193,9 +210,11 @@ impl Tray {
icon icon
} else { } else {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
let _ = tray.set_icon_as_template(true); let mut icon = match tray_icon.as_str() {
#[cfg(target_os = "macos")] "monochrome" => include_bytes!("../../icons/tray-icon-mono.ico").to_vec(),
let mut icon = include_bytes!("../../icons/mac-tray-icon.png").to_vec(); "colorful" => include_bytes!("../../icons/tray-icon.ico").to_vec(),
_ => include_bytes!("../../icons/tray-icon-mono.ico").to_vec(),
};
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
let mut icon = include_bytes!("../../icons/tray-icon.ico").to_vec(); let mut icon = include_bytes!("../../icons/tray-icon.ico").to_vec();
if *common_tray_icon { if *common_tray_icon {
@ -213,7 +232,12 @@ impl Tray {
if *tun_mode { if *tun_mode {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
let _ = tray.set_icon_as_template(false); let mut icon = match tray_icon.as_str() {
"monochrome" => include_bytes!("../../icons/tray-icon-tun-mono.ico").to_vec(),
"colorful" => include_bytes!("../../icons/tray-icon-tun.ico").to_vec(),
_ => include_bytes!("../../icons/tray-icon-tun-mono.ico").to_vec(),
};
#[cfg(not(target_os = "macos"))]
let mut icon = include_bytes!("../../icons/tray-icon-tun.ico").to_vec(); let mut icon = include_bytes!("../../icons/tray-icon-tun.ico").to_vec();
if *tun_tray_icon { if *tun_tray_icon {
let icon_dir_path = dirs::app_home_dir()?.join("icons"); let icon_dir_path = dirs::app_home_dir()?.join("icons");

View File

@ -180,6 +180,8 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> {
let proxy_bypass = patch.system_proxy_bypass; let proxy_bypass = patch.system_proxy_bypass;
let language = patch.language; let language = patch.language;
let port = patch.verge_mixed_port; let port = patch.verge_mixed_port;
#[cfg(target_os = "macos")]
let tray_icon = patch.tray_icon;
let common_tray_icon = patch.common_tray_icon; let common_tray_icon = patch.common_tray_icon;
let sysproxy_tray_icon = patch.sysproxy_tray_icon; let sysproxy_tray_icon = patch.sysproxy_tray_icon;
let tun_tray_icon = patch.tun_tray_icon; let tun_tray_icon = patch.tun_tray_icon;
@ -240,6 +242,10 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> {
{ {
handle::Handle::update_systray_part()?; handle::Handle::update_systray_part()?;
} }
#[cfg(target_os = "macos")]
if tray_icon.is_some() {
handle::Handle::update_systray_part()?;
}
<Result<()>>::Ok(()) <Result<()>>::Ok(())
} { } {

View File

@ -2,7 +2,7 @@
"$schema": "../node_modules/@tauri-apps/cli/schema.json", "$schema": "../node_modules/@tauri-apps/cli/schema.json",
"tauri": { "tauri": {
"systemTray": { "systemTray": {
"iconPath": "icons/mac-tray-icon.png", "iconPath": "icons/tray-icon-mono.ico",
"iconAsTemplate": true "iconAsTemplate": true
}, },
"bundle": { "bundle": {

View File

@ -10,6 +10,9 @@ import { convertFileSrc } from "@tauri-apps/api/tauri";
import { copyIconFile, getAppDir } from "@/services/cmds"; import { copyIconFile, getAppDir } from "@/services/cmds";
import { join } from "@tauri-apps/api/path"; import { join } from "@tauri-apps/api/path";
import { exists } from "@tauri-apps/api/fs"; import { exists } from "@tauri-apps/api/fs";
import getSystem from "@/utils/get-system";
const OS = getSystem();
export const LayoutViewer = forwardRef<DialogRef>((props, ref) => { export const LayoutViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation(); const { t } = useTranslation();
@ -128,6 +131,25 @@ export const LayoutViewer = forwardRef<DialogRef>((props, ref) => {
</Select> </Select>
</GuardState> </GuardState>
</SettingItem> </SettingItem>
{OS === "macos" && (
<SettingItem label={t("Tray Icon")}>
<GuardState
value={verge?.tray_icon ?? "monochrome"}
onCatch={onError}
onFormat={(e: any) => e.target.value}
onChange={(e) => onChangeData({ tray_icon: e })}
onGuard={(e) => patchVerge({ tray_icon: e })}
>
<Select
size="small"
sx={{ width: 140, "> div": { py: "7.5px" } }}
>
<MenuItem value="monochrome">{t("Monochrome")}</MenuItem>
<MenuItem value="colorful">{t("Colorful")}</MenuItem>
</Select>
</GuardState>
</SettingItem>
)}
<SettingItem label={t("Common Tray Icon")}> <SettingItem label={t("Common Tray Icon")}>
<GuardState <GuardState

View File

@ -122,6 +122,7 @@
"Traffic Graph": "Traffic Graph", "Traffic Graph": "Traffic Graph",
"Memory Usage": "Memory Usage", "Memory Usage": "Memory Usage",
"Proxy Group Icon": "Proxy Group Icon", "Proxy Group Icon": "Proxy Group Icon",
"Tray Icon": "Tray Icon",
"Menu Icon": "Menu Icon", "Menu Icon": "Menu Icon",
"Monochrome": "Monochrome", "Monochrome": "Monochrome",
"Colorful": "Colorful", "Colorful": "Colorful",

View File

@ -122,6 +122,7 @@
"Traffic Graph": "График трафика", "Traffic Graph": "График трафика",
"Memory Usage": "Использование памяти", "Memory Usage": "Использование памяти",
"Proxy Group Icon": "Иконка Группы прокси", "Proxy Group Icon": "Иконка Группы прокси",
"Tray Icon": "Иконка лотка",
"Menu Icon": "Иконка меню", "Menu Icon": "Иконка меню",
"Monochrome": "Монохромный", "Monochrome": "Монохромный",
"Colorful": "Полноцветный", "Colorful": "Полноцветный",

View File

@ -122,6 +122,7 @@
"Traffic Graph": "流量图显", "Traffic Graph": "流量图显",
"Memory Usage": "内存使用", "Memory Usage": "内存使用",
"Proxy Group Icon": "代理组图标", "Proxy Group Icon": "代理组图标",
"Tray Icon": "托盘图标",
"Menu Icon": "菜单图标", "Menu Icon": "菜单图标",
"Monochrome": "单色图标", "Monochrome": "单色图标",
"Colorful": "彩色图标", "Colorful": "彩色图标",

View File

@ -207,6 +207,7 @@ interface IVergeConfig {
enable_memory_usage?: boolean; enable_memory_usage?: boolean;
enable_group_icon?: boolean; enable_group_icon?: boolean;
menu_icon?: "monochrome" | "colorful" | "disable"; menu_icon?: "monochrome" | "colorful" | "disable";
tray_icon?: "monochrome" | "colorful";
common_tray_icon?: boolean; common_tray_icon?: boolean;
sysproxy_tray_icon?: boolean; sysproxy_tray_icon?: boolean;
tun_tray_icon?: boolean; tun_tray_icon?: boolean;