@@ -13,18 +13,28 @@ struct VisualEffect: NSViewRepresentable {
13
13
}
14
14
15
15
class AppDelegate : NSObject , NSApplicationDelegate {
16
+ private var permissionAlertShown = false
17
+
16
18
// Launch modes supported by the app
17
19
enum LaunchMode {
18
20
case chat
19
21
case settings
20
22
}
21
23
22
24
func applicationDidFinishLaunching( _ notification: Notification ) {
25
+ if #available( macOS 13 . 0 , * ) {
26
+ checkBackgroundPermissions ( )
27
+ }
28
+
23
29
let launchMode = determineLaunchMode ( )
24
30
handleLaunchMode ( launchMode)
25
31
}
26
32
27
33
func applicationShouldHandleReopen( _ sender: NSApplication , hasVisibleWindows flag: Bool ) -> Bool {
34
+ if #available( macOS 13 . 0 , * ) {
35
+ checkBackgroundPermissions ( )
36
+ }
37
+
28
38
let launchMode = determineLaunchMode ( )
29
39
handleLaunchMode ( launchMode)
30
40
return true
@@ -73,6 +83,28 @@ class AppDelegate: NSObject, NSApplicationDelegate {
73
83
}
74
84
}
75
85
86
+ @available ( macOS 13 . 0 , * )
87
+ private func checkBackgroundPermissions( ) {
88
+ Task {
89
+ // Direct check of permission status
90
+ let launchAgentManager = LaunchAgentManager ( )
91
+ let isPermissionGranted = await launchAgentManager. isBackgroundPermissionGranted ( )
92
+
93
+ if !isPermissionGranted {
94
+ // Only show alert if permission isn't granted
95
+ DispatchQueue . main. async {
96
+ if !self . permissionAlertShown {
97
+ showBackgroundPermissionAlert ( )
98
+ self . permissionAlertShown = true
99
+ }
100
+ }
101
+ } else {
102
+ // Permission is granted, reset flag
103
+ self . permissionAlertShown = false
104
+ }
105
+ }
106
+ }
107
+
76
108
// MARK: - Application Termination
77
109
78
110
func applicationShouldTerminate( _ sender: NSApplication ) -> NSApplication . TerminateReply {
0 commit comments