-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_windows.go
62 lines (56 loc) · 1.33 KB
/
main_windows.go
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
package main
import (
"embed"
"log"
"os"
"os/exec"
webview "github.com/jchv/go-webview2"
"i2pgit.org/idk/railroad/configuration"
)
// embed MicrosoftEdgeWebview2Setup.exe in the executable
//go:embed MicrosoftEdgeWebview2Setup.exe
var f embed.FS
func LaunchView() error {
if err := os.Setenv("NO_PROXY", "127.0.0.1:7672"); err != nil {
return err
}
debug := true
addr := addrString(configuration.Config().HttpHostAndPort)
webView := webview.NewWithOptions(webview.WebViewOptions{
Debug: debug,
AutoFocus: true,
WindowOptions: webview.WindowOptions{
Title: "Railroad Blog - Administration",
Width: 800,
Height: 600,
Center: true,
},
})
if webView == nil {
egbdir, err := f.ReadDir(".")
if err != nil {
return err
}
log.Println("egbdir", egbdir)
for _, e := range egbdir {
log.Println("found:", e.Name())
if e.Name() == "MicrosoftEdgeWebview2Setup.exe" {
cmd := exec.Command(e.Name())
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return err
}
}
}
log.Fatalln("Failed to load webview.")
}
defer webView.Destroy()
webView.SetTitle("Railroad Blog - Administration")
webView.SetSize(800, 600, webview.HintNone)
log.Println("http://" + addr + "/admin")
webView.Navigate("http://" + addr + "/admin")
webView.Run()
return nil
}