Skip to content

fix(desktop): show the window again on a second launch - #2290

Merged
abrichr merged 4 commits into
mainfrom
fix/desktop-second-launch-shows-window
Nov 19, 2026
Merged

abrichr merged 4 commits into
mainfrom
fix/desktop-second-launch-shows-window

Conversation

@abrichr

@abrichr abrichr commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Problem

On Windows 11 with Desktop 0.30.4: close the app's window with X, then choose OpenAdapt Desktop in the Start menu. No window appears (65 s watched, no new process). The app is still running behind its tray icon, so a person who closes the window cannot get it back from the Start menu.

Cause

Nothing handled the close request, so closing the main window destroyed it. The app stays alive because the tray icon and the hidden control overlay window remain. Three ways back all looked up the main window, found none, and did nothing:

  • the single-instance handler (a second launch),
  • "Open OpenAdapt" in the tray menu,
  • a click on the macOS Dock icon (there was no handler for it at all).

Fix

  • src-tauri/src/window.rs (new): closing the main window hides it instead; show_main restores, shows and focuses it.
  • main.rs: the single-instance handler and, on macOS, RunEvent::Reopen call show_main.
  • tray.rs: "Open OpenAdapt" and "Shadow mode settings" call the same function.
  • Quit in the tray menu and Cmd-Q still exit the app.
  • Desktop 0.30.6 (main was merged in after fix(desktop): start the engine's child processes without forking on macOS #2287 took 0.30.5).

Tests

  • Rust unit tests for the close rule (cargo test window::: 2 pass).
  • tests/test_main_window_reopens.py: holds the close handler and the three callers of show_main in place (4 pass).
  • cargo fmt --check clean. cargo clippy -D warnings fails on main already (tauri_plugin_shell::Shell::open deprecation in commands.rs), not from this change.

Verified on installers built from this branch

Packages run 44628317428 built head 6fad126 (version 0.30.6).

Windows 11 (setup .exe, sha256 2586a435...173adb, first run):

Test Result
Close with X, then Start menu (twice) Pass. Same window back in under 1 s, in front with focus; process IDs unchanged, so no second copy started
State kept Pass. Closed on the sample page; the same page showed after each reopen
Minimised, then Start menu Pass. Restored and in front
Tray menu: Open OpenAdapt, then Quit Pass. Window back in under 1 s; Quit ended the app and both engine processes
Fresh start and sample Pass. No Terminal or console window at launch; both result cards 1 min 46 s after "Run the sample"

macOS 15.7 (Apple Silicon .dmg):

Test Result
Close with the red button Window hidden, app and engine still running
Click the Dock icon Pass. Same window back, still on the sample page
Close, then open the app again Pass. One window, no second copy
Quit No app or engine process left

Not checked

  • Left-click or double-click on the Windows tray icon, the desktop shortcut, a taskbar pin.
  • Closing the window while the sample is running.
  • The reopened window coming to the front over another app's window (only the desktop was behind it).

Closing the main window destroyed it while the app kept running behind
the tray icon. After that a second launch from the Start menu, Open
OpenAdapt in the tray menu and a click on the macOS Dock icon all found
no window and did nothing.

Closing now hides the window. One function, window::show_main, restores,
shows and focuses it, and the single-instance handler, the tray menu and
the Dock all call it.
@abrichr

abrichr commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 6fad126

Verdict: APPROVE. The branch is up to date with main (89883a4 is an ancestor of the head). I found no P1 or P2 issues.

What I attacked:

  • A second launch cannot start a second engine or a second instance. The single-instance plugin is still the first plugin registered. In tauri-plugin-single-instance 2.5.3 (the version in Cargo.lock; I read the published crate source), each platform's plugin setup notifies the running instance and then calls std::process::exit(0) (linux.rs:88, windows.rs:125, macos.rs:28). Plugin setup runs before the app's .setup closure, and that closure is the only place sidecar::spawn is called. So a second process exits before it can start an engine or open the data or ports. This PR does not change that order; it only replaces the callback body with window::show_main(app).
  • The macOS Dock click. RunEvent::Reopen { has_visible_windows } exists in tauri 2.12.4 (app.rs:279, #[non_exhaustive], macOS only). The { .. } pattern and the #[cfg(target_os = "macos")] arm are correct for it. Reopen fires whether or not windows are visible, and show_main is safe in both cases.
  • The hidden window really comes back, rather than focus going to an invisible window.
    • Before this PR, nothing handled CloseRequested, so X destroyed main and every get_webview_window("main") afterwards returned None.
    • Now prevent_close() plus hide() keeps the window, and show_main calls unminimize, then show, then set_focus on it.
    • Side benefit: after a close, place_control_overlay and set_control_overlay_layout("stage") in commands.rs also need main. They used to return early or fail with "main window is unavailable"; now they work.
  • Quitting still works. Tray "quit" calls app.exit(0) and Cmd-Q sends an exit request, so neither one goes through CloseRequested on main. RunEvent::Exit still calls sidecar::shutdown. close_action keeps only main, so control-overlay and any other window close as before.
  • Programmatic closes. No frontend code calls close() or hide() on the main window, so the close interception cannot trap any existing JS path.

Tests at the exact head (py3.12 on Linux): test_main_window_reopens.py, test_native_release.py and test_release_intent.py all ran: 460 passed. I did not build the Rust code, because the box has no webkit2gtk. I relied on CI for that: Analyze (rust) passed and so did the Packages checks. All non-skipped checks are green.

P3 (optional):

  1. The comment in window.rs and the docstring in the test both say "Before 0.30.5 closing destroyed the window". The fix ships in 0.30.6, and 0.30.5 still destroys it.
  2. test_main_window_reopens.py only checks source strings. The behavior itself rests on the author's branch-build runs (Windows 11 and macOS, Packages run 44628317428). Those runs are the real proof, so please keep their results in the PR before merging.
  3. On Linux desktops with no tray (for example GNOME without AppIndicator), closing the window leaves the app running with no way to quit it from the UI. That was already true before this PR, because the overlay kept the process alive, so it is not a regression.

Generality gate: the change is app-shell window lifecycle only. It has no workflow-, application- or vendor-specific paths.

Limits: I ran nothing on macOS or Windows myself, and I did not build or run the Rust unit tests. Merging and releasing 0.30.6 remain the coordinator's decision, after the Windows proof the author mentioned. I pushed nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant