// Prevents additional console window on Windows in release. #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] use tauri::{ tray::TrayIconBuilder, Manager, }; fn main() { tauri::Builder::default() .setup(|app| { // Create system tray let _tray = TrayIconBuilder::new() .tooltip("AIUI") .on_tray_icon_event(|tray, event| { use tauri::tray::TrayIconEvent; if let TrayIconEvent::Click { .. } = event { let app = tray.app_handle(); if let Some(window) = app.get_webview_window("main") { let _ = window.show(); let _ = window.set_focus(); } } }) .build(app)?; // Register global shortcut (Cmd+Shift+A / Ctrl+Shift+A) #[cfg(target_os = "macos")] let shortcut = "CommandOrControl+Shift+A"; #[cfg(not(target_os = "macos"))] let shortcut = "Ctrl+Shift+A"; let app_handle = app.handle().clone(); app.global_shortcut().on_shortcut(shortcut, move |_app, _shortcut, _event| { if let Some(window) = app_handle.get_webview_window("main") { if window.is_visible().unwrap_or(false) { let _ = window.hide(); } else { let _ = window.show(); let _ = window.set_focus(); } } })?; Ok(()) }) .plugin(tauri_plugin_updater::Builder::new().build()) .run(tauri::generate_context!()) .expect("error while running tauri application"); }