forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpPage.swift
More file actions
47 lines (41 loc) · 1.42 KB
/
Copy pathHelpPage.swift
File metadata and controls
47 lines (41 loc) · 1.42 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
import SwiftUI
import WebKit
struct HelpPage: View {
var body: some View {
CrispWebView()
.ignoresSafeArea()
.onAppear {
CrispManager.shared.isViewingHelp = true
}
.onDisappear {
CrispManager.shared.isViewingHelp = false
}
}
}
/// Visible Crisp chat webview — separate from CrispManager's background monitoring webview.
struct CrispWebView: NSViewRepresentable {
private let websiteID = "0dcf3d1f-863d-4576-a534-31f2bb102ae5"
func makeNSView(context: Context) -> WKWebView {
let config = WKWebViewConfiguration()
config.defaultWebpagePreferences.allowsContentJavaScript = true
let webView = WKWebView(frame: .zero, configuration: config)
webView.setValue(false, forKey: "drawsBackground")
var urlString = "https://go.crisp.chat/chat/embed/?website_id=\(websiteID)"
if let email = AuthState.shared.userEmail,
let encodedEmail = email.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
{
urlString += "&user_email=\(encodedEmail)"
}
let name = AuthService.shared.displayName
if !name.isEmpty,
let encodedName = name.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
{
urlString += "&user_nickname=\(encodedName)"
}
if let url = URL(string: urlString) {
webView.load(URLRequest(url: url))
}
return webView
}
func updateNSView(_ nsView: WKWebView, context: Context) {}
}