aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2017-10-30 22:52:03 +0100
committerLibravatar Stefan Malzner <stefan@adlk.io>2017-10-30 22:52:03 +0100
commit9593b28a7b2c3aa4adb6ccca5d4d2d5bf0b95017 (patch)
tree10b4e58272736e60f992f51b891f36737b030837
parentMerge pull request #176 from meetfranz/feature/fix-hosted-service-import (diff)
downloadferdium-app-9593b28a7b2c3aa4adb6ccca5d4d2d5bf0b95017.tar.gz
ferdium-app-9593b28a7b2c3aa4adb6ccca5d4d2d5bf0b95017.tar.zst
ferdium-app-9593b28a7b2c3aa4adb6ccca5d4d2d5bf0b95017.zip
Recipe Notification API refactor
Fixes: #104
-rw-r--r--src/webview/notifications.js41
1 files 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 @@
1const { ipcRenderer } = require('electron'); 1const { ipcRenderer } = require('electron');
2const uuidV1 = require('uuid/v1'); 2const uuidV1 = require('uuid/v1');
3// const FranzNotificationStore = [];
4 3
5class Notification { 4class Notification {
5 static permission = 'granted';
6
6 constructor(title = '', options = {}) { 7 constructor(title = '', options = {}) {
7 this.title = title; 8 this.title = title;
8 this.options = options; 9 this.options = options;
9 this.notificationId = uuidV1(); 10 this.notificationId = uuidV1();
10 this.onclick = () => { };
11 11
12 ipcRenderer.sendToHost('notification', Notification.onNotify({ 12 ipcRenderer.sendToHost('notification', this.onNotify({
13 notificationId: this.notificationId, 13 notificationId: this.notificationId,
14 title, 14 title,
15 options, 15 options,
16 })); 16 }));
17 17
18 ipcRenderer.on(`notification-onclick:${this.notificationId}`, () => { 18 ipcRenderer.once(`notification-onclick:${this.notificationId}`, () => {
19 this.onclick(); 19 this.onclick();
20 }); 20 });
21 } 21 }
22}
23 22
24Notification.permission = 'granted'; 23 static requestPermission(cb = null) {
24 if (!cb) {
25 return new Promise((resolve) => {
26 resolve(Notification.permission);
27 });
28 }
25 29
26Notification.requestPermission = (cb = null) => { 30 if (typeof (cb) === 'function') {
27 console.log(this); 31 return cb(Notification.permission);
28 if (!cb) { 32 }
29 return new Promise((resolve) => {
30 resolve(Notification.permission);
31 });
32 }
33 33
34 if (typeof (cb) === 'function') { 34 return Notification.permission;
35 return cb(Notification.permission);
36 } 35 }
37 36
38 return Notification.permission; 37 onNotify(data) {
39}; 38 return data;
39 }
40 40
41Notification.close = () => { 41 onClick() {}
42 // no implementation yet
43};
44 42
45Notification.onNotify = data => data; 43 close() {}
44}
46 45
47window.Notification = Notification; 46window.Notification = Notification;