Desktop: tray mini card on left click (store status at a glance next to the tray icon; Refresh runs the main window's Refresh all)

This commit is contained in:
CRTkafa 2026-10-23 11:15:35 +08:00
parent c03938f9dc
commit 60a72e6947
23 changed files with 1052 additions and 11 deletions

View file

@ -3,6 +3,7 @@
pub mod accounts;
pub mod ai_fix;
pub mod cache;
pub mod card;
pub mod commands;
pub mod confirm;
pub mod downloads;
@ -66,8 +67,17 @@ fn tray(app: &tauri::App) -> tauri::Result<()> {
None => {}
})
.on_tray_icon_event(|t, e| {
if let TrayIconEvent::Click { button: MouseButton::Left, button_state: MouseButtonState::Up, .. } = e {
show_main(t.app_handle());
// left click: the tray card next to the icon (right click keeps the native menu)
if let TrayIconEvent::Click { button: MouseButton::Left, button_state: MouseButtonState::Up, rect, .. } = e {
let app = t.app_handle();
if app.get_webview_window(card::LABEL).is_none() {
show_main(app);
return;
}
let scale = app.get_webview_window(policy::MAIN).and_then(|w| w.scale_factor().ok()).unwrap_or(1.0);
let p = rect.position.to_physical::<f64>(scale);
let s = rect.size.to_physical::<f64>(scale);
card::toggle(app, card::Rect { x: p.x, y: p.y, w: s.width, h: s.height });
}
})
.build(app)?;
@ -281,6 +291,9 @@ pub fn run() {
}
app.manage(state);
tray(app)?;
if let Err(e) = card::create(app.handle()) {
logs::host("warn", &format!("tray card not created: {e}"));
}
if !started_hidden() {
show_main(app.handle());
}
@ -310,6 +323,13 @@ pub fn run() {
.on_window_event(|w, e| {
// the close button hides the window: the app keeps running in the tray (macOS: also the Dock); the tray's
// Quit (macOS: Cmd+Q) really quits
if w.label() == card::LABEL {
match e {
WindowEvent::Focused(false) => { let _ = w.hide(); card::note_hidden(); }
WindowEvent::CloseRequested { api, .. } => { api.prevent_close(); let _ = w.hide(); card::note_hidden(); }
_ => {}
}
}
if w.label() == policy::MAIN {
if let WindowEvent::CloseRequested { api, .. } = e {
api.prevent_close();
@ -354,6 +374,7 @@ pub fn run() {
commands::data_reveal,
commands::notify,
commands::tray_update,
commands::card_snapshot,
commands::app_reset,
commands::update_check,
commands::update_install,
@ -368,6 +389,8 @@ pub fn run() {
commands::ai_fix_info,
commands::ai_fix_run,
commands::ai_fix_undo,
commands::card_get,
commands::card_action,
])
.build(tauri::generate_context!())
.expect("storebound desktop failed to start");