-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
47 lines (39 loc) · 1.05 KB
/
renderer.js
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
function main() {
if (Notification.permission !== "granted") {
Notification.requestPermission().then((permission) => {
if (permission !== "granted") {
alert("Notification permission denied");
return;
}
});
}
function sendNotification(body) {
if (exposed.platform === "darwin") {
new Notification("Battery Status", {
body: body,
requireInteraction: true,
});
return;
}
new Notification("Battery Status", {
body: body,
icon: "images/icon.ico",
requireInteraction: true,
});
}
navigator.getBattery().then((batteryManager) => {
batteryManager.addEventListener("levelchange", (_event) => {
const level = Math.round(batteryManager.level * 100);
if (batteryManager.charging) {
if (level >= 80) {
sendNotification(`You might want to unplug your PC (${level}%)`);
}
return;
}
if (level <= 20) {
sendNotification(`You might want to plug in your PC (${level}%)`);
}
});
});
}
main();