diff --git a/index.js b/index.js index 05f736f..bca0054 100644 --- a/index.js +++ b/index.js @@ -64,8 +64,6 @@ const VueNativeNotification = { return new Error('No permission to show notification') } - // Create Notification object - const notification = new Notification(title, opts) const bindOnError = function (event) { 'use strict' @@ -91,12 +89,23 @@ const VueNativeNotification = { onshow() } - notification.onerror = bindOnError - notification.onclick = bindOnClick - notification.onclose = bindOnClose - notification.onshow = bindOnShow + // Create Notification object + try { + const notification = new Notification(title, opts) - return notification + notification.onerror = bindOnError + notification.onclick = bindOnClick + notification.onclose = bindOnClose + notification.onshow = bindOnShow + + return notification + } catch (e) { + if (e.name !== 'TypeError') + return e + + return navigator.serviceWorker.ready.then(reg => reg.showNotification(title, opts)) + .then(bindOnShow, bindOnError) + } }) } Vue.notification.show = show diff --git a/vue-native-notification.min.js b/vue-native-notification.min.js index 699fe45..84bb9d3 100644 --- a/vue-native-notification.min.js +++ b/vue-native-notification.min.js @@ -1 +1 @@ -(function(){function a(e,u,c){function f(r,n){if(!u[r]){if(!e[r]){var o="function"==typeof require&&require;if(!n&&o)return o(r,!0);if(s)return s(r,!0);var t=new Error("Cannot find module '"+r+"'");throw t.code="MODULE_NOT_FOUND",t}var i=u[r]={exports:{}};e[r][0].call(i.exports,function(n){var o=e[r][1][n];return f(o||n)},i,i.exports,a,e,u,c)}return u[r].exports}for(var s="function"==typeof require&&require,n=0;n