-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
74 lines (62 loc) · 1.47 KB
/
app.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
package main
import (
"context"
"fyne.io/systray"
"github.com/wailsapp/wails/v2/pkg/runtime"
"os"
"refi/icon"
)
type App struct {
ctx context.Context
SysTrayEnd func()
}
func NewApp() *App {
return &App{}
}
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
// TODO: using 3rd party systray library https://github.com/fyne-io/systray / https://pkg.go.dev/fyne.io/systray
// wails v3 will have built-in systray support
sysTrayStart, sysTrayEnd := systray.RunWithExternalLoop(a.sysTrayOnReady, a.sysTrayOnExit)
a.SysTrayEnd = sysTrayEnd
sysTrayStart()
}
func (a *App) GetUserDataDir() string {
dataDir := os.Getenv("XDG_DATA_HOME")
if dataDir == "" {
dataDir = os.ExpandEnv("$HOME/.local/share")
}
return dataDir
}
func (a *App) GetUserConfigDir() string {
configDir, err := os.UserConfigDir()
if err != nil {
configDir = os.ExpandEnv("$HOME/.config")
}
return configDir
}
func (a *App) GetAppName() string {
return "refi"
}
func (a *App) sysTrayOnReady() {
systray.SetIcon(icon.Data)
systray.SetTitle("Refi - offline documentation viewer")
systray.SetTooltip("Refi - offline documentation viewer")
mOpenApp := systray.AddMenuItem("Open", "Open Refi")
systray.AddSeparator()
mQuit := systray.AddMenuItem("Quit", "Quit Refi")
go func() {
for {
select {
case <-mOpenApp.ClickedCh:
runtime.WindowShow(a.ctx)
case <-mQuit.ClickedCh:
systray.Quit()
a.SysTrayEnd()
}
}
}()
}
func (a *App) sysTrayOnExit() {
runtime.Quit(a.ctx)
}