Fix window duplication issue
This commit is contained in:
parent
c7030276eb
commit
73318967ac
@ -12,8 +12,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
||||
menuBarManager?.applyActivationPolicy()
|
||||
|
||||
if !flag {
|
||||
menuBarManager?.focusMainWindow()
|
||||
if !flag, let menuBarManager = menuBarManager, !menuBarManager.isMenuBarOnly {
|
||||
if WindowManager.shared.showMainWindow() != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@ class MenuBarManager: ObservableObject {
|
||||
WindowManager.shared.hideMainWindow()
|
||||
} else {
|
||||
application.setActivationPolicy(.regular)
|
||||
WindowManager.shared.showMainWindow()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -151,8 +151,7 @@ struct VoiceInkApp: App {
|
||||
.environmentObject(enhancementService)
|
||||
.frame(minWidth: 880, minHeight: 780)
|
||||
.background(WindowAccessor { window in
|
||||
// Ensure this is called only once or is idempotent
|
||||
if window.title != "VoiceInk Onboarding" { // Prevent re-configuration
|
||||
if window.identifier == nil || window.identifier != NSUserInterfaceItemIdentifier("com.prakashjoshipax.voiceink.onboardingWindow") {
|
||||
WindowManager.shared.configureOnboardingPanel(window)
|
||||
}
|
||||
})
|
||||
|
||||
@ -5,6 +5,7 @@ class WindowManager: NSObject {
|
||||
static let shared = WindowManager()
|
||||
|
||||
private static let mainWindowIdentifier = NSUserInterfaceItemIdentifier("com.prakashjoshipax.voiceink.mainWindow")
|
||||
private static let onboardingWindowIdentifier = NSUserInterfaceItemIdentifier("com.prakashjoshipax.voiceink.onboardingWindow")
|
||||
private static let mainWindowAutosaveName = NSWindow.FrameAutosaveName("VoiceInkMainWindowFrame")
|
||||
|
||||
private weak var mainWindow: NSWindow?
|
||||
@ -15,6 +16,12 @@ class WindowManager: NSObject {
|
||||
}
|
||||
|
||||
func configureWindow(_ window: NSWindow) {
|
||||
if let existingWindow = NSApplication.shared.windows.first(where: { $0.identifier == Self.mainWindowIdentifier && $0 != window }) {
|
||||
window.close()
|
||||
existingWindow.makeKeyAndOrderFront(nil)
|
||||
return
|
||||
}
|
||||
|
||||
let requiredStyleMask: NSWindow.StyleMask = [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView]
|
||||
window.styleMask.formUnion(requiredStyleMask)
|
||||
window.titlebarAppearsTransparent = true
|
||||
@ -34,6 +41,10 @@ class WindowManager: NSObject {
|
||||
}
|
||||
|
||||
func configureOnboardingPanel(_ window: NSWindow) {
|
||||
if window.identifier == nil || window.identifier != Self.onboardingWindowIdentifier {
|
||||
window.identifier = Self.onboardingWindowIdentifier
|
||||
}
|
||||
|
||||
let requiredStyleMask: NSWindow.StyleMask = [.titled, .fullSizeContentView, .resizable]
|
||||
window.styleMask.formUnion(requiredStyleMask)
|
||||
window.titlebarAppearsTransparent = true
|
||||
@ -112,6 +123,8 @@ extension WindowManager: NSWindowDelegate {
|
||||
guard let window = notification.object as? NSWindow else { return }
|
||||
if window.identifier == Self.mainWindowIdentifier {
|
||||
window.orderOut(nil)
|
||||
mainWindow = nil
|
||||
didApplyInitialPlacement = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user