forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxySection.swift
More file actions
62 lines (56 loc) · 1.88 KB
/
ProxySection.swift
File metadata and controls
62 lines (56 loc) · 1.88 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
import Client
import SwiftUI
import Toast
struct ProxySection: View {
@AppStorage(\.gitHubCopilotProxyUrl) var gitHubCopilotProxyUrl
@AppStorage(\.gitHubCopilotProxyUsername) var gitHubCopilotProxyUsername
@AppStorage(\.gitHubCopilotProxyPassword) var gitHubCopilotProxyPassword
@AppStorage(\.gitHubCopilotUseStrictSSL) var gitHubCopilotUseStrictSSL
@Environment(\.toast) var toast
var body: some View {
SettingsSection(title: "Proxy") {
SettingsTextField(
title: "Proxy URL",
prompt: "http://host:port",
text: wrapBinding($gitHubCopilotProxyUrl)
)
SettingsTextField(
title: "Proxy username",
prompt: "username",
text: wrapBinding($gitHubCopilotProxyUsername)
)
SettingsSecureField(
title: "Proxy password",
prompt: "password",
text: wrapBinding($gitHubCopilotProxyPassword)
)
SettingsToggle(
title: "Proxy strict SSL",
isOn: wrapBinding($gitHubCopilotUseStrictSSL)
)
}
}
private func wrapBinding<T>(_ b: Binding<T>) -> Binding<T> {
DebouncedBinding(b, handler: refreshConfiguration).binding
}
func refreshConfiguration(_: Any) {
NotificationCenter.default.post(
name: .gitHubCopilotShouldRefreshEditorInformation,
object: nil
)
Task {
let service = try getService()
do {
try await service.postNotification(
name: Notification.Name
.gitHubCopilotShouldRefreshEditorInformation.rawValue
)
} catch {
toast(error.localizedDescription, .error)
}
}
}
}
#Preview {
ProxySection()
}