-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (58 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
package main
import (
log "github.com/sirupsen/logrus"
"github.com/lnenad/probster/storage"
"github.com/lnenad/probster/window"
"os"
evbus "github.com/asaskevich/EventBus"
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
gv "github.com/hashicorp/go-version"
"github.com/xujiajun/nutsdb"
)
const appID = "com.mockadillo.probster"
const dataFile = "data/db"
const logFile = "data/log"
const versionString = "0.4.1"
func main() {
parseArgs()
currentVersion, err := gv.NewVersion(versionString)
if err != nil {
log.Fatal("Error setting version: ", err)
}
application, err := gtk.ApplicationNew(appID, glib.APPLICATION_FLAGS_NONE)
if err != nil {
log.Fatal("Could not create application:", err)
}
opt := nutsdb.DefaultOptions
opt.Dir = dataFile
db, err := nutsdb.Open(opt)
if err != nil {
log.Fatal(err)
}
defer db.Close()
h := storage.SetupHistory(db)
st := storage.SetupSettings(db)
settings := st.GetAll()
bus := evbus.New()
application.Connect("activate", func() {
window.BuildWindow(currentVersion, &settings, application, &h, &st, bus)
aQuit := glib.SimpleActionNew("quit", nil)
aQuit.Connect("activate", func() {
application.Quit()
})
application.AddAction(aQuit)
})
os.Exit(application.Run(os.Args))
}
func parseArgs() {
if len(os.Args) >= 2 && os.Args[1] == "debug" {
f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()
log.SetOutput(f)
os.Args = os.Args[:1]
}
}