forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsView.swift
More file actions
72 lines (65 loc) · 2.71 KB
/
SettingsView.swift
File metadata and controls
72 lines (65 loc) · 2.71 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
import LaunchAgentManager
import SwiftUI
import XPCShared
struct SettingsView: View {
@AppStorage(SettingsKey.quitXPCServiceOnXcodeAndAppQuit, store: .shared)
var quitXPCServiceOnXcodeAndAppQuit: Bool = false
@AppStorage(SettingsKey.realtimeSuggestionToggle, store: .shared)
var realtimeSuggestionToggle: Bool = false
@AppStorage(SettingsKey.realtimeSuggestionDebounce, store: .shared)
var realtimeSuggestionDebounce: Double = 0.7
@AppStorage(SettingsKey.suggestionPresentationMode, store: .shared)
var suggestionPresentationModeRawValue: Int = 0
@State var editingRealtimeSuggestionDebounce: Double = UserDefaults.shared
.value(forKey: SettingsKey.realtimeSuggestionDebounce) as? Double ?? 0.7
var body: some View {
Section {
Form {
Toggle(isOn: $quitXPCServiceOnXcodeAndAppQuit) {
Text("Quit service when Xcode and host app are terminated")
}
.toggleStyle(.switch)
Picker(selection: $suggestionPresentationModeRawValue) {
ForEach(PresentationMode.allCases, id: \.rawValue) {
switch $0 {
case .comment:
Text("Comment")
case .floatingWidget:
Text("Floating Widget")
}
}
} label: {
Text("Present suggestions in")
}
Toggle(isOn: $realtimeSuggestionToggle) {
Text("Real-time suggestion")
}
.toggleStyle(.switch)
HStack {
Slider(value: $editingRealtimeSuggestionDebounce, in: 0...2, step: 0.1) {
Text("Real-time suggestion fetch debounce")
} onEditingChanged: { _ in
realtimeSuggestionDebounce = editingRealtimeSuggestionDebounce
}
Text(
"\(editingRealtimeSuggestionDebounce.formatted(.number.precision(.fractionLength(2))))s"
)
.font(.body)
.monospacedDigit()
.padding(.vertical, 2)
.padding(.horizontal, 6)
.background(
RoundedRectangle(cornerRadius: 4, style: .continuous)
.fill(Color.white.opacity(0.2))
)
}
}
}.buttonStyle(.copilot)
}
}
struct SettingsView_Preview: PreviewProvider {
static var previews: some View {
SettingsView()
.background(.purple)
}
}