-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmain.go
More file actions
121 lines (96 loc) · 2.93 KB
/
Copy pathmain.go
File metadata and controls
121 lines (96 loc) · 2.93 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
119
120
121
package main
import (
"embed"
"ghost-chat/internal/config"
"os"
"path/filepath"
"runtime"
"github.com/wailsapp/wails/v3/pkg/application"
)
//go:embed all:frontend/dist
var assets embed.FS
//go:embed frontend/src/assets/trayicon.png
var trayIcon []byte
//go:embed build/appicon.png
var appIcon []byte
var version = "dev"
func main() {
configPath, err := config.GetConfigPath()
if err != nil {
println("Error getting config path:", err.Error())
return
}
cfg, err := config.Load(configPath)
if err != nil {
println("Error loading config:", err.Error())
return
}
normalizedVersion := config.NormalizeVersion(version)
if err := config.RunMigrations(cfg, normalizedVersion); err != nil {
println("Error running migrations:", err.Error())
}
cfg.Version = normalizedVersion
if err := config.Save(cfg, configPath); err != nil {
println("Error saving config:", err.Error())
}
svc := NewApp(cfg, configPath, version)
initialW, initialH := sanitizeWindowSize(cfg.WindowState.Width, cfg.WindowState.Height)
var webviewUserDataPath string
if runtime.GOOS == "windows" {
if localAppData := os.Getenv("LOCALAPPDATA"); localAppData != "" {
webviewUserDataPath = filepath.Join(localAppData, "ghost-chat", "webview")
}
}
app := application.New(application.Options{
Name: "Ghost Chat",
Icon: appIcon,
Windows: application.WindowsOptions{
WebviewUserDataPath: webviewUserDataPath,
},
ShouldQuit: func() bool {
svc.SaveWindowState()
return true
},
Mac: application.MacOptions{
ApplicationShouldTerminateAfterLastWindowClosed: true,
},
Assets: application.AssetOptions{
Handler: application.BundledAssetFileServer(assets),
},
Services: []application.Service{
application.NewService(svc),
},
})
win := app.Window.NewWithOptions(application.WebviewWindowOptions{
Title: "ghost-chat",
Width: initialW,
Height: initialH,
Hidden: true,
Frameless: true,
AlwaysOnTop: true,
BackgroundType: application.BackgroundTypeTransparent,
BackgroundColour: application.NewRGBA(0, 0, 0, 0),
Windows: application.WindowsWindow{
DisableFramelessWindowDecorations: true,
},
Mac: application.MacWindow{
Backdrop: application.MacBackdropTransparent,
},
})
svc.SetApp(app, win)
tray := app.SystemTray.New()
tray.SetTemplateIcon(trayIcon)
tray.SetTooltip("Ghost Chat " + version)
menu := app.NewMenu()
menu.Add("Ghost Chat " + version).SetEnabled(false)
menu.AddSeparator()
menu.Add("Center on Screen").OnClick(func(_ *application.Context) { svc.CenterOnScreen() })
menu.Add("Toggle Vanish").OnClick(func(_ *application.Context) { svc.ToggleVanish() })
menu.Add("Open Config Folder").OnClick(func(_ *application.Context) { svc.OpenConfigFolder() })
menu.AddSeparator()
menu.Add("Quit").OnClick(func(_ *application.Context) { win.Close() })
tray.SetMenu(menu)
if err := app.Run(); err != nil {
println("Error:", err.Error())
}
}