From f03b0f3a18afef5952827508a02d4daef8bb7fb6 Mon Sep 17 00:00:00 2001 From: Beingpax Date: Mon, 12 May 2025 22:36:21 +0545 Subject: [PATCH] Fix dock icon persistence when launching externally --- VoiceInk/AppDelegate.swift | 6 ++++++ VoiceInk/MenuBarManager.swift | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/VoiceInk/AppDelegate.swift b/VoiceInk/AppDelegate.swift index d222a6e..d734069 100644 --- a/VoiceInk/AppDelegate.swift +++ b/VoiceInk/AppDelegate.swift @@ -7,12 +7,18 @@ class AppDelegate: NSObject, NSApplicationDelegate { } func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { + updateActivationPolicy() + if !flag { createMainWindowIfNeeded() } return true } + func applicationDidBecomeActive(_ notification: Notification) { + updateActivationPolicy() + } + func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return false } diff --git a/VoiceInk/MenuBarManager.swift b/VoiceInk/MenuBarManager.swift index 66c2506..9d87414 100644 --- a/VoiceInk/MenuBarManager.swift +++ b/VoiceInk/MenuBarManager.swift @@ -64,6 +64,12 @@ class MenuBarManager: ObservableObject { DispatchQueue.main.async { [weak self] in guard let self = self else { return } + if self.isMenuBarOnly { + NSApp.setActivationPolicy(.accessory) + } else { + NSApp.setActivationPolicy(.regular) + } + // Activate the app NSApp.activate(ignoringOtherApps: true)