-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
118 lines (99 loc) · 2.26 KB
/
Copy pathmain.go
File metadata and controls
118 lines (99 loc) · 2.26 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"context"
_ "embed"
"io/fs"
"os"
"os/signal"
"path/filepath"
"syscall"
"fyne.io/systray"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
//go:embed build/windows/icon.ico
var trayIcon []byte
var assetsDir string
func resolveAssetsDir() string {
candidates := []string{}
if exePath, err := os.Executable(); err == nil {
candidates = append(candidates, filepath.Join(filepath.Dir(exePath), "frontend", "dist"))
}
if wd, err := os.Getwd(); err == nil {
candidates = append(candidates, filepath.Join(wd, "frontend", "dist"))
}
for _, dir := range candidates {
if stat, err := os.Stat(dir); err == nil && stat.IsDir() {
return dir
}
}
return ""
}
func main() {
app := NewApp()
assetsDir = resolveAssetsDir()
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
loop, _ := systray.RunWithExternalLoop(func() {
systray.SetIcon(trayIcon)
systray.SetTooltip("Vibe Time")
systray.SetOnTapped(func() {
app.ShowWindow()
})
mShow := systray.AddMenuItem("显示窗口", "")
systray.AddSeparator()
mQuit := systray.AddMenuItem("退出", "")
go func() {
for {
select {
case <-mShow.ClickedCh:
app.ShowWindow()
case <-mQuit.ClickedCh:
systray.Quit()
}
}
}()
}, func() {
os.Exit(0)
})
go loop()
go func() {
<-sigCh
os.Exit(0)
}()
var assetFS fs.FS
if assetsDir != "" {
assetFS = os.DirFS(assetsDir)
}
err := wails.Run(&options.App{
Title: "Vibe Time",
Width: 900,
Height: 680,
MinWidth: 600,
MinHeight: 500,
Frameless: true,
AssetServer: &assetserver.Options{
Assets: assetFS,
},
BackgroundColour: &options.RGBA{R: 10, G: 14, B: 23, A: 255},
OnStartup: app.startup,
OnBeforeClose: func(ctx context.Context) bool {
runtime.WindowHide(ctx)
return true
},
SingleInstanceLock: &options.SingleInstanceLock{
UniqueId: "vibe-time-a3f8c9d2-e7b1-4d6a-b5c3-9e8f2a1d0c7b",
OnSecondInstanceLaunch: func(secondInstanceData options.SecondInstanceData) {
app.ShowWindow()
},
},
Bind: []interface{}{
app,
},
})
if err != nil {
println("Error:", err.Error())
}
}