-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathEnterpriseSection.swift
More file actions
44 lines (39 loc) · 1.12 KB
/
EnterpriseSection.swift
File metadata and controls
44 lines (39 loc) · 1.12 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
import Combine
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: DebouncedBinding($gitHubCopilotEnterpriseURI, handler: urlChanged).binding
)
}
}
func urlChanged(_ url: String) {
if !url.isEmpty {
validateAuthURL(url)
}
NotificationCenter.default.post(
name: .gitHubCopilotShouldRefreshEditorInformation,
object: nil
)
}
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()
}