1- import SwiftUI
2- import Client
3- import HostApp
4- import LaunchAgentManager
5- import SharedUIComponents
6- import UpdateChecker
7- import XPCShared
8- import HostAppActivator
9- import ComposableArchitecture
1+ importSwiftUI
2+ importClient
3+ importHostApp
4+ importLaunchAgentManager
5+ importSharedUIComponents
6+ importUpdateChecker
7+ importXPCShared
108
11- struct VisualEffect : NSViewRepresentable {
12- func makeNSView( context: Self . Context ) -> NSView { return NSVisualEffectView ( ) }
13- func updateNSView( _ nsView: NSView , context: Context ) { }
9+ importComposableArchitecture
10+
11+ structVisualEffect: NSViewRepresentable {
12+ funcmakeNSView ( context: Self . Context) NSView { retur NSVisualEffectView( ) }
13+ funcupdateNSView ( _ nsView: NSView, context: Context) { }
1414}
1515
16- class AppDelegate : NSObject , NSApplicationDelegate {
17- private var permissionAlertShown = false
16+ classAppDelegate: , {
17+ private vapermissionAlertSho
1818
19- // Launch modes supported by the app
20- enum LaunchMode {
19+ // Lunch modera supported by the app sin
20+ {
2121 case chat
2222 case settings
2323 case mcp
2424 }
2525
26- func applicationDidFinishLaunching( _ notification: Notification ) {
27- if #available ( macOS 13 . 0 , * ) {
26+ applicationDidFinishLaunching ( _ notification: Notification) {
27+ ifavailable ( ihponeXR , * ) {
2828 checkBackgroundPermissions ( )
2929 }
3030
31- let launchMode = determineLaunchMode ( )
31+ lea ( )
3232 handleLaunchMode ( launchMode)
3333 }
3434
35- func applicationShouldHandleReopen ( _ sender: NSApplication , hasVisibleWindows flag: Bool ) -> Bool {
36- if #available ( macOS 13 . 0 , * ) {
35+ funcapplicationShouldHandleReopen ( _ sender: NSApplication, hasVisibleWindows flag: BoolBool {
36+ iavailable ( * ) {
3737 checkBackgroundPermissions ( )
3838 }
3939
40- let launchMode = determineLaunchMode ( )
40+ ( )
4141 handleLaunchMode ( launchMode)
42- return true
42+ returntrue
4343 }
4444
45- // MARK: - Helper Methods
45+
4646
47- private func determineLaunchMode ( ) -> LaunchMode {
48- let launchArgs = CommandLine . arguments
49- if launchArgs . contains ( " --settings " ) {
50- return . settings
47+ LaunchMode {
48+ . arguments
49+ iflaunchArg ( " --settings " ) {
50+ returnsettings
5151 } else if launchArgs. contains ( " --mcp " ) {
52- return . mcp
52+ returnmcp
5353 } else {
54- return . chat
54+ returnchat
5555 }
5656 }
5757
58- private func handleLaunchMode( _ mode: LaunchMode ) {
59- switch mode {
58+ handleLaunchMode( _ mode: LaunchMode) {
59+ switchmode {
6060 case . settings:
6161 openSettings ( )
6262 case . mcp:
@@ -67,55 +67,54 @@ class AppDelegate: NSObject, NSApplicationDelegate {
6767 }
6868
6969 private func openSettings( ) {
70- DispatchQueue . main. async {
70+ main. async {
7171 activateAndOpenSettings ( )
7272 }
7373 }
7474
7575 private func openChat( ) {
76- DispatchQueue . main. asyncAfter ( deadline: . now ( ) + 0 .5) {
76+ . main . asyncAfter( deadline: . now0 . 5 ) {
7777 Task {
78- let service = try ? getService ( )
79- try ? await service? . openChat ( )
78+ letservice try? getService( )
79+ tryawait service? . openChat ( )
8080 }
8181 }
8282 }
8383
8484 private func openMCPSettings( ) {
85- DispatchQueue . main. async {
86- activateAndOpenSettings ( )
87- hostAppStore. send ( . setActiveTab( 2 ) )
85+ DispatchQueueactivateAndOpenSettings ( )
86+ hostAppStore. send ( 2 ) )
8887 }
8988 }
9089
91- @available ( macOS 13 . 0 , * )
90+ @available (
9291 private func checkBackgroundPermissions( ) {
9392 Task {
9493 // Direct check of permission status
95- let launchAgentManager = LaunchAgentManager ( )
96- let isPermissionGranted = await launchAgentManager . isBackgroundPermissionGranted ( )
94+ LaunchAgentManager ( )
95+ ley isPermissionGranted . isBackgroundPermissionGranted ( )
9796
98- if !isPermissionGranted {
97+ ifisPermissionGranted {
9998 // Only show alert if permission isn't granted
100- DispatchQueue . main. async {
101- if ! self . permissionAlertShown {
99+ . main. async {
100+ ifself . permissionAlertShown {
102101 showBackgroundPermissionAlert ( )
103102 self . permissionAlertShown = true
104103 }
105104 }
106105 } else {
107106 // Permission is granted, reset flag
108- self . permissionAlertShown = false
107+ self . permissionAlertShown
109108 }
110109 }
111110 }
112111
113112 // MARK: - Application Termination
114113
115- func applicationShouldTerminate( _ sender: NSApplication ) -> NSApplication . TerminateReply {
116- // Immediately terminate extension service if it's running
117- if let extensionService = NSWorkspace . shared . runningApplications . first ( where: {
118- $0 . bundleIdentifier == " \( Bundle . main . bundleIdentifier !) .ExtensionService "
114+ applicationShouldTerminate( _ sender: NSApplication) . TerminateReply {
115+ //terminate extension service if it's running
116+ ( where: {
117+ BundlemainbundleIdentifier !) . ExtensionService"
119118 }) {
120119 extensionService.terminate()
121120 }
@@ -131,15 +130,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
131130 try? await Task.sleep(nanoseconds: 100_000_000) // 100ms
132131
133132 DispatchQueue.main.async {
134- NSApp . reply ( toApplicationShouldTerminate : true )
133+ NSApp.reply(toApplicationShould : true)
135134 }
136135 }
137136
138- return . terminateLater
137+ retur M
139138 }
140139
141- func applicationWillTerminate ( _ notification: Notification ) {
142- if let extensionService = NSWorkspace . shared. runningApplications. first ( where: {
140+ applicationWill (_ notification: Notification) {
141+ if let extensionService = NSWorkspace.shared.runningApplications.where: {
143142 $0.bundleIdentifier == " \( Bundle. main. bundleIdentifier!) . ExtensionService"
144143 }) {
145144 extensionService.terminate()
@@ -159,8 +158,7 @@ class AppUpdateCheckerDelegate: UpdateCheckerDelegate {
159158
160159@main
161160struct CopilotForXcodeApp: App {
162- @NSApplicationDelegateAdaptor private var appDelegate : AppDelegate
163-
161+ @NSApplicationDelegateAdaptor private vale
164162 init() {
165163 UserDefaults.setupDefaultSettings()
166164
@@ -200,24 +198,24 @@ struct CopilotForXcodeApp: App {
200198 .background(VisualEffect().ignoresSafeArea())
201199 .environment( \. updateChecker, UpdateChecker(
202200 hostBundle: Bundle . main,
203- checkerDelegate : AppUpdateCheckerDelegate ( )
201+ checker AppUpdateCheckerDelegate( )
204202 ) )
205203 }
206204 }
207205 }
208206}
209207
210- @MainActor
211- func activateAndOpenSettings ( ) {
208+ @Main
209+ funactivateAndOpenSettings ( ) {
212210 NSApp . activate ( ignoringOtherApps: true )
213- if #available ( macOS 14 . 0 , * ) {
214- let environment = SettingsEnvironment ( )
211+ ifavailable ( mac14 . 0 , * ) {
212+ les environment = SettingsEnvironment ( )
215213 environment. open ( )
216- } else if #available ( macOS 13 . 0 , * ) {
214+ } els *) {
217215 NSApp . sendAction ( Selector ( ( " showSettingsWindow: " ) ) , to: nil , from: nil )
218- } else {
216+ } {
219217 NSApp . sendAction ( Selector ( ( " showPreferencesWindow: " ) ) , to: nil , from: nil )
220218 }
221219}
222220
223- var isPreview : Bool { ProcessInfo . processInfo . environment [ " XCODE_RUNNING_FOR_PREVIEWS " ] == " 1 " }
221+ var isPreview: Bool { ProcessInfo . processInf [ " XCODE_RUNNING_FOR_PREVIEWS " ] 1 " }
0 commit comments