-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
80 lines (70 loc) · 2.39 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { create, addEventListener as addNotificationEventListener, NotificationOptions } from "@openfin/workspace/notifications";
function addNotificationListeners() {
addNotificationEventListener("notification-created", (event) => {
console.log(`Created: ${event.notification.id}`);
});
addNotificationEventListener("notification-closed", (event) => {
console.log(`Closed: ${event.notification.id}`);
});
addNotificationEventListener("notification-action", (event) => {
if (event?.result?.BODY_CLICK === "dismiss_event") {
if (event.notification?.customData?.action) {
console.log(
`Data: ${
event?.notification?.customData ? JSON.stringify(event.notification.customData) : "None"
}`
);
} else {
console.log("No action");
}
console.log("Body click dismiss");
} else {
console.log(
`Data: ${event?.result?.customData ? JSON.stringify(event.result.customData) : "None"}`
);
console.log(`Task: ${event?.result?.task ?? "None"}`);
console.log(`Action: ${event.notification.id}`);
}
console.log(event);
});
addNotificationEventListener("notification-toast-dismissed", (event) => {
console.log(`Toast Dismissed: ${event.notification.id}`);
});
addNotificationEventListener("notification-form-submitted", (event) => {
console.log(`Data: ${event?.form ? JSON.stringify(event.form) : "None"}`);
console.log(`Form: ${event.notification.id}`);
console.log(event);
});
addNotificationEventListener("notifications-count-changed", (event) => {
console.log(`Notification Count: ${event.count}`);
});
}
async function init() {
const contact = document.querySelector<HTMLInputElement>("#contact");
const execute = document.querySelector("#execute");
const result = document.querySelector("#result");
result.textContent = "Not Set";
execute.addEventListener("click", () => {
const value = contact.value;
console.log(`Value ${value}`);
result.textContent = contact.value;
const notification: NotificationOptions = {
title: "Simple Notification",
body: `This is a simple notification. Input: ${contact.value}`,
toast: "transient",
category: "default",
template: "markdown",
id: `id-${Date.now()}`,
platform: fin.me.identity.uuid
};
create(notification);
});
addNotificationListeners();
}
document.addEventListener("DOMContentLoaded", async () => {
try {
await init();
} catch (error) {
console.error(error);
}
});