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:
Jordan Eldredge 2018-09-20 06:19:28 -07:00 committed by GitHub
parent 17756eaa60
commit ff06c96de2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 60 additions and 4 deletions

View file

@ -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.