-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindows.go
116 lines (99 loc) · 2.26 KB
/
mainwindows.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
package main
import (
"github.com/astaxie/beego/logs"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"os"
"time"
)
var mainWindowWidth = 500
var mainWindowHeight = 400
type MainWindowCtrl struct {
instance *MainWindow
ctrl *walk.MainWindow
exitInt int
exit chan struct{}
}
var mainWindowCtrl *MainWindowCtrl
func init() {
mainWindowCtrl = new(MainWindowCtrl)
mainWindowCtrl.exit = make(chan struct{}, 10)
}
func MainWindowsVisible(flag bool) {
if mainWindowCtrl.ctrl != nil {
mainWindowCtrl.ctrl.SetVisible(flag)
}
}
func MainWindowsClose() {
logs.Info("main windows ready to close")
mainWindowCtrl.exitInt = 0
mainWindowCtrl.exit <- struct{}{}
}
func AppExitPreFunc() {
if mainWindowCtrl.ctrl != nil {
mainWindowCtrl.ctrl.Close()
mainWindowCtrl.ctrl = nil
}
NotifyExit()
if err:= recover();err != nil{
logs.Error(err)
}
}
func MainWindowsCtrl() *walk.MainWindow {
return mainWindowCtrl.ctrl
}
func MainWindowsExit() {
CapSignal(AppExitPreFunc)
<- mainWindowCtrl.exit
AppExitPreFunc()
os.Exit(mainWindowCtrl.exitInt)
}
func MainWindowStart() error {
logs.Info("main windows start")
mainWindowCtrl.instance = mainWindowBuilder(&mainWindowCtrl.ctrl)
go func() {
cnt, err := mainWindowCtrl.instance.Run()
if err != nil {
logs.Error(err.Error())
}
mainWindowCtrl.exitInt = cnt
mainWindowCtrl.exit <- struct{}{}
logs.Info("main windows close")
}()
for {
if mainWindowCtrl.ctrl != nil && mainWindowCtrl.ctrl.Visible() {
break
}
time.Sleep(200*time.Millisecond)
}
NotifyInit(mainWindowCtrl.ctrl)
logs.Info("main windows start success")
return nil
}
func mainWindowBuilder(mw **walk.MainWindow) *MainWindow {
return &MainWindow{
Title: "Tcp Proxy " + VersionGet(),
Icon: ICON_Main,
AssignTo: mw,
MinSize: Size{mainWindowWidth, mainWindowHeight},
Size: Size{mainWindowWidth, mainWindowHeight},
Layout: VBox{
Alignment: AlignHNearVNear,
MarginsZero: true,
Margins: Margins{Left: 10, Top: 10},
},
MenuItems: MenuBarInit(),
Children: []Widget{
Composite{
Layout: HBox{ MarginsZero: true},
Children: []Widget{
ToolBarInit(),
},
},
Composite{
Layout: VBox{MarginsZero: true, Margins: Margins{Right: 10, Bottom: 10}},
Children: TableWight(),
},
},
}
}