macos: present the window on the post-grant relaunch

After the user clicks Relaunch on the warning row, the new instance
started hidden in the menu bar — no visible confirmation that the
relaunch actually worked. Present the window on that specific
launch so the user sees the app come up healthy.

Mechanism: relaunch_bundle() sets LAN_MOUSE_RELAUNCHED=1 via
`open --env` when spawning the new instance. build_ui reads the
env var and calls window.present() only when it's set. Normal
fresh launches (from Finder / Dock / Launchpad / any other
Launch Services path) continue to start hidden in the menu bar.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jon Kinney
2026-04-24 10:43:23 -05:00
committed by Ferdinand Schober
parent 94e9301e9c
commit 99344a3104
2 changed files with 15 additions and 1 deletions

View File

@@ -278,5 +278,15 @@ fn build_ui(app: &Application) {
#[cfg(not(target_os = "macos"))]
window.present();
// On macOS, surface the window on the specific launch that follows
// the user clicking "Relaunch" after granting Accessibility, so
// they see the app come up in its working state rather than just
// a menu-bar icon and wonder whether anything happened.
// relaunch_bundle() sets LAN_MOUSE_RELAUNCHED=1 via `open --env`.
#[cfg(target_os = "macos")]
if env::var_os("LAN_MOUSE_RELAUNCHED").is_some() {
window.present();
}
}

View File

@@ -144,7 +144,11 @@ pub fn relaunch_bundle() {
// Trailing `&` backgrounds the sleep+open so our shell call returns
// immediately; the spawned shell is adopted by launchd once we exit.
let cmd = format!("(sleep 1 && open {bundle:?}) &");
// `--env LAN_MOUSE_RELAUNCHED=1` sets an env var on the new process
// so `build_ui` can present the main window on this specific launch
// (confirming to the user that the grant + relaunch worked) while
// still starting hidden in the menu bar on normal fresh launches.
let cmd = format!("(sleep 1 && open --env LAN_MOUSE_RELAUNCHED=1 {bundle:?}) &");
let _ = Command::new("sh").arg("-c").arg(cmd).spawn();
}