Skip to content

Instantly share code, notes, and snippets.

@malko
Created March 20, 2017 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malko/697543ad1c85fb065a8dd51579a44a82 to your computer and use it in GitHub Desktop.
Save malko/697543ad1c85fb065a8dd51579a44a82 to your computer and use it in GitHub Desktop.
Notification api
const notificationGrantedPromise = () => {
if (!('Notification' in window)) {
return Promise.reject();
}
return (Notification.permission !== 'default') ? Promise.resolve(Notification.permission) : Notification.requestPermission();
};
const notify = (...args) => notificationGrantedPromise().then((permission) => permission === 'granted' ? new Notification(...args) : null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment