|
| 1 | +import Client |
| 2 | +import SwiftUI |
| 3 | +import Toast |
| 4 | + |
| 5 | +struct ProxySection: View { |
| 6 | + @AppStorage(\.gitHubCopilotProxyUrl) var gitHubCopilotProxyUrl |
| 7 | + @AppStorage(\.gitHubCopilotProxyUsername) var gitHubCopilotProxyUsername |
| 8 | + @AppStorage(\.gitHubCopilotProxyPassword) var gitHubCopilotProxyPassword |
| 9 | + @AppStorage(\.gitHubCopilotUseStrictSSL) var gitHubCopilotUseStrictSSL |
| 10 | + |
| 11 | + @Environment(\.toast) var toast |
| 12 | + |
| 13 | + var body: some View { |
| 14 | + SettingsSection(title: "Proxy") { |
| 15 | + SettingsTextField( |
| 16 | + title: "Proxy URL", |
| 17 | + prompt: "http://host:port", |
| 18 | + text: $gitHubCopilotProxyUrl |
| 19 | + ) |
| 20 | + SettingsTextField( |
| 21 | + title: "Proxy username", |
| 22 | + prompt: "username", |
| 23 | + text: $gitHubCopilotProxyUsername |
| 24 | + ) |
| 25 | + SettingsSecureField( |
| 26 | + title: "Proxy password", |
| 27 | + prompt: "password", |
| 28 | + text: $gitHubCopilotProxyPassword |
| 29 | + ) |
| 30 | + SettingsToggle( |
| 31 | + title: "Proxy strict SSL", |
| 32 | + isOn: $gitHubCopilotUseStrictSSL |
| 33 | + ) |
| 34 | + } footer: { |
| 35 | + HStack { |
| 36 | + Spacer() |
| 37 | + Button("Refresh configurations") { |
| 38 | + refreshConfiguration() |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + func refreshConfiguration() { |
| 45 | + NotificationCenter.default.post( |
| 46 | + name: .gitHubCopilotShouldRefreshEditorInformation, |
| 47 | + object: nil |
| 48 | + ) |
| 49 | + Task { |
| 50 | + let service = try getService() |
| 51 | + do { |
| 52 | + try await service.postNotification( |
| 53 | + name: Notification.Name |
| 54 | + .gitHubCopilotShouldRefreshEditorInformation.rawValue |
| 55 | + ) |
| 56 | + } catch { |
| 57 | + toast(error.localizedDescription, .error) |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +#Preview { |
| 64 | + ProxySection() |
| 65 | +} |
0 commit comments