Нет описания

AppDelegate.swift 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // AppDelegate.swift
  3. // Assistant for Google Meet
  4. //
  5. // Created by Dev Mac 1 on 06/04/2026.
  6. //
  7. import Cocoa
  8. import UserNotifications
  9. @main
  10. class AppDelegate: NSObject, NSApplicationDelegate {
  11. private let darkModeDefaultsKey = "settings.darkModeEnabled"
  12. private var statusBarController: StatusBarController?
  13. func applicationDidFinishLaunching(_ aNotification: Notification) {
  14. // Always sync to current macOS appearance on launch.
  15. // (User can still toggle in-app later.)
  16. let darkEnabled = systemPrefersDarkMode()
  17. UserDefaults.standard.set(darkEnabled, forKey: darkModeDefaultsKey)
  18. NSApp.appearance = NSAppearance(named: darkEnabled ? .darkAqua : .aqua)
  19. UNUserNotificationCenter.current().delegate = self
  20. MeetingReminderManager.shared.requestPermissionIfNeeded()
  21. DesktopWidgetWindowManager.shared.restore()
  22. statusBarController = StatusBarController()
  23. }
  24. func applicationWillTerminate(_ aNotification: Notification) {
  25. // Insert code here to tear down your application
  26. }
  27. func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
  28. return true
  29. }
  30. private func systemPrefersDarkMode() -> Bool {
  31. // Use the system-wide appearance setting (not app/window effective appearance).
  32. // When the key is missing, macOS is in Light mode.
  33. let global = UserDefaults.standard.persistentDomain(forName: UserDefaults.globalDomain)
  34. let style = global?["AppleInterfaceStyle"] as? String
  35. return style?.lowercased() == "dark"
  36. }
  37. }
  38. extension AppDelegate: UNUserNotificationCenterDelegate {
  39. func userNotificationCenter(
  40. _ center: UNUserNotificationCenter,
  41. didReceive response: UNNotificationResponse,
  42. withCompletionHandler completionHandler: @escaping () -> Void
  43. ) {
  44. NSRunningApplication.current.activate(options: [.activateAllWindows, .activateIgnoringOtherApps])
  45. NSApp.activate(ignoringOtherApps: true)
  46. completionHandler()
  47. }
  48. func userNotificationCenter(
  49. _ center: UNUserNotificationCenter,
  50. willPresent notification: UNNotification,
  51. withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
  52. ) {
  53. completionHandler([.banner, .sound])
  54. }
  55. }