-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
96 lines (76 loc) · 1.7 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
package main
import (
"context"
"net"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/driver/desktop"
"go.etcd.io/bbolt"
"tailscale.com/tsnet"
)
type router struct {
leaseBinding *MikrotikDataTable
ssh *remote
err error
host string
user string
password string
ssl bool
}
type appData struct {
routers map[string]*router
neighbors *MikrotikRouterList
app fyne.App
win fyne.Window
m *fyne.Menu
bindings []*MikrotikDataTable
current *router
identity binding.String
db *bbolt.DB
key *secretKey
currentView, currentTab string
ts *tsnet.Server
dial func(ctx context.Context, network, address string) (net.Conn, error)
cancel context.CancelFunc
useTailScale bool
}
var tcpDialer = net.Dialer{Timeout: 5 * time.Second}
func main() {
a := app.NewWithID("github.com.bluebugs.gotik")
a.Settings().SetTheme(&myTheme{})
myApp := &appData{
routers: map[string]*router{},
app: a,
win: a.NewWindow("Mikrotik Router"),
bindings: []*MikrotikDataTable{},
dial: tcpDialer.DialContext,
cancel: func() {},
neighbors: NewMikrotikRouterList(),
}
lastHost, _ := myApp.openDB()
myApp.createUI(lastHost)
defer myApp.Close()
if desk, ok := a.(desktop.App); ok {
myApp.m = fyne.NewMenu("Gotik", fyne.NewMenuItem("Show", func() {
myApp.win.Show()
}))
desk.SetSystemTrayMenu(myApp.m)
}
selfManage(a, myApp.win)
myApp.win.ShowAndRun()
}
func (a *appData) Close() {
for _, value := range a.bindings {
value.Close()
}
for _, value := range a.routers {
if value.leaseBinding != nil {
value.leaseBinding.Close()
}
}
if a.useTailScale {
a.tailScaleDisconnect()
}
}