aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/notifications.js
diff options
context:
space:
mode:
authorLibravatar Markus Hatvan <markus_hatvan@aon.at>2021-10-14 09:32:20 +0200
committerLibravatar GitHub <noreply@github.com>2021-10-14 13:02:20 +0530
commit52211095aab71f8b59b093b19ae34c222be9f390 (patch)
tree28f24a9be5ee5577667cdd396fb3fc64fc861e65 /src/webview/notifications.js
parentchore: convert class components to functional (#2065) (diff)
downloadferdium-app-52211095aab71f8b59b093b19ae34c222be9f390.tar.gz
ferdium-app-52211095aab71f8b59b093b19ae34c222be9f390.tar.zst
ferdium-app-52211095aab71f8b59b093b19ae34c222be9f390.zip
chore: convert various JS to TS (#2062)
Diffstat (limited to 'src/webview/notifications.js')
-rw-r--r--src/webview/notifications.js71
1 files changed, 0 insertions, 71 deletions
diff --git a/src/webview/notifications.js b/src/webview/notifications.js
deleted file mode 100644
index 22960d818..000000000
--- a/src/webview/notifications.js
+++ /dev/null
@@ -1,71 +0,0 @@
1import { ipcRenderer } from 'electron';
2
3import { v1 as uuidV1 } from 'uuid';
4
5const debug = require('debug')('Ferdi:Notifications');
6
7export class NotificationsHandler {
8 onNotify = data => data;
9
10 displayNotification(title, options) {
11 return new Promise(resolve => {
12 debug('New notification', title, options);
13
14 const notificationId = uuidV1();
15
16 ipcRenderer.sendToHost(
17 'notification',
18 this.onNotify({
19 title,
20 options,
21 notificationId,
22 }),
23 );
24
25 ipcRenderer.once(`notification-onclick:${notificationId}`, () => {
26 resolve();
27 });
28 });
29 }
30}
31
32export const notificationsClassDefinition = `(() => {
33 class Notification {
34 static permission = 'granted';
35
36 constructor(title = '', options = {}) {
37 this.title = title;
38 this.options = options;
39 window.ferdi.displayNotification(title, options)
40 .then(() => {
41 if (typeof (this.onClick) === 'function') {
42 this.onClick();
43 }
44 });
45 }
46
47 static requestPermission(cb = null) {
48 if (!cb) {
49 return new Promise((resolve) => {
50 resolve(Notification.permission);
51 });
52 }
53
54 if (typeof (cb) === 'function') {
55 return cb(Notification.permission);
56 }
57
58 return Notification.permission;
59 }
60
61 onNotify(data) {
62 return data;
63 }
64
65 onClick() {}
66
67 close() {}
68 }
69
70 window.Notification = Notification;
71})();`;