forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLaunchAgentView.swift
More file actions
95 lines (88 loc) · 3.66 KB
/
LaunchAgentView.swift
File metadata and controls
95 lines (88 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import LaunchAgentManager
import SwiftUI
import XPCShared
struct LaunchAgentView: View {
@State var errorMessage: String?
@State var isDidRemoveLaunchAgentAlertPresented = false
@State var isDidSetupLaunchAgentAlertPresented = false
@State var isDidRestartLaunchAgentAlertPresented = false
@AppStorage(SettingsKey.nodePath, store: .shared) var nodePath: String = ""
var body: some View {
Section {
VStack(alignment: .leading, spacing: 8) {
HStack {
Button(action: {
do {
try LaunchAgentManager().setupLaunchAgent()
isDidSetupLaunchAgentAlertPresented = true
} catch {
errorMessage = error.localizedDescription
}
}) {
Text("Set Up Launch Agent for XPC Service")
}
.alert(isPresented: $isDidSetupLaunchAgentAlertPresented) {
.init(
title: Text("Finished Launch Agent Setup"),
message: Text(
"You may need to restart Xcode to make the extension work."
),
dismissButton: .default(Text("OK"))
)
}
Button(action: {
do {
try LaunchAgentManager().removeLaunchAgent()
isDidRemoveLaunchAgentAlertPresented = true
} catch {
errorMessage = error.localizedDescription
}
}) {
Text("Remove Launch Agent")
}
.alert(isPresented: $isDidRemoveLaunchAgentAlertPresented) {
.init(
title: Text("Launch Agent Removed"),
dismissButton: .default(Text("OK"))
)
}
Button(action: {
LaunchAgentManager().restartLaunchAgent()
isDidRestartLaunchAgentAlertPresented = true
}) {
Text("Restart XPC Service")
}.alert(isPresented: $isDidRestartLaunchAgentAlertPresented) {
.init(
title: Text("Launch Agent Restarted"),
dismissButton: .default(Text("OK"))
)
}
EmptyView()
.alert(isPresented: .init(
get: { errorMessage != nil },
set: { yes in
if !yes { errorMessage = nil }
}
)) {
.init(
title: Text("Failed. Got to the GitHub page for Help"),
message: Text(errorMessage ?? "Unknown Error"),
dismissButton: .default(Text("OK"))
)
}
}
HStack {
Text("Path to Node: ")
TextField("node", text: $nodePath)
.textFieldStyle(.copilot)
}
}
}.buttonStyle(.copilot)
}
}
struct LaunchAgentView_Preview: PreviewProvider {
static var previews: some View {
LaunchAgentView()
.background(.black)
}
}