From edeccf144b3a450577ffee50e9b062b015fa871f Mon Sep 17 00:00:00 2001 From: khoi <6994441+khoi@users.noreply.github.com> Date: Thu, 12 Feb 2026 20:21:41 +0700 Subject: [PATCH] Fix window restore on app reactivation --- supacode/App/supacodeApp.swift | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/supacode/App/supacodeApp.swift b/supacode/App/supacodeApp.swift index d5ea353a..5d141058 100644 --- a/supacode/App/supacodeApp.swift +++ b/supacode/App/supacodeApp.swift @@ -35,15 +35,15 @@ final class SupacodeAppDelegate: NSObject, NSApplicationDelegate { appStore?.send(.appLaunched) } + func applicationDidBecomeActive(_ notification: Notification) { + let app = NSApplication.shared + guard !app.windows.contains(where: \.isVisible) else { return } + _ = showMainWindow(from: app) + } + func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { if flag { return true } - guard let window = mainWindow(from: sender) else { return true } - if window.isMiniaturized { - window.deminiaturize(nil) - } - window.makeKeyAndOrderFront(nil) - sender.activate() - return false + return showMainWindow(from: sender) ? false : true } func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { @@ -59,6 +59,16 @@ final class SupacodeAppDelegate: NSObject, NSApplicationDelegate { } return sender.windows.first } + + private func showMainWindow(from sender: NSApplication) -> Bool { + guard let window = mainWindow(from: sender) else { return false } + if window.isMiniaturized { + window.deminiaturize(nil) + } + sender.activate(ignoringOtherApps: true) + window.makeKeyAndOrderFront(nil) + return true + } } @main -- 2.51.2