From 3cd26a22205a572ab8201baa0fdb56c8f3a98e91 Mon Sep 17 00:00:00 2001 From: ALMAS Date: Wed, 10 Jan 2024 20:28:15 +0800 Subject: [PATCH] [v3] Improve OnShutdown (#3190) * [v3] Improve OnShutdown * add change log --- mkdocs-website/docs/en/changelog.md | 1 + v3/pkg/application/application.go | 8 ++------ v3/pkg/application/options_application.go | 5 +++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mkdocs-website/docs/en/changelog.md b/mkdocs-website/docs/en/changelog.md index 1d9b4fc76..8aea8c2bb 100644 --- a/mkdocs-website/docs/en/changelog.md +++ b/mkdocs-website/docs/en/changelog.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [linux] add onKeyPress logic to convert linux keypress into an accelerator @[Atterpac](https://github.com/Atterpac) in[#3022](https://github.com/wailsapp/wails/pull/3022]) - [linux] add task `run:linux` by [@marcus-crane](https://github.com/marcus-crane) in [#3146](https://github.com/wailsapp/wails/pull/3146) - export `SetIcon` method by @almas1992 in [PR](https://github.com/wailsapp/wails/pull/3147) +- Improve `OnShutdown` by @almas1992 in [PR](https://github.com/wailsapp/wails/pull/3189) ### Fixed diff --git a/v3/pkg/application/application.go b/v3/pkg/application/application.go index 7215accb9..c68a03057 100644 --- a/v3/pkg/application/application.go +++ b/v3/pkg/application/application.go @@ -291,10 +291,6 @@ type App struct { // Keybindings keyBindings map[string]func(window *WebviewWindow) - // OnShutdown is called when the application is about to quit. - // This is useful for cleanup tasks. - // The shutdown process blocks until this function returns - OnShutdown func() performingShutdown bool } @@ -609,8 +605,8 @@ func (a *App) Quit() { return } a.performingShutdown = true - if a.OnShutdown != nil { - a.OnShutdown() + if a.options.OnShutdown != nil { + a.options.OnShutdown() } InvokeSync(func() { a.windowsLock.RLock() diff --git a/v3/pkg/application/options_application.go b/v3/pkg/application/options_application.go index 5ee2afe35..87f45c323 100644 --- a/v3/pkg/application/options_application.go +++ b/v3/pkg/application/options_application.go @@ -51,6 +51,11 @@ type Options struct { // KeyBindings is a map of key bindings to functions KeyBindings map[string]func(window *WebviewWindow) + + // OnShutdown is called when the application is about to quit. + // This is useful for cleanup tasks. + // The shutdown process blocks until this function returns + OnShutdown func() } // AssetOptions defines the configuration of the AssetServer.