diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-30 22:52:03 +0100 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2017-10-30 22:52:03 +0100 |
commit | 9593b28a7b2c3aa4adb6ccca5d4d2d5bf0b95017 (patch) | |
tree | 10b4e58272736e60f992f51b891f36737b030837 /src | |
parent | Merge pull request #176 from meetfranz/feature/fix-hosted-service-import (diff) | |
download | ferdium-app-9593b28a7b2c3aa4adb6ccca5d4d2d5bf0b95017.tar.gz ferdium-app-9593b28a7b2c3aa4adb6ccca5d4d2d5bf0b95017.tar.zst ferdium-app-9593b28a7b2c3aa4adb6ccca5d4d2d5bf0b95017.zip |
Recipe Notification API refactor
Fixes: #104
Diffstat (limited to 'src')
-rw-r--r-- | src/webview/notifications.js | 41 |
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 @@ | |||
1 | const { ipcRenderer } = require('electron'); | 1 | const { ipcRenderer } = require('electron'); |
2 | const uuidV1 = require('uuid/v1'); | 2 | const uuidV1 = require('uuid/v1'); |
3 | // const FranzNotificationStore = []; | ||
4 | 3 | ||
5 | class Notification { | 4 | class 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 | ||
24 | Notification.permission = 'granted'; | 23 | static requestPermission(cb = null) { |
24 | if (!cb) { | ||
25 | return new Promise((resolve) => { | ||
26 | resolve(Notification.permission); | ||
27 | }); | ||
28 | } | ||
25 | 29 | ||
26 | Notification.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 | ||
41 | Notification.close = () => { | 41 | onClick() {} |
42 | // no implementation yet | ||
43 | }; | ||
44 | 42 | ||
45 | Notification.onNotify = data => data; | 43 | close() {} |
44 | } | ||
46 | 45 | ||
47 | window.Notification = Notification; | 46 | window.Notification = Notification; |