mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-02 19:50:21 +08:00
chore(tray): migrate template icons to Tauri 2.13 APIs
This commit is contained in:
@@ -296,19 +296,13 @@ impl Tray {
|
||||
|
||||
let (_is_custom_icon, icon_bytes) = TrayState::get_tray_icon(verge).await;
|
||||
|
||||
let template = {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
verge.tray_icon.as_ref().is_none_or(|v| v == "monochrome")
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
false
|
||||
}
|
||||
};
|
||||
let icon = Some(tauri::image::Image::from_bytes(&icon_bytes)?);
|
||||
|
||||
logging_error!(Type::Tray, tray.set_icon_with_as_template(icon, template));
|
||||
let result = if cfg!(target_os = "macos") && verge.tray_icon.as_ref().is_none_or(|v| v == "monochrome") {
|
||||
tray.set_icon_templated(icon)
|
||||
} else {
|
||||
tray.set_icon(icon)
|
||||
};
|
||||
logging_error!(Type::Tray, result);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -404,26 +398,18 @@ impl Tray {
|
||||
let icon_bytes = TrayState::get_tray_icon(&verge).await.1;
|
||||
let icon = tauri::image::Image::from_bytes(&icon_bytes)?;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
let builder = TrayIconBuilder::with_id(TRAY_ID).icon(icon).icon_as_template(false);
|
||||
let builder = TrayIconBuilder::with_id(TRAY_ID);
|
||||
let builder = if cfg!(target_os = "macos") && verge.tray_icon.as_ref().is_none_or(|v| v == "monochrome") {
|
||||
builder.icon_templated(icon)
|
||||
} else {
|
||||
builder.icon(icon)
|
||||
};
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "windows"))]
|
||||
let show_menu_on_left_click = verge.tray_event.as_ref().is_some_and(|v| v == "tray_menu");
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
let mut builder = TrayIconBuilder::with_id(TRAY_ID).icon(icon).icon_as_template(false);
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let is_monochrome = verge.tray_icon.as_ref().is_none_or(|v| v == "monochrome");
|
||||
builder = builder.icon_as_template(is_monochrome);
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "windows"))]
|
||||
{
|
||||
if !show_menu_on_left_click {
|
||||
builder = builder.show_menu_on_left_click(false);
|
||||
}
|
||||
}
|
||||
let builder = builder.show_menu_on_left_click(show_menu_on_left_click);
|
||||
|
||||
let tray = builder.build(app_handle)?;
|
||||
tray.on_tray_icon_event(on_tray_icon_event);
|
||||
|
||||
Reference in New Issue
Block a user