2
0
mirror of https://github.com/tenrok/vue-native-notification.git synced 2026-05-17 04:09:39 +03:00

Add fallback for Chrome on mobile

This commit is contained in:
Quentin
2018-07-30 10:52:14 +01:00
parent 9d60bad87f
commit 3693990690
2 changed files with 17 additions and 8 deletions
+16 -7
View File
@@ -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
+1 -1
View File
@@ -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<e.length;u++)i(e[u]);return i})({1:[function(n,o,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});var e=window.Notification||window.webkitNotification;var i=function n(o){};var t=function n(o){o.preventDefault();window.focus();o.target.close()};var u=function n(o){};var f=function n(o){};var c={onerror:i,onclick:t,onclose:u,onshow:f};var s={install:function n(o,r){r=r||{};r.requestOnNotify=r.requestOnNotify||true;o.notification={};o.prototype.$notification={};var i=function n(){return e.requestPermission()};o.notification.requestPermission=i;o.prototype.$notification.requestPermission=i;var t=function n(o,t,u){var f=u.onerror,s=f===undefined?function(){}:f,a=u.onclick,d=a===undefined?function(){}:a,v=u.onclose,w=v===undefined?function(){}:v,l=u.onshow,p=l===undefined?function(){}:l;return Promise.resolve().then(function(){if(r.requestOnNotify&&e.permission!=="granted"){return i()}return e.permission}).then(function(n){if(n==="denied"){return new Error("No permission to show notification")}var r=new e(o,t);var i=function n(o){"use strict";c.onerror(o);s()};var u=function n(o){"use strict";c.onclick(o);d()};var f=function n(o){"use strict";c.onclose(o);w()};var a=function n(o){"use strict";c.onshow(o);p()};r.onerror=i;r.onclick=u;r.onclose=f;r.onshow=a;return r})};o.notification.show=t;o.prototype.$notification.show=t}};if(typeof window!=="undefined"&&window.Vue){window.Vue.use(s)}r.default=s},{}]},{},[1]);
(function(){function a(i,u,c){function f(r,n){if(!u[r]){if(!i[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 e=u[r]={exports:{}};i[r][0].call(e.exports,function(n){var o=i[r][1][n];return f(o||n)},e,e.exports,a,i,u,c)}return u[r].exports}for(var s="function"==typeof require&&require,n=0;n<c.length;n++)f(c[n]);return f}return a})()({1:[function(n,o,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});var l=window.Notification||window.webkitNotification;var t=function n(o){};var e=function n(o){o.preventDefault();window.focus();o.target.close()};var i=function n(o){};var u=function n(o){};var p={onerror:t,onclick:e,onclose:i,onshow:u};var c={install:function n(o,w){w=w||{};w.requestOnNotify=w.requestOnNotify||true;o.notification={};o.prototype.$notification={};var v=function n(){return l.requestPermission()};o.notification.requestPermission=v;o.prototype.$notification.requestPermission=v;var r=function n(u,c,o){var r=o.onerror,f=r===undefined?function(){}:r,t=o.onclick,s=t===undefined?function(){}:t,e=o.onclose,a=e===undefined?function(){}:e,i=o.onshow,d=i===undefined?function(){}:i;return Promise.resolve().then(function(){if(w.requestOnNotify&&l.permission!=="granted"){return v()}return l.permission}).then(function(n){if(n==="denied"){return new Error("No permission to show notification")}try{var o=new l(u,c);var r=function n(o){"use strict";p.onerror(o);f()};var t=function n(o){"use strict";p.onclick(o);s()};var e=function n(o){"use strict";p.onclose(o);a()};var i=function n(o){"use strict";p.onshow(o);d()};o.onerror=r;o.onclick=t;o.onclose=e;o.onshow=i;return o}catch(n){if(n.name!=="TypeError")throw n;return navigator.serviceWorker.ready.then(function(n){return n.showNotification(u,c)})}})};o.notification.show=r;o.prototype.$notification.show=r}};if(typeof window!=="undefined"&&window.Vue){window.Vue.use(c)}r.default=c},{}]},{},[1]);