Skip to content

Commit 5f11c93

Browse files
author
Sven Scholz
committed
added options to Notification
rename content from _notify to title
1 parent 0a58363 commit 5f11c93

File tree

4 files changed

+13
-33
lines changed

4 files changed

+13
-33
lines changed

src/Notify/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CHANGELOG
22

3-
- Added body, icon, tag ,renotify to controller.js for mercure-notifier
3+
- Added options to Notification
4+
- Rename content from _notify to title
45

56
## 2.13.2
67

src/Notify/assets/dist/controller.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export default class extends Controller {
1313
initialize(): void;
1414
connect(): void;
1515
disconnect(): void;
16-
_notify(content: string | undefined, tag: string | undefined, body: string | undefined, icon: string | undefined, renotify: boolean | undefined): void;
16+
_notify(title: string | undefined, options: NotificationOptions | undefined): void;
1717
private dispatchEvent;
1818
}

src/Notify/assets/dist/controller.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class default_1 extends Controller {
2626
return;
2727
}
2828
this.eventSources.forEach((eventSource) => {
29-
const listener = (event) => this._notify(JSON.parse(event.data).summary, JSON.parse(event.data).tag, JSON.parse(event.data).body, JSON.parse(event.data).icon, JSON.parse(event.data).renotify);
29+
const listener = (event) => this._notify(JSON.parse(event.data).summary, JSON.parse(event.data).content);
3030
eventSource.addEventListener('message', listener);
3131
this.listeners.set(eventSource, listener);
3232
});
@@ -42,23 +42,17 @@ class default_1 extends Controller {
4242
});
4343
this.eventSources = [];
4444
}
45-
_notify(content, tag, body, icon, renotify) {
46-
if (!content)
45+
_notify(title, options) {
46+
if (!title)
4747
return;
48-
if (!tag)
49-
tag = '';
50-
if (!icon)
51-
icon = '';
52-
if (!body)
53-
body = '';
5448
if ('granted' === Notification.permission) {
55-
new Notification(content, { tag: tag, body: body, icon: icon, renotify: renotify });
49+
new Notification(title, options);
5650
return;
5751
}
5852
if ('denied' !== Notification.permission) {
5953
Notification.requestPermission().then((permission) => {
6054
if ('granted' === permission) {
61-
new Notification(content, { tag: tag, body: body, icon: icon, renotify: renotify });
55+
new Notification(title, options);
6256
}
6357
});
6458
}

src/Notify/assets/src/controller.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,7 @@ export default class extends Controller {
5252

5353
this.eventSources.forEach((eventSource) => {
5454
const listener = (event: MessageEvent) =>
55-
this._notify(
56-
JSON.parse(event.data).summary,
57-
JSON.parse(event.data).tag,
58-
JSON.parse(event.data).body,
59-
JSON.parse(event.data).icon,
60-
JSON.parse(event.data).renotify
61-
);
55+
this._notify(JSON.parse(event.data).summary, JSON.parse(event.data).content);
6256

6357
eventSource.addEventListener('message', listener);
6458
this.listeners.set(eventSource, listener);
@@ -80,28 +74,19 @@ export default class extends Controller {
8074
this.eventSources = [];
8175
}
8276

83-
_notify(
84-
content: string | undefined,
85-
tag: string | undefined,
86-
body: string | undefined,
87-
icon: string | undefined,
88-
renotify: boolean | undefined
89-
) {
90-
if (!content) return;
91-
if (!tag) tag = '';
92-
if (!icon) icon = '';
93-
if (!body) body = '';
77+
_notify(title: string | undefined, options: NotificationOptions | undefined) {
78+
if (!title) return;
9479

9580
if ('granted' === Notification.permission) {
96-
new Notification(content, { tag: tag, body: body, icon: icon, renotify: renotify });
81+
new Notification(title, options);
9782

9883
return;
9984
}
10085

10186
if ('denied' !== Notification.permission) {
10287
Notification.requestPermission().then((permission) => {
10388
if ('granted' === permission) {
104-
new Notification(content, { tag: tag, body: body, icon: icon, renotify: renotify });
89+
new Notification(title, options);
10590
}
10691
});
10792
}

0 commit comments

Comments
 (0)