@@ -13,18 +13,28 @@ struct VisualEffect: NSViewRepresentable {
1313} 
1414
1515class  AppDelegate :  NSObject ,  NSApplicationDelegate  { 
16+     private  var  permissionAlertShown =  false 
17+     
1618    // Launch modes supported by the app
1719    enum  LaunchMode  { 
1820        case  chat
1921        case  settings
2022    } 
2123
2224    func  applicationDidFinishLaunching( _ notification:  Notification )  { 
25+         if  #available( macOS 13 . 0 ,  * )  { 
26+             checkBackgroundPermissions ( ) 
27+         } 
28+         
2329        let  launchMode  =  determineLaunchMode ( ) 
2430        handleLaunchMode ( launchMode) 
2531    } 
2632
2733    func  applicationShouldHandleReopen( _ sender:  NSApplication ,  hasVisibleWindows flag:  Bool )  ->  Bool  { 
34+         if  #available( macOS 13 . 0 ,  * )  { 
35+             checkBackgroundPermissions ( ) 
36+         } 
37+         
2838        let  launchMode  =  determineLaunchMode ( ) 
2939        handleLaunchMode ( launchMode) 
3040        return  true 
@@ -73,6 +83,28 @@ class AppDelegate: NSObject, NSApplicationDelegate {
7383        } 
7484    } 
7585
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+     
76108    // MARK: - Application Termination
77109
78110    func  applicationShouldTerminate( _ sender:  NSApplication )  ->  NSApplication . TerminateReply  { 
0 commit comments