-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtray.go
More file actions
92 lines (79 loc) · 2.21 KB
/
tray.go
File metadata and controls
92 lines (79 loc) · 2.21 KB
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
package main
import (
"log"
"fyne.io/systray"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// TrayManager управляет иконкой в системном трее
type TrayManager struct {
app *App
iconData []byte
isVisible bool
}
// NewTrayManager создаёт менеджер трея
func NewTrayManager(app *App, iconData []byte) *TrayManager {
return &TrayManager{app: app, iconData: iconData, isVisible: true}
}
// Start запускает system tray в отдельной горутине
func (t *TrayManager) Start() {
go func() {
systray.Run(t.onReady, t.onExit)
}()
}
// onReady вызывается когда трей готов
func (t *TrayManager) onReady() {
systray.SetIcon(t.iconData)
systray.SetTitle("TeleGhost")
systray.SetTooltip("TeleGhost — Анонимный мессенджер I2P")
// Обрабоботка клика по иконке (ЛКМ)
// Используем SetOnTapped для fyne.io/systray v1.12.0+
systray.SetOnTapped(func() {
t.toggleWindow()
})
// Пункты меню (ПКМ)
mShow := systray.AddMenuItem("Показать/Скрыть", "Переключить видимость окна")
systray.AddSeparator()
mQuit := systray.AddMenuItem("Выход", "Закрыть приложение полностью")
// Обработка кликов меню
go func() {
for {
select {
case <-mShow.ClickedCh:
t.toggleWindow()
case <-mQuit.ClickedCh:
log.Println("[Tray] Quit requested")
systray.Quit()
if t.app != nil && t.app.ctx != nil {
runtime.Quit(t.app.ctx)
}
}
}
}()
}
// toggleWindow переключает видимость окна
func (t *TrayManager) toggleWindow() {
if t.app == nil || t.app.ctx == nil {
return
}
if t.isVisible {
runtime.WindowHide(t.app.ctx)
t.isVisible = false
if t.app.core != nil {
t.app.core.IsVisible = false
}
} else {
runtime.WindowShow(t.app.ctx)
t.isVisible = true
if t.app.core != nil {
t.app.core.IsVisible = true
}
}
}
// Stop останавливает трей
func (t *TrayManager) Stop() {
systray.Quit()
}
// onExit вызывается при выходе
func (t *TrayManager) onExit() {
log.Println("[Tray] Exiting...")
}