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
120 lines (109 loc) · 4.57 KB
/
SettingsView.swift
File metadata and controls
120 lines (109 loc) · 4.57 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
import LaunchAgentManager
import Preferences
import SwiftUI
final class Settings: ObservableObject {
@AppStorage(\.quitXPCServiceOnXcodeAndAppQuit)
var quitXPCServiceOnXcodeAndAppQuit: Bool
@AppStorage(\.realtimeSuggestionToggle)
var realtimeSuggestionToggle: Bool
@AppStorage(\.realtimeSuggestionDebounce)
var realtimeSuggestionDebounce: Double
@AppStorage(\.suggestionPresentationMode)
var suggestionPresentationMode: Preferences.PresentationMode
@AppStorage(\.suggestionWidgetPositionMode)
var suggestionWidgetPositionMode: SuggestionWidgetPositionMode
@AppStorage(\.widgetColorScheme)
var widgetColorScheme: WidgetColorScheme
init() {}
}
struct SettingsView: View {
@StateObject var settings = Settings()
@State var editingRealtimeSuggestionDebounce: Double = UserDefaults.shared
.value(for: \.realtimeSuggestionDebounce)
@Environment(\.updateChecker) var updateChecker
var body: some View {
Section {
Form {
Toggle(isOn: $settings.quitXPCServiceOnXcodeAndAppQuit) {
Text("Quit service when Xcode and host app are terminated")
}
.toggleStyle(.switch)
Toggle(isOn: .init(
get: { updateChecker.automaticallyChecksForUpdates },
set: { updateChecker.automaticallyChecksForUpdates = $0 }
)) {
Text("Automatically Check for Update")
}
.toggleStyle(.switch)
Picker(selection: $settings.suggestionPresentationMode) {
ForEach(PresentationMode.allCases, id: \.rawValue) {
switch $0 {
case .comment:
Text("Comment").tag($0)
case .floatingWidget:
Text("Floating Widget").tag($0)
}
}
} label: {
Text("Present suggestions in")
}
if settings.suggestionPresentationMode == PresentationMode.floatingWidget {
Picker(selection: $settings.suggestionWidgetPositionMode) {
ForEach(SuggestionWidgetPositionMode.allCases, id: \.rawValue) {
switch $0 {
case .fixedToBottom:
Text("Fixed to Bottom").tag($0)
case .alignToTextCursor:
Text("Follow Text Cursor").tag($0)
}
}
} label: {
Text("Widget position")
}
Picker(selection: $settings.widgetColorScheme) {
ForEach(WidgetColorScheme.allCases, id: \.rawValue) {
switch $0 {
case .system:
Text("System").tag($0)
case .light:
Text("Light").tag($0)
case .dark:
Text("Dark").tag($0)
}
}
} label: {
Text("Widget color scheme")
}
}
Toggle(isOn: $settings.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
settings.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)
}
}