Notifications

This commit is contained in:
RobinLinus 2018-09-21 22:31:46 +02:00
parent 5a631d3833
commit 476cb0ae65

View file

@ -335,7 +335,7 @@ class Notifications {
constructor() { constructor() {
// Check if the browser supports notifications // Check if the browser supports notifications
if (!('Notification' in window)) return; if (!('Notification' in window)) return;
// Check whether notification permissions have already been granted // Check whether notification permissions have already been granted
if (Notification.permission !== 'granted') { if (Notification.permission !== 'granted') {
this.$button = $('notification'); this.$button = $('notification');
@ -361,11 +361,12 @@ class Notifications {
const config = { const config = {
body: body, body: body,
icon: '/images/logo_transparent_128x128.png', icon: '/images/logo_transparent_128x128.png',
// vibrate: [200, 100, 200, 100, 200, 100, 400],
// requireInteraction: true
} }
if (serviceWorker && serviceWorker.showNotification) { if (serviceWorker && serviceWorker.showNotification) {
// android doesn't support "new Notification" if service worker is installed // android doesn't support "new Notification" if service worker is installed
config.actions = {
{ "action": "yes", "title": "Yes"}
};
return serviceWorker.showNotification(message, config); return serviceWorker.showNotification(message, config);
} else { } else {
return new Notification(message, config); return new Notification(message, config);
@ -385,11 +386,20 @@ class Notifications {
_downloadNotification(message) { _downloadNotification(message) {
const notification = this._notify(message, 'Click to download'); const notification = this._notify(message, 'Click to download');
if (window.isDownloadSupported) return; if (window.isDownloadSupported) return;
notification.onclick = e => { notification.onclick = e => this._download(e);
document.querySelector('x-dialog [download]').click();
};
} }
_download(e) {
document.querySelector('x-dialog [download]').click();
e.target.close();
}
_copyText(notification, message) {
console.log('message');
document.copy(message);
this._notify('Copied to clipboard');
notification.close();
}
} }
class Snapdrop { class Snapdrop {