From 99344a310465966bb037e82537050f77dd2d1e0e Mon Sep 17 00:00:00 2001 From: Jon Kinney Date: Fri, 24 Apr 2026 10:43:23 -0500 Subject: [PATCH] macos: present the window on the post-grant relaunch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- lan-mouse-gtk/src/lib.rs | 10 ++++++++++ lan-mouse-gtk/src/macos_privacy.rs | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) 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(); }