Fix window close: use RegisterHook to hide instead of destroy
RegisterHook + e.Cancel() prevents Wails from destroying the WebView when the window is closed. The app now hides to the system tray. Left- click on the tray icon correctly restores the window.
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v3/pkg/application"
|
"github.com/wailsapp/wails/v3/pkg/application"
|
||||||
|
"github.com/wailsapp/wails/v3/pkg/events"
|
||||||
"github.com/zalando/go-keyring"
|
"github.com/zalando/go-keyring"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -760,6 +761,12 @@ func main() {
|
|||||||
} else {
|
} else {
|
||||||
window.Center()
|
window.Center()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
|
||||||
|
window.Hide()
|
||||||
|
e.Cancel()
|
||||||
|
})
|
||||||
|
|
||||||
window.Show()
|
window.Show()
|
||||||
|
|
||||||
systemTray.AttachWindow(window)
|
systemTray.AttachWindow(window)
|
||||||
|
|||||||
Reference in New Issue
Block a user