-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathServiceWorker__test.js
More file actions
78 lines (74 loc) · 1.74 KB
/
ServiceWorker__test.js
File metadata and controls
78 lines (74 loc) · 1.74 KB
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
// Generated by ReScript, PLEASE EDIT WITH CARE
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
self.addEventListener("push", event => {
console.log("received push event");
let data = event.data;
let match;
if (data !== undefined) {
let match$1 = Primitive_option.valFromOption(data).json();
if (typeof match$1 === "object" && match$1 !== null && !Array.isArray(match$1)) {
let title = match$1.title;
if (typeof title === "string") {
let body = match$1.body;
match = typeof body === "string" ? [
title,
body
] : [
"???",
"???"
];
} else {
match = [
"???",
"???"
];
}
} else {
match = [
"???",
"???"
];
}
} else {
match = [
"???",
"???"
];
}
event.waitUntil(self.fetch("https://rescript-lang.org"));
self.registration.showNotification(match[0], {
body: match[1],
icon: "/icon.png",
data: 17,
actions: [
{
action: "open",
title: "Open"
},
{
action: "close",
title: "Close"
}
],
vibrate: [
200,
50,
200,
50,
400
]
});
});
self.addEventListener("notificationclick", event => {
console.log(`notification clicked: ` + event.action);
event.notification.close();
Stdlib_Option.forEach(Stdlib_Option.flatMap(event.notification.data, data => {
if (typeof data === "number") {
return data.toString();
}
}), id => {
self.clients.open(`https://mywebsite.com/mydata/` + id);
});
});
/* Not a pure module */