diff --git a/src-tauri/src/app_runtime.rs b/src-tauri/src/app_runtime.rs index f9ff9ad..1aa8286 100644 --- a/src-tauri/src/app_runtime.rs +++ b/src-tauri/src/app_runtime.rs @@ -125,6 +125,11 @@ fn configure_setup(builder: Builder) -> Builder { fn handle_run_event(app_handle: &tauri::AppHandle, event: RunEvent) { match app_runtime_events::run_event_action(&event) { + #[cfg(target_os = "macos")] + app_runtime_events::RunEventAction::ShowMainWindow => { + append_desktop_log("application reopen requested, showing main window"); + window::actions::show_main_window(app_handle, DEFAULT_SHELL_LOCALE, append_desktop_log); + } app_runtime_events::RunEventAction::HandleExitRequested => { if let RunEvent::ExitRequested { api, .. } = event { lifecycle::events::handle_exit_requested(app_handle, &api); diff --git a/src-tauri/src/app_runtime_events.rs b/src-tauri/src/app_runtime_events.rs index 8d1e5a9..d932706 100644 --- a/src-tauri/src/app_runtime_events.rs +++ b/src-tauri/src/app_runtime_events.rs @@ -17,6 +17,8 @@ pub(crate) enum PageLoadAction { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(crate) enum RunEventAction { None, + #[cfg(target_os = "macos")] + ShowMainWindow, HandleExitRequested, HandleExit, } @@ -63,8 +65,22 @@ pub(crate) fn page_load_action( } } +#[cfg(target_os = "macos")] +pub(crate) fn reopen_event_action(has_visible_windows: bool) -> RunEventAction { + if has_visible_windows { + RunEventAction::None + } else { + RunEventAction::ShowMainWindow + } +} + pub(crate) fn run_event_action(event: &RunEvent) -> RunEventAction { match event { + #[cfg(target_os = "macos")] + RunEvent::Reopen { + has_visible_windows, + .. + } => reopen_event_action(*has_visible_windows), RunEvent::ExitRequested { .. } => RunEventAction::HandleExitRequested, RunEvent::Exit => RunEventAction::HandleExit, _ => RunEventAction::None, @@ -79,6 +95,9 @@ mod tests { }; use tauri::{webview::PageLoadEvent, RunEvent}; + #[cfg(target_os = "macos")] + use super::reopen_event_action; + #[test] fn main_window_action_ignores_non_main_windows() { assert_eq!( @@ -119,6 +138,13 @@ mod tests { ); } + #[cfg(target_os = "macos")] + #[test] + fn reopen_event_action_shows_main_window_only_when_no_window_is_visible() { + assert_eq!(reopen_event_action(false), RunEventAction::ShowMainWindow); + assert_eq!(reopen_event_action(true), RunEventAction::None); + } + #[test] fn run_event_action_maps_exit_events() { assert_eq!(