forked from wailsapp/wails
/
systemtray.go
106 lines (92 loc) · 1.69 KB
/
systemtray.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
package application
type IconPosition int
const (
NSImageNone = iota
NSImageOnly
NSImageLeft
NSImageRight
NSImageBelow
NSImageAbove
NSImageOverlaps
NSImageLeading
NSImageTrailing
)
type systemTrayImpl interface {
setLabel(label string)
run()
setIcon(icon []byte)
setMenu(menu *Menu)
setIconPosition(position int)
setTemplateIcon(icon []byte)
destroy()
}
type SystemTray struct {
id uint
label string
icon []byte
iconPosition int
// Platform specific implementation
impl systemTrayImpl
menu *Menu
isTemplateIcon bool
}
func NewSystemTray(id uint) *SystemTray {
return &SystemTray{
id: id,
label: "",
iconPosition: NSImageLeading,
}
}
func (s *SystemTray) SetLabel(label string) {
if s.impl == nil {
s.label = label
return
}
s.impl.setLabel(label)
}
func (s *SystemTray) Label() string {
return s.label
}
func (s *SystemTray) Run() {
s.impl = newSystemTrayImpl(s)
s.impl.run()
}
func (s *SystemTray) SetIcon(icon []byte) *SystemTray {
if s.impl == nil {
s.icon = icon
} else {
s.impl.setIcon(icon)
}
return s
}
func (s *SystemTray) SetMenu(menu *Menu) *SystemTray {
if s.impl == nil {
s.menu = menu
} else {
s.impl.setMenu(menu)
}
return s
}
func (s *SystemTray) SetIconPosition(iconPosition int) *SystemTray {
if s.impl == nil {
s.iconPosition = iconPosition
} else {
s.impl.setIconPosition(iconPosition)
}
return s
}
func (s *SystemTray) SetTemplateIcon(icon []byte) *SystemTray {
if s.impl == nil {
s.icon = icon
s.isTemplateIcon = true
} else {
s.impl.setTemplateIcon(icon)
}
return s
}
func (s *SystemTray) Destroy() {
if s.impl == nil {
return
}
s.impl.destroy()
}