/
main.go
132 lines (113 loc) · 3.08 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"log"
"os"
"gioui.org/app"
_ "gioui.org/app/permission/storage"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/unit"
"gioui.org/widget/material"
"gioui.org/x/notify"
"github.com/julioguillermo/jg_sender/config"
"github.com/julioguillermo/jg_sender/connection"
"github.com/julioguillermo/jg_sender/font"
"github.com/julioguillermo/jg_sender/gui/dialog"
"github.com/julioguillermo/jg_sender/gui/screen"
"github.com/julioguillermo/jg_sender/notification"
)
func main() {
os.Setenv("LANG", "en_US.utf8")
go func() {
th := material.NewTheme(font.JGFonts())
conf := config.NewConfig(th)
w := app.NewWindow(
app.Title("JG Sender"),
app.Size(400, 600),
app.StatusColor(conf.AndroidBarColor),
)
err := run(th, w, conf)
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
app.Main()
}
func run(th *material.Theme, w *app.Window, conf *config.Config) error {
th.TextSize = unit.Sp(20)
server := connection.InitServer(conf)
notifications := map[string][]notify.Notification{}
history := screen.NewHistoryScreen(th, conf, w)
config_screen := screen.NewConfigScreen(conf)
subnet_screen := screen.NewSubnetworksScreen(th, conf)
scanner_screen := screen.NewScannerScreen(th, conf, subnet_screen, w)
scanner_screen.OnOpen = history.Open
scanner_screen.Notification = notifications
history.Notification = notifications
history.SendMSG = server.SendMSG
history.SendRes = server.SendResources
history.SendView = server.SendUserView
history.ContinueTrans = server.ContinueTrans
server.UpdateHistory = history.Update
notifier := notification.InitNotifier()
server.Notify = func(UserID, title, txt string) {
if history.Visibility() && history.UserID == UserID {
go server.SendUserView(UserID)
} else {
dev := connection.GetDevice(UserID)
if dev != nil {
dev.Not++
}
if notifier != nil {
n, err := notifier.CreateNotification(title, txt)
if err == nil {
if notifications[UserID] == nil {
notifications[UserID] = []notify.Notification{n}
} else {
notifications[UserID] = append(notifications[UserID], n)
}
}
}
}
w.Invalidate()
}
tabs := screen.NewTabScreen(conf)
tabs.Push("Subnetworks", config.ICSubNetworks, subnet_screen)
tabs.Push("Scanner", config.ICConnections, scanner_screen)
tabs.Push("Config", config.ICConfig, config_screen)
var ops op.Ops
var (
dlg dialog.Dialog
)
dlg.Conf = conf
conf.SetDialogOpener(dlg.SetWidget)
conf.SetDialogCloser(func() {
dlg.RemoveWidget()
})
for {
e := <-w.Events()
switch e := e.(type) {
case system.DestroyEvent:
return e.Err
case system.FrameEvent:
gtx := layout.NewContext(&ops, e)
layout.Stack{
Alignment: layout.Center,
}.Layout(
gtx,
layout.Expanded(func(gtx layout.Context) layout.Dimensions {
return tabs.Layout(th, gtx, w)
}),
layout.Expanded(func(gtx layout.Context) layout.Dimensions {
return history.Layout(th, gtx)
}),
layout.Expanded(func(gtx layout.Context) layout.Dimensions {
return dlg.Layout(th, gtx, w, conf)
}),
)
e.Frame(gtx.Ops)
}
}
}