forked from bitepeng/b0pass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
86 lines (76 loc) · 1.52 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"b0pass/boot"
_ "b0pass/boot"
"b0pass/library/openurl"
_ "b0pass/router"
"fmt"
"github.com/gogf/gf/frame/g"
"github.com/zserge/lorca"
"log"
"os"
"os/signal"
"runtime"
"strconv"
"time"
)
func main() {
//处理命令行参数
boot.ExecArgs()
fmt.Printf("[ServerUrl] http://127.0.0.1:%d\n",boot.ServPort)
fmt.Printf("[Work-Path] %s\n",boot.PathRoot)
//是否开启GUI模式
//判断是否安装谷歌浏览器
ChromeExe := lorca.ChromeExecutable()
if ChromeExe != "" {
//打开UI界面
execUI()
} else {
//打开浏览器
go func() {
time.Sleep(1000 * time.Millisecond)
_ = openurl.Open("http://127.0.0.1:" + strconv.Itoa(boot.ServPort))
}()
g.Wait()
}
}
func execUI() {
// Wait Server Run
time.Sleep(3 * time.Second)
// Cli Args
var args []string
if runtime.GOOS == "linux" {
args = append(args, "--class=Lorca")
}
if runtime.GOOS == "windows" {
args = append(args, "-ldflags '-H windowsgui'")
}
// New Lorca UI
ui, err := lorca.New(
`data:text/html,
<html><head><title>B0App</title></head></html>`,
"", 360, 640, args...,
)
if err != nil {
log.Fatal(err)
}
defer func() {
_ = ui.Close()
}()
// Load url
_ = ui.Load(fmt.Sprintf(
"http://%s",
"127.0.0.1:"+g.Config().GetString("setting.port")),
)
// Wait until the interrupt signal arrives
// or browser window is closed
sigc := make(chan os.Signal)
signal.Notify(sigc, os.Interrupt)
select {
case <-sigc:
case <-ui.Done():
}
// Close UI
log.Println("exiting...")
_ = g.Server().Shutdown()
}