Files
ignis/shims/electron/remote/notification.js

38 lines
878 B
JavaScript
Raw Normal View History

2026-03-07 14:38:51 +01:00
export class notificationShim {
constructor(options = {}) {
2026-03-11 22:08:30 +01:00
this.title = options.title || "";
this.body = options.body || "";
2026-03-07 14:38:51 +01:00
this.silent = options.silent || false;
this._handlers = {};
}
show() {
2026-03-11 22:08:30 +01:00
if ("Notification" in window && Notification.permission === "granted") {
2026-03-07 14:38:51 +01:00
new Notification(this.title, { body: this.body, silent: this.silent });
2026-03-11 22:08:30 +01:00
} else if (
"Notification" in window &&
Notification.permission !== "denied"
) {
2026-03-07 14:38:51 +01:00
Notification.requestPermission().then((perm) => {
2026-03-11 22:08:30 +01:00
if (perm === "granted") {
new Notification(this.title, {
body: this.body,
silent: this.silent,
});
2026-03-07 14:38:51 +01:00
}
});
}
}
close() {}
on(event, handler) {
this._handlers[event] = handler;
return this;
}
static isSupported() {
2026-03-11 22:08:30 +01:00
return "Notification" in window;
2026-03-07 14:38:51 +01:00
}
}