From 9593b28a7b2c3aa4adb6ccca5d4d2d5bf0b95017 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Mon, 30 Oct 2017 22:52:03 +0100 Subject: Recipe Notification API refactor Fixes: #104 --- src/webview/notifications.js | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/webview/notifications.js b/src/webview/notifications.js index b3397148d..4055b10de 100644 --- a/src/webview/notifications.js +++ b/src/webview/notifications.js @@ -1,47 +1,46 @@ const { ipcRenderer } = require('electron'); const uuidV1 = require('uuid/v1'); -// const FranzNotificationStore = []; class Notification { + static permission = 'granted'; + constructor(title = '', options = {}) { this.title = title; this.options = options; this.notificationId = uuidV1(); - this.onclick = () => { }; - ipcRenderer.sendToHost('notification', Notification.onNotify({ + ipcRenderer.sendToHost('notification', this.onNotify({ notificationId: this.notificationId, title, options, })); - ipcRenderer.on(`notification-onclick:${this.notificationId}`, () => { + ipcRenderer.once(`notification-onclick:${this.notificationId}`, () => { this.onclick(); }); } -} -Notification.permission = 'granted'; + static requestPermission(cb = null) { + if (!cb) { + return new Promise((resolve) => { + resolve(Notification.permission); + }); + } -Notification.requestPermission = (cb = null) => { - console.log(this); - if (!cb) { - return new Promise((resolve) => { - resolve(Notification.permission); - }); - } + if (typeof (cb) === 'function') { + return cb(Notification.permission); + } - if (typeof (cb) === 'function') { - return cb(Notification.permission); + return Notification.permission; } - return Notification.permission; -}; + onNotify(data) { + return data; + } -Notification.close = () => { - // no implementation yet -}; + onClick() {} -Notification.onNotify = data => data; + close() {} +} window.Notification = Notification; -- cgit v1.2.3-70-g09d2