diff --git a/lan-mouse-gtk/src/lib.rs b/lan-mouse-gtk/src/lib.rs index 112aae6..c1acbd4 100644 --- a/lan-mouse-gtk/src/lib.rs +++ b/lan-mouse-gtk/src/lib.rs @@ -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(); + } } diff --git a/lan-mouse-gtk/src/macos_privacy.rs b/lan-mouse-gtk/src/macos_privacy.rs index 9183a96..3d93667 100644 --- a/lan-mouse-gtk/src/macos_privacy.rs +++ b/lan-mouse-gtk/src/macos_privacy.rs @@ -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(); }