// // AppDelegate.swift // App for Indeed // // Created by Mql Mac 2 on 11/05/2026. // import Cocoa enum AppWindowConfiguration { static let defaultContentSize = NSSize(width: 1120, height: 800) static let minimumContentSize = NSSize(width: 1120, height: 800) @MainActor static func apply(to window: NSWindow) { window.minSize = minimumContentSize window.isRestorable = false window.title = AppMarketingLinks.appDisplayName window.styleMask.insert(.fullSizeContentView) window.titlebarAppearsTransparent = true window.titleVisibility = .hidden window.isMovableByWindowBackground = true // Same as dashboard chrome — avoids a halo outside the frame with fullSizeContentView. window.backgroundColor = AppAppearanceManager.shared.windowChromeColor let targetContent = NSRect(origin: .zero, size: defaultContentSize) let targetFrame = window.frameRect(forContentRect: targetContent) var frame = targetFrame let current = window.frame frame.origin.x = current.midX - frame.width / 2 frame.origin.y = current.midY - frame.height / 2 window.setFrame(frame, display: false, animate: false) window.setContentSize(defaultContentSize) } @MainActor static func mainWindow(in app: NSApplication = .shared) -> NSWindow? { app.mainWindow ?? app.keyWindow ?? app.windows.first(where: { $0.isVisible && $0.canBecomeKey }) } } @main class AppDelegate: NSObject, NSApplicationDelegate { /// Avoids hammering StoreKit when `didBecomeActive` fires in quick succession (e.g. after system sheets). private var lastSubscriptionRefreshAt: Date? func applicationWillFinishLaunching(_ notification: Notification) { AppAppearanceManager.shared.apply() } func applicationDidFinishLaunching(_ aNotification: Notification) { AppRatingCoordinator.shared.start() NotificationCenter.default.addObserver( forName: NSApplication.didBecomeActiveNotification, object: nil, queue: .main ) { [weak self] _ in Task { @MainActor in guard let self else { return } let now = Date() if let last = self.lastSubscriptionRefreshAt, now.timeIntervalSince(last) < 2.5 { return } self.lastSubscriptionRefreshAt = now await SubscriptionStore.shared.refreshEntitlements(deep: true) } } // Initial StoreKit refresh runs on `LoadingViewController` before the dashboard is shown. NSApp.activate(ignoringOtherApps: true) applyDefaultWindowSize() } @MainActor private func applyDefaultWindowSize() { DispatchQueue.main.async { [weak self] in guard let self, let window = AppWindowConfiguration.mainWindow() else { return } AppWindowConfiguration.apply(to: window) window.center() window.makeKeyAndOrderFront(nil) // Layout can run after the first pass; enforce default size once more. DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { [weak self] in guard self != nil, let window = AppWindowConfiguration.mainWindow() else { return } AppWindowConfiguration.apply(to: window) window.center() } } } func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { // Opt out until real `NSWindowRestoration` is implemented (avoids null className restore logs). return false } }