mirror of
https://github.com/captbaritone/webamp.git
synced 2026-01-23 02:15:01 +00:00
Provide a way to prevent closing Webamp (#655)
* Provide a way to prevent closing Webamp Fixes #653 * Fix typos for onWillClose in usage and types
This commit is contained in:
parent
17756eaa60
commit
ff06c96de2
7 changed files with 60 additions and 4 deletions
|
|
@ -216,6 +216,21 @@ const unsubscribe = webamp.onTrackDidChange((track => {
|
|||
unsubscribe();
|
||||
```
|
||||
|
||||
### `onWillClose(callback)`
|
||||
|
||||
A callback which will be called when Webamp is _about to_ close. Returns an "unsubscribe" function. The callback will be passed a `cancel` function which you can use to conditionally prevent Webamp from being closed.
|
||||
|
||||
```JavaScript
|
||||
const unsubscribe = webamp.onWillClose((cancel) => {
|
||||
if (!window.confirm("Are you sure you want to close Webamp?")) {
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
|
||||
// If at some point in the future you want to stop listening to these events:
|
||||
unsubscribe();
|
||||
```
|
||||
|
||||
### `onClose(callback)`
|
||||
|
||||
A callback which will be called when Webamp is closed. Returns an "unsubscribe" function.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue