51 Star 263 Fork 59

bitepeng / b0pass

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
main.go 1.52 KB
Copy Edit Web IDE Raw Blame History
bitepeng authored 2019-10-30 16:32 . add cli args port(-p=3000)
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()
}

Comment ( 0 )

Sign in for post a comment

Go
1
https://gitee.com/b0cloud/b0pass.git
git@gitee.com:b0cloud/b0pass.git
b0cloud
b0pass
b0pass
master

Search

103611 48b8ff67 1899542 103622 4d02230c 1899542