5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 22:31:06 +08:00

[website] Add OnBeforeClose docs

This commit is contained in:
Lea\Anthony 2021-12-04 14:31:59 +11:00
parent ac803aa426
commit ffc0765a2f
2 changed files with 27 additions and 0 deletions

View File

@ -119,6 +119,8 @@ A standard Go context is passed to this method. This context is required when ca
a reference to in this method. Just before the application shuts down, the [OnShutdown](/docs/reference/options#OnShutdown) callback is called in the same way,
again with the context. There is also an [OnDomReady](/docs/reference/options#OnDomReady) callback for when the frontend
has completed loading all assets in `index.html` and is equivalent of the [`body onload`](https://www.w3schools.com/jsref/event_onload.asp) event in Javascript.
It is also possible to hook into the window close (or application quit) event by setting the
option [OnBeforeClose](/docs/reference/options#OnBeforeClose).
#### Method Binding

View File

@ -260,6 +260,31 @@ Type: func(ctx context.Context)
This callback is called after the frontend has been destroyed, just before the application terminates. It is given
the application context.
### OnBeforeClose
Name: OnBeforeClose
Type: func(ctx context.Context) bool
If this callback is set, it will be called when the application is about to quit, either by clicking the window close
button or calling `runtime.Quit`. Returning true will cause the application to continue, false will continue shutdown
as normal. This is good for confirming with the user that they wish to exit the program.
Example:
```go title=windowsapp.go
func (b *App) beforeClose(ctx context.Context) (prevent bool) {
dialog, err := runtime.MessageDialog(ctx, runtime.MessageDialogOptions{
Type: runtime.QuestionDialog,
Title: "Quit?",
Message: "Are you sure you want to quit?",
})
if err != nil {
return false
}
return dialog != "Yes"
```
### WindowStartState
Name: WindowStartState