| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- //
- // AppDelegate.swift
- // zoom_app
- //
- // Created by Dev Mac 1 on 14/04/2026.
- //
- import Cocoa
- @main
- class AppDelegate: NSObject, NSApplicationDelegate {
- private let darkModeDefaultsKey = "settings.darkModeEnabled"
- private enum DefaultWindowSize {
- static let width: CGFloat = 1020
- static let height: CGFloat = 690
- }
-
-
- func applicationDidFinishLaunching(_ aNotification: Notification) {
- let hasValue = UserDefaults.standard.object(forKey: darkModeDefaultsKey) != nil
- let darkEnabled = hasValue ? UserDefaults.standard.bool(forKey: darkModeDefaultsKey) : systemPrefersDarkMode()
- if hasValue == false {
- UserDefaults.standard.set(darkEnabled, forKey: darkModeDefaultsKey)
- }
- NSApp.appearance = NSAppearance(named: darkEnabled ? .darkAqua : .aqua)
- // Force a consistent launch size (avoid state restoration overriding it).
- DispatchQueue.main.async { [weak self] in
- self?.applyDefaultWindowSizeIfNeeded()
- }
- }
- func applicationWillTerminate(_ aNotification: Notification) {
- // Insert code here to tear down your application
- }
- func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
- // If enabled, macOS can restore the last window frame (size/position) on next launch.
- // This app wants a consistent default launch size instead.
- return false
- }
- private func applyDefaultWindowSizeIfNeeded() {
- let targetSize = NSSize(width: DefaultWindowSize.width, height: DefaultWindowSize.height)
- for window in NSApplication.shared.windows {
- // Only touch the main app window (not OAuth popups, alerts, etc.).
- guard window.contentViewController is ViewController else { continue }
- window.isRestorable = false
- window.setContentSize(targetSize)
- window.center()
- }
- }
- private func systemPrefersDarkMode() -> Bool {
- let global = UserDefaults.standard.persistentDomain(forName: UserDefaults.globalDomain)
- let style = global?["AppleInterfaceStyle"] as? String
- return style?.lowercased() == "dark"
- }
- }
|