Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src-tauri/src/app_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ fn configure_setup(builder: Builder<tauri::Wry>) -> Builder<tauri::Wry> {

fn handle_run_event(app_handle: &tauri::AppHandle, event: RunEvent) {
match app_runtime_events::run_event_action(&event) {
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);
Expand Down
24 changes: 22 additions & 2 deletions src-tauri/src/app_runtime_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub(crate) enum PageLoadAction {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum RunEventAction {
None,
ShowMainWindow,
HandleExitRequested,
HandleExit,
}
Expand Down Expand Up @@ -63,8 +64,21 @@ pub(crate) fn page_load_action(
}
}

pub(crate) fn reopen_event_action(has_visible_windows: bool) -> RunEventAction {
if has_visible_windows {
RunEventAction::None
} else {
RunEventAction::ShowMainWindow
}
}
Comment on lines +69 to +75
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

在 macOS 上,点击 Dock 图标的标准行为是确保主窗口可见并获得焦点。目前的实现使用了 has_visible_windows 来判断是否执行 ShowMainWindow,这在多窗口场景下可能不够健壮:如果用户打开了辅助窗口(如设置窗口)但隐藏了主窗口,点击 Dock 图标将不会恢复主窗口。建议考虑移除此判断,让 show_main_window 始终执行(该函数内部通常是幂等的,且会自动处理聚焦),或者明确这是否是针对单窗口场景的有意简化。


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,
Expand All @@ -74,8 +88,8 @@ pub(crate) fn run_event_action(event: &RunEvent) -> RunEventAction {
#[cfg(test)]
mod tests {
use super::{
main_window_action, page_load_action, run_event_action, MainWindowAction, PageLoadAction,
RunEventAction,
main_window_action, page_load_action, reopen_event_action, run_event_action,
MainWindowAction, PageLoadAction, RunEventAction,
};
use tauri::{webview::PageLoadEvent, RunEvent};

Expand Down Expand Up @@ -119,6 +133,12 @@ mod tests {
);
}

#[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!(
Expand Down
Loading