-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathGeneralView.swift
More file actions
244 lines (220 loc) · 8.34 KB
/
GeneralView.swift
File metadata and controls
244 lines (220 loc) · 8.34 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import Client
import ComposableArchitecture
import KeyboardShortcuts
import LaunchAgentManager
import Preferences
import SharedUIComponents
import SwiftUI
struct GeneralView: View {
let store: StoreOf<General>
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 0) {
AppInfoView(store: store)
SettingsDivider()
GitHubCopilotView()
SettingsDivider()
ExtensionServiceView(store: store)
SettingsDivider()
LaunchAgentView()
SettingsDivider()
GeneralSettingsView()
}
}
.onAppear {
store.send(.appear)
}
}
}
struct AppInfoView: View {
@State var appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
@Environment(\.updateChecker) var updateChecker
let store: StoreOf<General>
var body: some View {
VStack(alignment: .leading) {
HStack(alignment: .top) {
Text(
Bundle.main
.object(forInfoDictionaryKey: "HOST_APP_NAME") as? String
?? "GitHub Copilot for Xcode"
)
.font(.title)
Text(appVersion ?? "")
.font(.footnote)
.foregroundColor(.secondary)
Spacer()
Button(action: {
updateChecker.checkForUpdates()
}) {
HStack(spacing: 2) {
Image(systemName: "arrow.up.right.circle.fill")
Text("Check for Updates")
}
}
}
}.padding()
}
}
struct ExtensionServiceView: View {
@Perception.Bindable var store: StoreOf<General>
var body: some View {
WithPerceptionTracking {
VStack(alignment: .leading) {
Text("Extension Service Version: \(store.xpcServiceVersion ?? "Loading..")")
let grantedStatus: String = {
guard let granted = store.isAccessibilityPermissionGranted
else { return "Loading.." }
return granted ? "Granted" : "Not Granted"
}()
Text("Accessibility Permission: \(grantedStatus)")
HStack {
Button(action: { store.send(.reloadStatus) }) {
Text("Refresh")
}.disabled(store.isReloading)
Button(action: {
Task {
let workspace = NSWorkspace.shared
let url = Bundle.main.bundleURL
.appendingPathComponent("Contents")
.appendingPathComponent("Applications")
.appendingPathComponent("GitHub Copilot for Xcode Extension.app")
workspace.activateFileViewerSelecting([url])
}
}) {
Text("Reveal Extension Service in Finder")
}
Button(action: {
let url = URL(
string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility"
)!
NSWorkspace.shared.open(url)
}) {
Text("Accessibility Settings")
}
Button(action: {
let url = URL(
string: "x-apple.systempreferences:com.apple.ExtensionsPreferences"
)!
NSWorkspace.shared.open(url)
}) {
Text("Extensions Settings")
}
}
}
}
.padding()
}
}
struct LaunchAgentView: View {
@Environment(\.toast) var toast
@State var isDidRemoveLaunchAgentAlertPresented = false
@State var isDidSetupLaunchAgentAlertPresented = false
@State var isDidRestartLaunchAgentAlertPresented = false
var body: some View {
VStack(alignment: .leading) {
HStack {
Button(action: {
Task {
do {
try await LaunchAgentManager().setupLaunchAgent()
isDidSetupLaunchAgentAlertPresented = true
} catch {
toast(error.localizedDescription, .error)
}
}
}) {
Text("Set Up Launch Agent")
}
.alert(isPresented: $isDidSetupLaunchAgentAlertPresented) {
.init(
title: Text("Finished Launch Agent Setup"),
message: Text(
"Please refresh the Copilot status. (The first refresh may fail)"
),
dismissButton: .default(Text("OK"))
)
}
Button(action: {
Task {
do {
try await LaunchAgentManager().removeLaunchAgent()
isDidRemoveLaunchAgentAlertPresented = true
} catch {
toast(error.localizedDescription, .error)
}
}
}) {
Text("Remove Launch Agent")
}
.alert(isPresented: $isDidRemoveLaunchAgentAlertPresented) {
.init(
title: Text("Launch Agent Removed"),
dismissButton: .default(Text("OK"))
)
}
Button(action: {
Task {
do {
try await LaunchAgentManager().reloadLaunchAgent()
isDidRestartLaunchAgentAlertPresented = true
} catch {
toast(error.localizedDescription, .error)
}
}
}) {
Text("Reload Launch Agent")
}.alert(isPresented: $isDidRestartLaunchAgentAlertPresented) {
.init(
title: Text("Launch Agent Reloaded"),
dismissButton: .default(Text("OK"))
)
}
}
}
.padding()
}
}
struct GeneralSettingsView: View {
class Settings: ObservableObject {
@AppStorage(\.quitXPCServiceOnXcodeAndAppQuit)
var quitXPCServiceOnXcodeAndAppQuit
@AppStorage(\.suggestionWidgetPositionMode)
var suggestionWidgetPositionMode
@AppStorage(\.widgetColorScheme)
var widgetColorScheme
@AppStorage(\.preferWidgetToStayInsideEditorWhenWidthGreaterThan)
var preferWidgetToStayInsideEditorWhenWidthGreaterThan
@AppStorage(\.showHideWidgetShortcutGlobally)
var showHideWidgetShortcutGlobally
@AppStorage(\.installPrereleases)
var installPrereleases
}
@StateObject var settings = Settings()
@Environment(\.updateChecker) var updateChecker
@State var automaticallyCheckForUpdate: Bool?
var body: some View {
Form {
Toggle(isOn: $settings.quitXPCServiceOnXcodeAndAppQuit) {
Text("Quit service when Xcode and host app are terminated")
}
Toggle(isOn: .init(
get: { automaticallyCheckForUpdate ?? updateChecker.automaticallyChecksForUpdates },
set: {
updateChecker.automaticallyChecksForUpdates = $0
automaticallyCheckForUpdate = $0
}
)) {
Text("Automatically Check for Updates")
}
Toggle(isOn: $settings.installPrereleases) {
Text("Install pre-releases")
}
}.padding()
}
}
struct GeneralView_Previews: PreviewProvider {
static var previews: some View {
GeneralView(store: .init(initialState: .init(), reducer: { General() }))
.frame(height: 800)
}
}