-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
97 lines (81 loc) · 1.81 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
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"PGCombatTracker/abstract"
"PGCombatTracker/collectors"
"PGCombatTracker/ui"
"PGCombatTracker/utils"
"gioui.org/app"
"gioui.org/layout"
"gioui.org/op"
"golang.design/x/clipboard"
"log"
"os"
"time"
)
func main() {
err := clipboard.Init()
if err != nil {
panic(err)
}
go func() {
window := new(app.Window)
window.Option(
app.Title("PGCombatTracker"),
)
err := run(window)
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
app.Main()
}
func run(window *app.Window) error {
state, err := ui.NewGlobalState(
window,
func(state abstract.GlobalState, path string, watch bool, timeFrames []abstract.MarkerTimeFrame) (abstract.StatisticsCollector, error) {
return collectors.NewStatisticsCollector(state, path, watch, timeFrames)
},
)
state.Settings().Theme.Theme().Apply(state.Theme())
if err != nil {
return err
}
state.SwitchPage(ui.NewFileSelectionPage())
go func() {
for {
stats := state.StatisticsCollector()
if stats != nil && stats.IsAlive() {
<-stats.Notify()
window.Invalidate()
continue
}
time.Sleep(100 * time.Millisecond)
}
}()
var ops op.Ops
for {
switch e := window.Event().(type) {
case app.DestroyEvent:
return e.Err
case app.FrameEvent:
// This graphics context is used for managing the rendering state.
gtx := app.NewContext(&ops, e)
layout.Background{}.Layout(
gtx,
utils.MakeColoredAndOptionalDragBG(state.Theme().Bg, state.CanBeDragged()),
func(gtx layout.Context) layout.Dimensions {
if state.Page != nil {
err := state.Page().Layout(gtx, state)
if err != nil {
log.Printf("Error updating UI: %v\n", err)
}
}
return layout.Dimensions{Size: gtx.Constraints.Min}
},
)
// Pass the drawing operations to the GPU.
e.Frame(gtx.Ops)
}
}
}