-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.go
98 lines (86 loc) · 1.83 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
98
package main
import (
"context"
"fmt"
"log/slog"
_ "net"
"os"
"time"
"gioui.org/app"
_ "gioui.org/app/permission/storage"
"gioui.org/op"
"github.com/go-gost/core/logger"
"github.com/go-gost/gost.plus/config"
"github.com/go-gost/gost.plus/runner"
"github.com/go-gost/gost.plus/runner/task"
"github.com/go-gost/gost.plus/tunnel"
"github.com/go-gost/gost.plus/tunnel/entrypoint"
"github.com/go-gost/gost.plus/ui"
"github.com/go-gost/gost.plus/ui/page"
"github.com/go-gost/gost.plus/ui/theme"
"github.com/go-gost/gost.plus/ui/widget"
_ "github.com/go-gost/gost.plus/winres"
)
func main() {
Init()
go func() {
if err := run(); err != nil {
logger.Default().Fatal(err)
}
os.Exit(0)
}()
app.Main()
}
func run() error {
ui := ui.NewUI()
go handleEvent(ui)
w := ui.Window()
var ops op.Ops
for {
switch e := w.Event().(type) {
case app.DestroyEvent:
tunnel.SaveConfig()
entrypoint.SaveConfig()
return e.Err
case app.FrameEvent:
gtx := app.NewContext(&ops, e)
ui.Layout(gtx)
e.Frame(gtx.Ops)
}
}
}
func handleEvent(ui *ui.UI) {
for {
select {
case e := <-ui.Router().Event():
switch e.ID {
case page.EventThemeChanged:
slog.Debug("theme changed", "event", e.ID)
ui.Window().Option(app.StatusColor(theme.Current().Material.Bg))
}
case e := <-runner.Event():
switch e.TaskID {
case runner.TaskUpdateStats:
ui.Window().Invalidate()
default:
if e.Err != nil {
slog.Error(fmt.Sprintf("task: %s", e.Err), "task", e.TaskID)
ui.Router().Notify(widget.Message{
Type: widget.Error,
Content: e.Err.Error(),
})
}
}
}
}
}
func Init() {
config.Init()
tunnel.LoadConfig()
entrypoint.LoadConfig()
runner.Exec(context.Background(), task.UpdateStats(),
runner.WithAync(true),
runner.WithInterval(time.Second),
runner.WithCancel(true),
)
}