From 3d05a6ee1eaea82a7710969f113bf314f9967972 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 21 Feb 2017 17:01:05 +0200 Subject: [PATCH] chore(notify) new -> module.exports --- client/notify.js | 71 ++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/client/notify.js b/client/notify.js index ee43772d..6ce1209c 100644 --- a/client/notify.js +++ b/client/notify.js @@ -4,48 +4,43 @@ const Events = require('./events'); -module.exports = new Notify(); +let Show; -function Notify() { - let Show; +Events.add({ + 'blur': () => { + Show = true; + }, + 'focus': () => { + Show = false; + } +}); + +module.exports.send = (msg) => { + const notifications = CloudCmd.config('notifications'); + const focus = window.focus.bind(window); + const granted = check(); - const Notify = this; - const Notification = window.Notification; + if (!notifications || !granted || !Show) + return; - Events.add({ - 'blur': () => { - Show = true; - }, - 'focus': () => { - Show = false; - } + const notify = new Notification(msg, { + icon: '/img/favicon/favicon-notify.png' }); + + Events.addClick(notify, focus); +}; + +module.exports.check = check; + +function check() { + const Not = Notification; + const perm = Not && Not.permission; - this.send = (msg) => { - const notifications = CloudCmd.config('notifications'); - const focus = window.focus.bind(window); - const granted = Notify.check(); - - if (notifications && granted && Show) { - const notify = new Notification(msg, { - icon: '/img/favicon/favicon-notify.png' - }); - - Events.addClick(notify, focus); - } - }; - - this.check = () => { - const Not = Notification; - const perm = Not && Not.permission; - - if (perm === 'granted') - return true; - }; - - this.request = () => { - if (Notification) - Notification.requestPermission(); - }; + return perm === 'granted'; } +module.exports.request = () => { + if (Notification) + Notification.requestPermission(); +}; +