-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathEnterpriseSection.swift
More file actions
57 lines (52 loc) · 1.52 KB
/
EnterpriseSection.swift
File metadata and controls
57 lines (52 loc) · 1.52 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
import Combine
import Client
import SwiftUI
import Toast
struct EnterpriseSection: View {
@AppStorage(\.gitHubCopilotEnterpriseURI) var gitHubCopilotEnterpriseURI
@Environment(\.toast) var toast
var body: some View {
SettingsSection(title: "Enterprise") {
SettingsTextField(
title: "Auth provider URL",
prompt: "https://your-enterprise.ghe.com",
text: $gitHubCopilotEnterpriseURI,
onDebouncedChange: { url in urlChanged(url)}
)
}
}
func urlChanged(_ url: String) {
if !url.isEmpty {
validateAuthURL(url)
}
NotificationCenter.default.post(
name: .gitHubCopilotShouldRefreshEditorInformation,
object: nil
)
Task {
do {
let service = try getService()
try await service.postNotification(
name: Notification.Name
.gitHubCopilotShouldRefreshEditorInformation.rawValue
)
} catch {
toast(error.localizedDescription, .error)
}
}
}
func validateAuthURL(_ url: String) {
let maybeURL = URL(string: url)
guard let parsedURL = maybeURL else {
toast("Invalid URL", .error)
return
}
if parsedURL.scheme != "https" {
toast("URL scheme must be https://", .error)
return
}
}
}
#Preview {
EnterpriseSection()
}