Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: App/AppDelegate.swift3// Description: Application delegate: activity tracking (no polling in the background), the optional window lock, notification permission on demand, and a guard that the main window exists after a relaunch.4import AppKit5import UserNotifications67@MainActor final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate {8 weak var model: AppModel?910 func applicationDidFinishLaunching(_ notification: Notification) {11 UNUserNotificationCenter.current().delegate = self12 NSWindow.allowsAutomaticWindowTabbing = false13 }14 func applicationDidBecomeActive(_ notification: Notification) {15 AppActivity.isActive = true16 model?.lock.appDidBecomeActive()17 if let m = model, m.phase == .signedIn { Task { await m.refreshPortfolio() } }18 }19 func applicationDidResignActive(_ notification: Notification) { AppActivity.isActive = false; model?.lock.appDidResign() }20 func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true }21 func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { true }2223 // a notification is shown even when the app is frontmost24 nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions { [.banner, .list, .sound] }25}26