Açıklama Yok

AppDelegate.swift 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // AppDelegate.swift
  3. // zoom_app
  4. //
  5. // Created by Dev Mac 1 on 14/04/2026.
  6. //
  7. import Cocoa
  8. @main
  9. class AppDelegate: NSObject, NSApplicationDelegate {
  10. private let darkModeDefaultsKey = "settings.darkModeEnabled"
  11. private enum DefaultWindowSize {
  12. static let width: CGFloat = 1020
  13. static let height: CGFloat = 690
  14. }
  15. func applicationDidFinishLaunching(_ aNotification: Notification) {
  16. let hasValue = UserDefaults.standard.object(forKey: darkModeDefaultsKey) != nil
  17. let darkEnabled = hasValue ? UserDefaults.standard.bool(forKey: darkModeDefaultsKey) : systemPrefersDarkMode()
  18. if hasValue == false {
  19. UserDefaults.standard.set(darkEnabled, forKey: darkModeDefaultsKey)
  20. }
  21. NSApp.appearance = NSAppearance(named: darkEnabled ? .darkAqua : .aqua)
  22. // Force a consistent launch size (avoid state restoration overriding it).
  23. DispatchQueue.main.async { [weak self] in
  24. self?.applyDefaultWindowSizeIfNeeded()
  25. }
  26. }
  27. func applicationWillTerminate(_ aNotification: Notification) {
  28. // Insert code here to tear down your application
  29. }
  30. func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
  31. // If enabled, macOS can restore the last window frame (size/position) on next launch.
  32. // This app wants a consistent default launch size instead.
  33. return false
  34. }
  35. private func applyDefaultWindowSizeIfNeeded() {
  36. let targetSize = NSSize(width: DefaultWindowSize.width, height: DefaultWindowSize.height)
  37. for window in NSApplication.shared.windows {
  38. // Only touch the main app window (not OAuth popups, alerts, etc.).
  39. guard window.contentViewController is ViewController else { continue }
  40. window.isRestorable = false
  41. window.setContentSize(targetSize)
  42. window.center()
  43. }
  44. }
  45. private func systemPrefersDarkMode() -> Bool {
  46. let global = UserDefaults.standard.persistentDomain(forName: UserDefaults.globalDomain)
  47. let style = global?["AppleInterfaceStyle"] as? String
  48. return style?.lowercased() == "dark"
  49. }
  50. }