-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
192 lines (166 loc) · 5.19 KB
/
Copy pathmain.go
File metadata and controls
192 lines (166 loc) · 5.19 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package main
import (
"context"
"embed"
goruntime "runtime"
"prochub/internal/platform"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/menu/keys"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/linux"
"github.com/wailsapp/wails/v2/pkg/options/mac"
"github.com/wailsapp/wails/v2/pkg/options/windows"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
//go:embed all:frontend/dist
var assets embed.FS
//go:embed build/appicon.png
var icon []byte
//go:embed build/trayicon.png
var trayIcon []byte
//go:embed build/trayicon_windows.ico
var trayIconWindows []byte
// Global app reference for tray menu callbacks
var globalApp *App
var trayManager *platform.TrayManager
// UpdateTrayLanguage updates the system tray menu language
func UpdateTrayLanguage() {
if trayManager != nil {
trayManager.UpdateLanguage()
}
}
// createApplicationMenu creates the application menu with Edit menu
// Returns nil on Windows to hide the menu bar
func createApplicationMenu() *menu.Menu {
// On Windows, return nil to hide menu bar
// Keyboard shortcuts (Ctrl+C/V/X/A/Z) work natively via WebviewGpuIsDisabled=false
if goruntime.GOOS == "windows" {
return nil
}
appMenu := menu.NewMenu()
if goruntime.GOOS == "darwin" {
// App menu (macOS only)
appMenu.Append(menu.AppMenu())
// Edit menu with standard shortcuts using roles (macOS)
appMenu.Append(menu.EditMenu())
} else {
// Edit menu with standard shortcuts (Linux)
editMenu := appMenu.AddSubmenu("Edit")
editMenu.AddText("Undo", keys.CmdOrCtrl("z"), func(_ *menu.CallbackData) {})
editMenu.AddText("Redo", keys.CmdOrCtrl("shift+z"), func(_ *menu.CallbackData) {})
editMenu.AddSeparator()
editMenu.AddText("Cut", keys.CmdOrCtrl("x"), func(_ *menu.CallbackData) {})
editMenu.AddText("Copy", keys.CmdOrCtrl("c"), func(_ *menu.CallbackData) {})
editMenu.AddText("Paste", keys.CmdOrCtrl("v"), func(_ *menu.CallbackData) {})
editMenu.AddText("Select All", keys.CmdOrCtrl("a"), func(_ *menu.CallbackData) {})
}
return appMenu
}
// wrapStartup wraps the app startup to initialize the tray after Wails context is ready
func wrapStartup(app *App) func(ctx context.Context) {
return func(ctx context.Context) {
// Call original startup
app.startup(ctx)
// Ensure window is shown on startup
runtime.WindowShow(ctx)
// Initialize and start system tray after Wails is ready
trayManager = platform.NewTrayManager(app, trayIcon, trayIconWindows)
go trayManager.Run()
}
}
// wrapShutdown wraps the app shutdown to cleanup the tray
func wrapShutdown(app *App) func(ctx context.Context) {
return func(ctx context.Context) {
// Stop systray
if trayManager != nil {
trayManager.Quit()
}
// Call original shutdown
app.shutdown(ctx)
}
}
func main() {
// Create an instance of the app structure
app := NewApp()
globalApp = app
// Create application with options
err := wails.Run(&options.App{
Title: "ProcHub",
Width: 1024,
Height: 720,
MinWidth: 900,
MinHeight: 640,
Frameless: false,
DisableResize: false,
AssetServer: &assetserver.Options{
Assets: assets,
},
BackgroundColour: &options.RGBA{R: 248, G: 250, B: 252, A: 1},
EnableDefaultContextMenu: false,
Menu: createApplicationMenu(),
CSSDragValue: "drag",
CSSDragProperty: "--wails-draggable",
// Custom close behavior: hide window and Dock icon instead of quitting
OnBeforeClose: func(ctx context.Context) (prevent bool) {
// Hide the window
runtime.WindowHide(ctx)
// Hide Dock icon on macOS
platform.HideDockIcon()
// Prevent the default close behavior (quitting the app)
return true
},
OnStartup: wrapStartup(app),
OnShutdown: wrapShutdown(app),
Bind: []interface{}{
app,
},
// macOS specific options
Mac: &mac.Options{
TitleBar: &mac.TitleBar{
TitlebarAppearsTransparent: false,
HideTitle: false,
HideTitleBar: false,
FullSizeContent: false,
UseToolbar: false,
HideToolbarSeparator: true,
},
About: &mac.AboutInfo{
Title: "ProcHub",
Message: "Process Manager",
Icon: icon,
},
},
// Windows specific options
Windows: &windows.Options{
WebviewIsTransparent: false,
WindowIsTranslucent: false,
DisableWindowIcon: false,
},
// Linux specific options
Linux: &linux.Options{
Icon: icon,
WindowIsTranslucent: false,
},
// Single instance lock - show window when second instance is launched
SingleInstanceLock: &options.SingleInstanceLock{
UniqueId: "prochub-app-unique-id",
OnSecondInstanceLaunch: func(secondInstanceData options.SecondInstanceData) {
if globalApp != nil && globalApp.ctx != nil {
// Show Dock icon first (macOS)
platform.ShowDockIcon()
// Show the window
runtime.WindowShow(globalApp.ctx)
if goruntime.GOOS == "darwin" {
runtime.WindowSetAlwaysOnTop(globalApp.ctx, true)
runtime.WindowSetAlwaysOnTop(globalApp.ctx, false)
}
}
},
},
})
if err != nil {
println("Error:", err.Error())
}
}