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
71 lines (66 loc) · 2.5 KB
/
LaunchAgentView.swift
File metadata and controls
71 lines (66 loc) · 2.5 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
import SwiftUI
struct LaunchAgentView: View {
@State var errorMessage: String?
@State var isDidRemoveLaunchAgentAlertPresented = false
@State var isDidSetupLaunchAgentAlertPresented = false
var body: some View {
Section {
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"))
)
}
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"))
)
}
}
}.buttonStyle(.copilot)
}
}
struct LaunchAgentView_Preview: PreviewProvider {
static var previews: some View {
LaunchAgentView()
.background(.black)
}
}