perf(tray): ignore unnecessary tray icon events to reduce refreshes

This commit is contained in:
Tunglies
2025-10-22 18:49:28 +08:00
parent 2d2167e048
commit 815a865265
2 changed files with 11 additions and 1 deletions

View File

@@ -537,6 +537,16 @@ impl Tray {
let tray = builder.build(app_handle)?;
tray.on_tray_icon_event(|_app_handle, event| {
// 忽略移动、进入和离开等无需处理的事件,避免不必要的刷新
match event {
TrayIconEvent::Move { .. }
| TrayIconEvent::Enter { .. }
| TrayIconEvent::Leave { .. } => {
return;
}
_ => {}
}
AsyncHandler::spawn(|| async move {
let tray_event = { Config::verge().await.latest_ref().tray_event.clone() };
let tray_event: String = tray_event.unwrap_or_else(|| "main_window".into());