mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Update systray-custom to show keep-alive after window kill
This commit is contained in:
parent
65f95b0380
commit
a90764891f
11 changed files with 46 additions and 43 deletions
|
|
@ -40,8 +40,11 @@ func main() {
|
|||
},
|
||||
})
|
||||
|
||||
// Register a hook to hide the window when the window is closing
|
||||
window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
|
||||
// Hide the window
|
||||
window.Hide()
|
||||
// Cancel the event so it doesn't get destroyed
|
||||
e.Cancel()
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -10,55 +10,55 @@ import (
|
|||
"github.com/wailsapp/wails/v3/pkg/icons"
|
||||
)
|
||||
|
||||
func createWindow(app *application.App) *application.WebviewWindow {
|
||||
window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
||||
Width: 500,
|
||||
Height: 500,
|
||||
Name: "Systray Demo Window",
|
||||
AlwaysOnTop: true,
|
||||
Hidden: true,
|
||||
BackgroundColour: application.NewRGB(33, 37, 41),
|
||||
DisableResize: true,
|
||||
Windows: application.WindowsWindow{
|
||||
HiddenOnTaskbar: true,
|
||||
},
|
||||
})
|
||||
|
||||
window.OnWindowEvent(events.Common.WindowClosing, func(e *application.WindowEvent) {
|
||||
println("Window Closing")
|
||||
})
|
||||
|
||||
return window
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := application.New(application.Options{
|
||||
Name: "Systray Demo",
|
||||
Description: "A demo of the Systray API",
|
||||
Assets: application.AlphaAssets,
|
||||
Windows: application.WindowsOptions{
|
||||
DisableQuitOnLastWindowClosed: true,
|
||||
},
|
||||
Mac: application.MacOptions{
|
||||
ActivationPolicy: application.ActivationPolicyAccessory,
|
||||
},
|
||||
})
|
||||
|
||||
systemTray := app.NewSystemTray()
|
||||
|
||||
window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
||||
Width: 500,
|
||||
Height: 500,
|
||||
Name: "Systray Demo Window",
|
||||
Frameless: true,
|
||||
AlwaysOnTop: true,
|
||||
Hidden: true,
|
||||
DisableResize: true,
|
||||
Windows: application.WindowsWindow{
|
||||
HiddenOnTaskbar: true,
|
||||
},
|
||||
})
|
||||
|
||||
window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
|
||||
window.Hide()
|
||||
e.Cancel()
|
||||
window := createWindow(app)
|
||||
menu := app.NewMenu()
|
||||
menu.Add("Quit").OnClick(func(data *application.Context) {
|
||||
app.Quit()
|
||||
})
|
||||
systemTray.SetMenu(menu)
|
||||
|
||||
if runtime.GOOS == "darwin" {
|
||||
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
|
||||
}
|
||||
|
||||
systemTray.OnClick(func() {
|
||||
println("System tray clicked!")
|
||||
if window.IsVisible() {
|
||||
window.Hide()
|
||||
} else {
|
||||
window.Show()
|
||||
}
|
||||
})
|
||||
|
||||
systemTray.OnDoubleClick(func() {
|
||||
println("System tray double clicked!")
|
||||
})
|
||||
|
||||
systemTray.OnRightClick(func() {
|
||||
println("System tray right clicked!")
|
||||
println("Creating New Window!")
|
||||
createWindow(app).Show()
|
||||
})
|
||||
|
||||
systemTray.AttachWindow(window).WindowOffset(5)
|
||||
|
|
|
|||
|
|
@ -781,13 +781,13 @@ func (a *App) cleanup() {
|
|||
InvokeSync(func() {
|
||||
a.windowsLock.RLock()
|
||||
for _, window := range a.windows {
|
||||
window.Destroy()
|
||||
window.Close()
|
||||
}
|
||||
a.windows = nil
|
||||
a.windowsLock.RUnlock()
|
||||
a.systemTraysLock.Lock()
|
||||
for _, systray := range a.systemTrays {
|
||||
systray.Destroy()
|
||||
systray.destroy()
|
||||
}
|
||||
a.systemTrays = nil
|
||||
a.systemTraysLock.Unlock()
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ static void run(void) {
|
|||
}
|
||||
}
|
||||
|
||||
// Destroy application
|
||||
// destroyApp destroys the application
|
||||
static void destroyApp(void) {
|
||||
[NSApp terminate:nil];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ func (m *windowsApp) destroy() {
|
|||
return
|
||||
}
|
||||
globalApplication.cleanup()
|
||||
// Destroy the main thread window
|
||||
// destroy the main thread window
|
||||
w32.DestroyWindow(m.mainThreadWindowHWND)
|
||||
// Post a quit message to the main thread
|
||||
w32.PostQuitMessage(0)
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ func (s *SystemTray) SetTemplateIcon(icon []byte) *SystemTray {
|
|||
return s
|
||||
}
|
||||
|
||||
func (s *SystemTray) Destroy() {
|
||||
func (s *SystemTray) destroy() {
|
||||
if s.impl == nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -388,7 +388,7 @@ func (s *windowsSystemTray) destroy() {
|
|||
s.menu.Destroy()
|
||||
}
|
||||
w32.DestroyWindow(s.hwnd)
|
||||
// Destroy the notification icon
|
||||
// destroy the notification icon
|
||||
nid := s.newNotifyIconData()
|
||||
if !w32.ShellNotifyIcon(w32.NIM_DELETE, &nid) {
|
||||
globalApplication.debug(syscall.GetLastError().Error())
|
||||
|
|
|
|||
|
|
@ -900,7 +900,7 @@ func (w *WebviewWindow) SetRelativePosition(x, y int) Window {
|
|||
return w
|
||||
}
|
||||
|
||||
func (w *WebviewWindow) Destroy() {
|
||||
func (w *WebviewWindow) destroy() {
|
||||
if w.impl == nil && !w.isDestroyed() {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -523,7 +523,7 @@ func (w *windowsWebviewWindow) destroy() {
|
|||
if w.dropTarget != nil {
|
||||
w.dropTarget.Release()
|
||||
}
|
||||
// Destroy the window
|
||||
// destroy the window
|
||||
w32.DestroyWindow(w.hwnd)
|
||||
}
|
||||
|
||||
|
|
@ -1647,6 +1647,7 @@ func (w *windowsWebviewWindow) setupChromium() {
|
|||
|
||||
// Set background colour
|
||||
w.setBackgroundColour(w.parent.options.BackgroundColour)
|
||||
chromium.SetBackgroundColour(w.parent.options.BackgroundColour.Red, w.parent.options.BackgroundColour.Green, w.parent.options.BackgroundColour.Blue, w.parent.options.BackgroundColour.Alpha)
|
||||
|
||||
chromium.SetGlobalPermission(edge.CoreWebView2PermissionStateAllow)
|
||||
chromium.AddWebResourceRequestedFilter("*", edge.COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ type Window interface {
|
|||
Callback
|
||||
Center()
|
||||
Close()
|
||||
Destroy()
|
||||
DisableSizeConstraints()
|
||||
DispatchWailsEvent(event *CustomEvent)
|
||||
EmitEvent(name string, data ...any)
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ package w32
|
|||
type Menu HMENU
|
||||
type PopupMenu Menu
|
||||
|
||||
func (m Menu) Destroy() bool {
|
||||
func (m Menu) destroy() bool {
|
||||
ret, _, _ := procDestroyMenu.Call(uintptr(m))
|
||||
return ret != 0
|
||||
}
|
||||
|
||||
func (p PopupMenu) Destroy() bool {
|
||||
return Menu(p).Destroy()
|
||||
func (p PopupMenu) destroy() bool {
|
||||
return Menu(p).destroy()
|
||||
}
|
||||
|
||||
func (p PopupMenu) Track(hwnd HWND, flags uint32, x, y int32) bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue