mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 06:53:44 +08:00
fix: the tray icon does not display the correct colours on macos.
This commit is contained in:
parent
7b1ec1ec22
commit
d3123253b3
Binary file not shown.
Before Width: | Height: | Size: 19 KiB |
Binary file not shown.
Before Width: | Height: | Size: 22 KiB |
Binary file not shown.
Before Width: | Height: | Size: 20 KiB |
@ -83,8 +83,6 @@ impl Tray {
|
|||||||
let verge = Config::verge().latest().clone();
|
let verge = Config::verge().latest().clone();
|
||||||
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);
|
||||||
@ -97,28 +95,10 @@ impl Tray {
|
|||||||
*tun_mode,
|
*tun_mode,
|
||||||
)?));
|
)?));
|
||||||
|
|
||||||
// let _ = tray.
|
let mut use_custom_icon = false;
|
||||||
#[cfg(target_os = "macos")]
|
#[allow(unused)]
|
||||||
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")]
|
|
||||||
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");
|
||||||
@ -128,38 +108,10 @@ impl Tray {
|
|||||||
} else if png_path.exists() {
|
} else if png_path.exists() {
|
||||||
icon = std::fs::read(png_path).unwrap();
|
icon = std::fs::read(png_path).unwrap();
|
||||||
}
|
}
|
||||||
|
use_custom_icon = true;
|
||||||
}
|
}
|
||||||
icon
|
icon
|
||||||
} else {
|
} else if *tun_mode {
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
let mut icon = match tray_icon.as_str() {
|
|
||||||
"monochrome" => include_bytes!("../../icons/tray-icon-mono.ico").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"))]
|
|
||||||
let mut icon = include_bytes!("../../icons/tray-icon.ico").to_vec();
|
|
||||||
if *common_tray_icon {
|
|
||||||
let icon_dir_path = dirs::app_home_dir()?.join("icons");
|
|
||||||
let png_path = icon_dir_path.join("common.png");
|
|
||||||
let ico_path = icon_dir_path.join("common.ico");
|
|
||||||
if ico_path.exists() {
|
|
||||||
icon = std::fs::read(ico_path).unwrap();
|
|
||||||
} else if png_path.exists() {
|
|
||||||
icon = std::fs::read(png_path).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
icon
|
|
||||||
};
|
|
||||||
|
|
||||||
if *tun_mode {
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
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");
|
||||||
@ -170,9 +122,34 @@ impl Tray {
|
|||||||
} else if png_path.exists() {
|
} else if png_path.exists() {
|
||||||
icon = std::fs::read(png_path).unwrap();
|
icon = std::fs::read(png_path).unwrap();
|
||||||
}
|
}
|
||||||
|
use_custom_icon = true;
|
||||||
|
}
|
||||||
|
icon
|
||||||
|
} else {
|
||||||
|
let mut icon = include_bytes!("../../icons/tray-icon.ico").to_vec();
|
||||||
|
if *common_tray_icon {
|
||||||
|
let icon_dir_path = dirs::app_home_dir()?.join("icons");
|
||||||
|
let png_path = icon_dir_path.join("common.png");
|
||||||
|
let ico_path = icon_dir_path.join("common.ico");
|
||||||
|
if ico_path.exists() {
|
||||||
|
icon = std::fs::read(ico_path).unwrap();
|
||||||
|
} else if png_path.exists() {
|
||||||
|
icon = std::fs::read(png_path).unwrap();
|
||||||
|
}
|
||||||
|
use_custom_icon = true;
|
||||||
|
}
|
||||||
|
icon
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
{
|
||||||
|
if use_custom_icon {
|
||||||
|
let _ = tray.set_icon_as_template(false);
|
||||||
|
let _ = tray.set_icon(Some(tauri::image::Image::from_bytes(&indication_icon)?));
|
||||||
}
|
}
|
||||||
indication_icon = icon
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
let _ = tray.set_icon(Some(tauri::image::Image::from_bytes(&indication_icon)?));
|
let _ = tray.set_icon(Some(tauri::image::Image::from_bytes(&indication_icon)?));
|
||||||
|
|
||||||
let switch_map = {
|
let switch_map = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user