From 3693990690d282a8b9c1dd0fc30ec267e925bcda Mon Sep 17 00:00:00 2001 From: Quentin Date: Mon, 30 Jul 2018 10:52:14 +0100 Subject: [PATCH] Add fallback for Chrome on mobile --- index.js | 23 ++++++++++++++++------- vue-native-notification.min.js | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 790b06b..f51b6f4 100644 --- a/index.js +++ b/index.js @@ -65,8 +65,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' @@ -92,12 +90,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 54cf363..84bb9d3 100644 --- a/vue-native-notification.min.js +++ b/vue-native-notification.min.js @@ -1 +1 @@ -(function n(o,r,e){function i(u,f){if(!r[u]){if(!o[u]){var c=typeof require=="function"&&require;if(!f&&c)return c(u,!0);if(t)return t(u,!0);var s=new Error("Cannot find module '"+u+"'");throw s.code="MODULE_NOT_FOUND",s}var a=r[u]={exports:{}};o[u][0].call(a.exports,function(n){var r=o[u][1][n];return i(r?r:n)},a,a.exports,n,o,r,e)}return r[u].exports}var t=typeof require=="function"&&require;for(var u=0;u