mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
implement shims
This commit is contained in:
34
shims/electron/remote/notification.js
Normal file
34
shims/electron/remote/notification.js
Normal file
@@ -0,0 +1,34 @@
|
||||
// Shim for remote.Notification
|
||||
// Maps to browser Notification API
|
||||
|
||||
export class notificationShim {
|
||||
constructor(options = {}) {
|
||||
this.title = options.title || '';
|
||||
this.body = options.body || '';
|
||||
this.silent = options.silent || false;
|
||||
this._handlers = {};
|
||||
}
|
||||
|
||||
show() {
|
||||
if ('Notification' in window && Notification.permission === 'granted') {
|
||||
new Notification(this.title, { body: this.body, silent: this.silent });
|
||||
} else if ('Notification' in window && Notification.permission !== 'denied') {
|
||||
Notification.requestPermission().then((perm) => {
|
||||
if (perm === 'granted') {
|
||||
new Notification(this.title, { body: this.body, silent: this.silent });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
close() {}
|
||||
|
||||
on(event, handler) {
|
||||
this._handlers[event] = handler;
|
||||
return this;
|
||||
}
|
||||
|
||||
static isSupported() {
|
||||
return 'Notification' in window;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user