Skip to content

Commit eb1a2cf

Browse files
committed
feat(macos): launcher rename, Dock icon, hide-to-tray window lifecycle
A bare `python main_qml.py` launch surfaces "python" in the Dock tile, Cmd+Tab caption, Force Quit, and Activity Monitor because macOS reads the Mach-O image basename at exec time and there is no in-process API to rename it after the fact. The application icon comes from the same bundle identity, so the Dock also shows the generic Python launcher icon instead of Mouser's branding. None of this affects PyInstaller `.app` bundles -- only source and venv launches. The fix layers a few small pieces in main_qml.py. `_maybe_relaunch_with_mouser_process_name` re-execs the current interpreter through a stable symlink whose basename is `Mouser`, staged atomically via os.replace() to avoid a TOCTOU window where a concurrent launch could observe the launcher path missing. The symlink lives next to the venv's python shim so pyvenv.cfg discovery still resolves site-packages after the re-exec. It returns immediately on PyInstaller-frozen bundles (where the Mach-O is already correctly named), on non-macOS platforms, and when the env-var guard shows we already relaunched. `_rename_macos_bundle_for_dock` mutates [NSBundle mainBundle]'s display-name keys so the application menu, Force Quit, and notification banners read "Mouser" as well. `_install_macos_dock_icon` replaces NSApplication's icon with `images/logo_icon.png`. The decoded NSImage is cached at module scope so repeated invocations (one per Regular promotion) only re-issue the cheap setApplicationIconImage_ syscall instead of re-decoding the 1024px PNG. `_app_icon` similarly hands QIcon the full-resolution PNG directly so the Dock and Cmd+Tab tiles render crisply at native size instead of the previous upscaled-256px blur. `_configure_macos_app_mode` and `_set_macos_activation_policy` launch the app as NSApplicationActivationPolicyAccessory (menu-bar only, no Dock entry), then promote to Regular when a window becomes visible. The visibilityChanged hook flips back to Accessory on hide so the Dock collapses cleanly. The policy setter is idempotent against rapid visibilityChanged storms by skipping the AppKit round-trip when the requested state matches the last-applied one. `_check_accessibility` fails closed on exception now (returns False) so future callers can rely on the docstring contract, and `_parse_cli_args` returns a 4-tuple so callers can branch on the new `--show-window` flag.
1 parent 1801142 commit eb1a2cf

1 file changed

Lines changed: 293 additions & 37 deletions

File tree

0 commit comments

Comments
 (0)