-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebview.go
More file actions
102 lines (84 loc) · 1.87 KB
/
webview.go
File metadata and controls
102 lines (84 loc) · 1.87 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//go:build !darwin && !crossbuild
package main
import (
"fmt"
"log"
"sync"
webview "github.com/webview/webview_go"
)
var (
wv webview.WebView
wvMu sync.Mutex
wvDashboardURL string
)
// initWebview creates the native webview window.
// On Windows/Linux, uses webview_go library.
func initWebview(dashURL string) {
wvMu.Lock()
defer wvMu.Unlock()
wvDashboardURL = dashURL
w := webview.New(false)
if w == nil {
log.Printf("[webview] failed to create native window — browser fallback active")
return
}
cfg := getConfig()
title := "TSC Bridge"
if cfg.Whitelabel.Name != "" {
title = fmt.Sprintf("TSC Bridge — %s", cfg.Whitelabel.Name)
}
w.SetTitle(title)
w.SetSize(1100, 750, webview.HintNone)
w.Navigate(dashURL)
wv = w
log.Printf("[webview] native window created: %s", dashURL)
}
// showDashboard opens or refocuses the native webview window.
func showDashboard(dashURL string) {
wvMu.Lock()
w := wv
wvMu.Unlock()
if dashURL == "" {
dashURL = wvDashboardURL
}
if w == nil {
log.Printf("[webview] no native window — opening browser: %s", dashURL)
openBrowser(dashURL)
return
}
w.Dispatch(func() {
w.Navigate(dashURL)
})
}
// setWebviewTitle updates the window title with whitelabel branding.
func setWebviewTitle() {
wvMu.Lock()
w := wv
wvMu.Unlock()
cfg := getConfig()
title := "TSC Bridge"
if cfg.Whitelabel.Name != "" {
title = fmt.Sprintf("TSC Bridge — %s", cfg.Whitelabel.Name)
}
if w != nil {
w.Dispatch(func() {
w.SetTitle(title)
})
}
}
// isWebviewActive reports whether a native webview window exists.
func isWebviewActive() bool {
wvMu.Lock()
defer wvMu.Unlock()
return wv != nil
}
// destroyWebview tears down the native webview window.
func destroyWebview() {
wvMu.Lock()
defer wvMu.Unlock()
if wv != nil {
log.Printf("[webview] destroying native window")
wv.Destroy()
wv = nil
}
}