|
1 | 1 | import SwiftUI |
| 2 | +import XPCShared |
2 | 3 |
|
3 | 4 | struct LaunchAgentView: View { |
4 | 5 | @State var errorMessage: String? |
5 | 6 | @State var isDidRemoveLaunchAgentAlertPresented = false |
6 | 7 | @State var isDidSetupLaunchAgentAlertPresented = false |
7 | 8 | @State var isDidRestartLaunchAgentAlertPresented = false |
8 | | - |
| 9 | + @AppStorage(SettingsKey.nodePath, store: .shared) var nodePath: String = "" |
| 10 | + |
9 | 11 | var body: some View { |
10 | 12 | Section { |
11 | | - HStack { |
12 | | - Button(action: { |
13 | | - do { |
14 | | - try LaunchAgentManager().setupLaunchAgent() |
15 | | - isDidSetupLaunchAgentAlertPresented = true |
16 | | - } catch { |
17 | | - errorMessage = error.localizedDescription |
| 13 | + VStack(alignment: .leading, spacing: 8) { |
| 14 | + HStack { |
| 15 | + Button(action: { |
| 16 | + do { |
| 17 | + try LaunchAgentManager().setupLaunchAgent() |
| 18 | + isDidSetupLaunchAgentAlertPresented = true |
| 19 | + } catch { |
| 20 | + errorMessage = error.localizedDescription |
| 21 | + } |
| 22 | + }) { |
| 23 | + Text("Set Up Launch Agent for XPC Service") |
18 | 24 | } |
19 | | - }) { |
20 | | - Text("Set Up Launch Agent for XPC Service") |
21 | | - } |
22 | | - .alert(isPresented: $isDidSetupLaunchAgentAlertPresented) { |
23 | | - .init( |
24 | | - title: Text("Finished Launch Agent Setup"), |
25 | | - message: Text( |
26 | | - "You may need to restart Xcode to make the extension work." |
27 | | - ), |
28 | | - dismissButton: .default(Text("OK")) |
29 | | - ) |
30 | | - } |
31 | | - |
32 | | - Button(action: { |
33 | | - do { |
34 | | - try LaunchAgentManager().removeLaunchAgent() |
35 | | - isDidRemoveLaunchAgentAlertPresented = true |
36 | | - } catch { |
37 | | - errorMessage = error.localizedDescription |
| 25 | + .alert(isPresented: $isDidSetupLaunchAgentAlertPresented) { |
| 26 | + .init( |
| 27 | + title: Text("Finished Launch Agent Setup"), |
| 28 | + message: Text( |
| 29 | + "You may need to restart Xcode to make the extension work." |
| 30 | + ), |
| 31 | + dismissButton: .default(Text("OK")) |
| 32 | + ) |
38 | 33 | } |
39 | | - }) { |
40 | | - Text("Remove Launch Agent") |
41 | | - } |
42 | | - .alert(isPresented: $isDidRemoveLaunchAgentAlertPresented) { |
43 | | - .init( |
44 | | - title: Text("Launch Agent Removed"), |
45 | | - dismissButton: .default(Text("OK")) |
46 | | - ) |
47 | | - } |
48 | | - |
49 | | - Button(action: { |
50 | | - LaunchAgentManager().restartLaunchAgent() |
51 | | - isDidRestartLaunchAgentAlertPresented = true |
52 | | - }) { |
53 | | - Text("Restart XPC Service") |
54 | | - }.alert(isPresented: $isDidRestartLaunchAgentAlertPresented) { |
55 | | - .init( |
56 | | - title: Text("Launch Agent Restarted"), |
57 | | - dismissButton: .default(Text("OK")) |
58 | | - ) |
59 | | - } |
60 | 34 |
|
61 | | - EmptyView() |
62 | | - .alert(isPresented: .init( |
63 | | - get: { errorMessage != nil }, |
64 | | - set: { yes in |
65 | | - if !yes { errorMessage = nil } |
| 35 | + Button(action: { |
| 36 | + do { |
| 37 | + try LaunchAgentManager().removeLaunchAgent() |
| 38 | + isDidRemoveLaunchAgentAlertPresented = true |
| 39 | + } catch { |
| 40 | + errorMessage = error.localizedDescription |
66 | 41 | } |
67 | | - )) { |
| 42 | + }) { |
| 43 | + Text("Remove Launch Agent") |
| 44 | + } |
| 45 | + .alert(isPresented: $isDidRemoveLaunchAgentAlertPresented) { |
| 46 | + .init( |
| 47 | + title: Text("Launch Agent Removed"), |
| 48 | + dismissButton: .default(Text("OK")) |
| 49 | + ) |
| 50 | + } |
| 51 | + |
| 52 | + Button(action: { |
| 53 | + LaunchAgentManager().restartLaunchAgent() |
| 54 | + isDidRestartLaunchAgentAlertPresented = true |
| 55 | + }) { |
| 56 | + Text("Restart XPC Service") |
| 57 | + }.alert(isPresented: $isDidRestartLaunchAgentAlertPresented) { |
68 | 58 | .init( |
69 | | - title: Text("Failed. Got to the GitHub page for Help"), |
70 | | - message: Text(errorMessage ?? "Unknown Error"), |
| 59 | + title: Text("Launch Agent Restarted"), |
71 | 60 | dismissButton: .default(Text("OK")) |
72 | 61 | ) |
73 | 62 | } |
| 63 | + |
| 64 | + EmptyView() |
| 65 | + .alert(isPresented: .init( |
| 66 | + get: { errorMessage != nil }, |
| 67 | + set: { yes in |
| 68 | + if !yes { errorMessage = nil } |
| 69 | + } |
| 70 | + )) { |
| 71 | + .init( |
| 72 | + title: Text("Failed. Got to the GitHub page for Help"), |
| 73 | + message: Text(errorMessage ?? "Unknown Error"), |
| 74 | + dismissButton: .default(Text("OK")) |
| 75 | + ) |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + HStack { |
| 80 | + Text("Path to Node: ") |
| 81 | + TextField("node", text: $nodePath) |
| 82 | + .textFieldStyle(.copilot) |
| 83 | + } |
74 | 84 | } |
75 | 85 | }.buttonStyle(.copilot) |
76 | 86 | } |
|
0 commit comments