forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneralSettingsView.swift
More file actions
78 lines (73 loc) · 2.69 KB
/
GeneralSettingsView.swift
File metadata and controls
78 lines (73 loc) · 2.69 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
import ComposableArchitecture
import SwiftUI
struct GeneralSettingsView: View {
@AppStorage(\.extensionPermissionShown) var extensionPermissionShown: Bool
@AppStorage(\.quitXPCServiceOnXcodeAndAppQuit) var quitXPCServiceOnXcodeAndAppQuit: Bool
@State private var shouldPresentExtensionPermissionAlert = false
let store: StoreOf<General>
var accessibilityPermissionSubtitle: String {
switch store.isAccessibilityPermissionGranted {
case .granted:
return "Granted"
case .notGranted:
return "Not Granted. Required to run. Click to open System Preferences."
case .unknown:
return ""
}
}
var body: some View {
SettingsSection(title: "General") {
SettingsToggle(
title: "Quit GitHub Copilot when Xcode App is closed",
isOn: $quitXPCServiceOnXcodeAndAppQuit
)
Divider()
SettingsLink(
url: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility",
title: "Accessibility Permission",
subtitle: accessibilityPermissionSubtitle
)
Divider()
SettingsLink(
url: "x-apple.systempreferences:com.apple.ExtensionsPreferences",
title: "Extension Permission",
subtitle: """
Check for GitHub Copilot in Xcode's Editor menu. \
Restart Xcode if greyed out.
"""
)
} footer: {
HStack {
Spacer()
Button("?") {
NSWorkspace.shared.open(
URL(string: "https://github.com/github/CopilotForXcode/blob/main/TROUBLESHOOTING.md")!
)
}
.clipShape(Circle())
}
}
.alert(
"Enable Extension Permission",
isPresented: $shouldPresentExtensionPermissionAlert
) {
Button("Open System Preferences", action: {
let url = "x-apple.systempreferences:com.apple.ExtensionsPreferences"
NSWorkspace.shared.open(URL(string: url)!)
}).keyboardShortcut(.defaultAction)
Button("Close", role: .cancel, action: {})
} message: {
Text("Enable GitHub Copilot under Xcode Source Editor extensions")
}
.task {
if extensionPermissionShown { return }
extensionPermissionShown = true
shouldPresentExtensionPermissionAlert = true
}
}
}
#Preview {
GeneralSettingsView(
store: .init(initialState: .init(), reducer: { General() })
)
}