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:
parent
ac803aa426
commit
ffc0765a2f
@ -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,
|
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
|
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.
|
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
|
#### Method Binding
|
||||||
|
|
||||||
|
@ -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
|
This callback is called after the frontend has been destroyed, just before the application terminates. It is given
|
||||||
the application context.
|
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
|
### WindowStartState
|
||||||
|
|
||||||
Name: WindowStartState
|
Name: WindowStartState
|
||||||
|
Loading…
Reference in New Issue
Block a user