-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgo4rdm.go
87 lines (79 loc) · 1.55 KB
/
go4rdm.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
87
package main
import (
"errors"
"fmt"
"fyne.io/fyne/dialog"
"github.com/gen2brain/dlgs"
"github.com/gohouse/go4rdm/config"
"github.com/gohouse/go4rdm/data"
"github.com/gohouse/go4rdm/ui"
"log"
"os/exec"
"runtime"
)
var (
VERSION int64 = 1
)
func main() {
NewGo4rdm().Run()
}
type Go4rdm struct {
conf *config.Config
rds *data.Redis
}
func NewGo4rdm() *Go4rdm {
conf := config.NewConfig()
return &Go4rdm{conf: conf, rds: data.NewRedis(conf)}
}
func (g *Go4rdm) Run() {
defer func() {
if err := recover(); err != nil {
log.Println("[[panic recover]]: ", err)
}
}()
// 统计一下
go data.NewApi().Statistic()
// 检查版本
if g.checkVersion() {
return
}
u := ui.NewUI(g.conf, g.rds)
defer func() {
if err := recover(); err != nil {
dialog.ShowError(errors.New(fmt.Sprint(err)), u.Window)
}
}()
u.Build()
}
func (g *Go4rdm) checkVersion() bool {
v := data.NewApi().GetVersion()
if v.Num > VERSION {
info, _ := dlgs.Question("update to new version "+v.NumText, v.Notes, false)
if info {
err := OpenUrl(v.Url)
if err != nil {
err2 := OpenUrl(v.Url)
if err2 != nil {
dlgs.Info("error", fmt.Sprintf("auto open error, please visit %s for download the new version", v.Url))
}
}
return true
}
}
return false
}
func OpenUrl(url string) error {
var cmd string
var args []string
switch runtime.GOOS {
case "darwin":
cmd = "open"
case "windows":
cmd = "cmd"
args = append(args, `/c`, `start`)
default:
cmd = "xdg-open"
}
args = append(args, url)
return exec.Command(cmd, args...).Start()
}