mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-21 07:16:18 -04:00
Add Timeout to automatically close Notifications
This commit is contained in:
parent
819697d697
commit
82de30525b
2 changed files with 12 additions and 5 deletions
|
@ -361,19 +361,26 @@ class Notifications {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_notify(message, body) {
|
_notify(message, body, closeTimeout = 10000) {
|
||||||
const config = {
|
const config = {
|
||||||
body: body,
|
body: body,
|
||||||
icon: '/images/logo_transparent_128x128.png',
|
icon: '/images/logo_transparent_128x128.png',
|
||||||
}
|
}
|
||||||
|
let notification;
|
||||||
try {
|
try {
|
||||||
return new Notification(message, config);
|
notification = new Notification(message, config);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// android doesn't support "new Notification" if service worker is installed
|
// Android doesn't support "new Notification" if service worker is installed
|
||||||
if (!serviceWorker || !serviceWorker.showNotification) return;
|
if (!serviceWorker || !serviceWorker.showNotification) return;
|
||||||
return serviceWorker.showNotification(message, config);
|
notification = serviceWorker.showNotification(message, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notification is persistent on Android. We have to close it manually
|
||||||
|
if(closeTimeout){
|
||||||
|
setTimeout( _ => notification.close(), closeTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
_messageNotification(message) {
|
_messageNotification(message) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var CACHE_NAME = 'snapdrop-cache-v1.01';
|
var CACHE_NAME = 'snapdrop-cache-v1.02';
|
||||||
var urlsToCache = [
|
var urlsToCache = [
|
||||||
'/',
|
'/',
|
||||||
'/styles.css',
|
'/styles.css',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue