feat(desktop): respect minimize to tray setting for window visibility

Add conditional window showing based on minimize to tray preference. Split window opening logic into open_app_window() for respecting settings and force_open_app_window() for user-initiated actions. Update single instance handler and setup to check minimize setting before showing window.
This commit is contained in:
bobokun 2025-09-15 21:14:46 -04:00
parent b10e9fa2e9
commit d24d2e0954
No known key found for this signature in database
GPG key ID: B73932169607D927
2 changed files with 28 additions and 9 deletions

View file

@ -1 +1 @@
4.6.3-develop11 4.6.3-develop12

View file

@ -400,6 +400,23 @@ async fn wait_until_ready(port: u16, base_url: &Option<String>, timeout: Duratio
} }
fn open_app_window(app: &AppHandle) { fn open_app_window(app: &AppHandle) {
// Check if minimize to tray is enabled and respect it
let minimize_to_tray = *MINIMIZE_TO_TRAY.lock().unwrap_or_else(|_| {
// If lock fails, load setting directly
std::sync::Mutex::new(load_minimize_setting(app))
});
// Only show window if minimize to tray is disabled, or if explicitly requested
if !minimize_to_tray {
if let Some(win) = app.get_webview_window("main") {
let _ = win.show();
let _ = win.set_focus();
}
}
}
fn force_open_app_window(app: &AppHandle) {
// Force open window regardless of minimize to tray setting (for user-initiated actions)
if let Some(win) = app.get_webview_window("main") { if let Some(win) = app.get_webview_window("main") {
let _ = win.show(); let _ = win.show();
let _ = win.set_focus(); let _ = win.set_focus();
@ -527,16 +544,21 @@ pub fn run() {
tauri::Builder::default() tauri::Builder::default()
// Single instance should be first (per docs) // Single instance should be first (per docs)
.plugin(single_instance(|app, _argv, _cwd| { .plugin(single_instance(|app, _argv, _cwd| {
// Load the minimize setting directly in case it hasn't been loaded yet
let minimize_to_tray = load_minimize_setting(app);
if !minimize_to_tray {
if let Some(win) = app.get_webview_window("main") { if let Some(win) = app.get_webview_window("main") {
let _ = win.show(); let _ = win.show();
let _ = win.set_focus(); let _ = win.set_focus();
} }
}
})) }))
.plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_opener::init())
.setup(|app| { .setup(|app| {
let app_handle = app.handle().clone(); let app_handle = app.handle().clone();
// Load settings first before any window operations
let minimize_to_tray = load_minimize_setting(&app_handle); let minimize_to_tray = load_minimize_setting(&app_handle);
*MINIMIZE_TO_TRAY.lock().unwrap() = minimize_to_tray; *MINIMIZE_TO_TRAY.lock().unwrap() = minimize_to_tray;
@ -557,16 +579,13 @@ pub fn run() {
.. ..
} = event { } = event {
let app = tray.app_handle(); let app = tray.app_handle();
if let Some(win) = app.get_webview_window("main") { force_open_app_window(app);
let _ = win.show();
let _ = win.set_focus();
}
} }
}) })
.on_menu_event(|app, event| { .on_menu_event(|app, event| {
match event.id().as_ref() { match event.id().as_ref() {
"open" => { "open" => {
open_app_window(app); force_open_app_window(app);
} }
"restart" => { "restart" => {
// Stop server first, then start it again with minimal delay // Stop server first, then start it again with minimal delay