mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 03:03:46 +08:00
fix(tray): resolve blank icon issue on Windows and optimize creation logic
This commit is contained in:
parent
d895b68f04
commit
c98330ea1f
@ -68,7 +68,6 @@ impl Tray {
|
||||
|
||||
pub fn create_systray(&self) -> Result<()> {
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
let tray_incon_id = TrayIconId::new("main");
|
||||
|
||||
// 创建初始菜单
|
||||
let initial_menu = create_tray_menu(
|
||||
@ -80,7 +79,7 @@ impl Tray {
|
||||
)?;
|
||||
|
||||
// 使用 TrayIconBuilder 构建托盘
|
||||
let _tray = tauri::tray::TrayIconBuilder::<Wry>::with_id(tray_incon_id)
|
||||
let tray = tauri::tray::TrayIconBuilder::<Wry>::with_id(TrayIconId::new("main"))
|
||||
.menu(&initial_menu) // 先设置菜单
|
||||
.show_menu_on_left_click(false) // 再禁用左键菜单
|
||||
.on_tray_icon_event(move |tray, event| {
|
||||
|
@ -14,7 +14,7 @@ use anyhow::{bail, Result};
|
||||
use reqwest_dav::list_cmd::ListFile;
|
||||
use serde_yaml::{Mapping, Value};
|
||||
use std::fs;
|
||||
use tauri::Manager;
|
||||
use tauri::{Manager, tray::TrayIcon};
|
||||
use tauri_plugin_clipboard_manager::ClipboardExt;
|
||||
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
|
||||
|
||||
@ -146,9 +146,14 @@ pub fn quit(code: Option<i32>) {
|
||||
let _ = window.close();
|
||||
}
|
||||
|
||||
// 移除系统托盘图标
|
||||
if let Some(tray) = app_handle.tray_by_id("main") {
|
||||
let _ = tray.set_icon(None);
|
||||
}
|
||||
|
||||
// 后台执行所有清理工作
|
||||
let app_handle_clone = app_handle.clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
tauri::async_runtime::block_on(async move {
|
||||
// 1. 发送停止内核指令
|
||||
let _ = CoreManager::global().stop_core().await;
|
||||
|
||||
@ -162,7 +167,7 @@ pub fn quit(code: Option<i32>) {
|
||||
log::info!(target: "app", "Cleanup tasks completed in background");
|
||||
});
|
||||
|
||||
// 主线程立即退出
|
||||
// 主线程退出
|
||||
println!("Exiting application with code: {:?}", code);
|
||||
log::info!(target: "app", "Exiting application with code: {:?}", code);
|
||||
app_handle.exit(code.unwrap_or(0));
|
||||
|
@ -19,12 +19,5 @@
|
||||
"template": "./packages/windows/installer.nsi"
|
||||
}
|
||||
}
|
||||
},
|
||||
"app": {
|
||||
"windows": [],
|
||||
"trayIcon": {
|
||||
"iconPath": "icons/tray-icon.ico",
|
||||
"iconAsTemplate": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user