| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // AppDelegate.swift
- // App for Indeed
- //
- // Created by Mql Mac 2 on 11/05/2026.
- //
- import Cocoa
- @main
- class AppDelegate: NSObject, NSApplicationDelegate {
- private let minimumWindowSize = NSSize(width: 1120, height: 700)
- /// Avoids hammering StoreKit when `didBecomeActive` fires in quick succession (e.g. after system sheets).
- private var lastSubscriptionRefreshAt: Date?
- func applicationWillFinishLaunching(_ notification: Notification) {
- // Dashboard is light-themed; without this, a Dark Mode Mac paints a dark title bar.
- NSApp.appearance = NSAppearance(named: .aqua)
- }
- func applicationDidFinishLaunching(_ aNotification: Notification) {
- 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)
- }
- }
- Task { @MainActor in
- // Do not call `AppStore.sync()` here — it prompts "Sign in with Apple Account" in Xcode / StoreKit
- // testing and can repeat when the app re-activates after dismissing the sheet. Sync only from
- // explicit "Restore purchases" in `SubscriptionStore.restorePurchases()`.
- lastSubscriptionRefreshAt = Date()
- await SubscriptionStore.shared.refreshEntitlements(deep: true)
- NotificationCenter.default.post(name: .subscriptionStatusDidChange, object: nil)
- }
- NSApp.activate(ignoringOtherApps: true)
- DispatchQueue.main.async { [weak self] in
- guard
- let self,
- let window = NSApp.windows.first
- else { return }
- window.minSize = self.minimumWindowSize
- window.setContentSize(self.minimumWindowSize)
- // Prevents "className=(null)" restoration warnings; layout is applied each launch.
- window.isRestorable = false
- window.title = "App for Indeed"
- window.styleMask.insert(.fullSizeContentView)
- window.titlebarAppearsTransparent = true
- window.titleVisibility = .hidden
- window.isMovableByWindowBackground = true
- window.center()
- window.makeKeyAndOrderFront(nil)
- }
- }
- 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
- }
- }
|