mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-22 07:46:17 -04:00
QoL: Native notification improvements
Only send native notification when document is not visible, clear notifications when document become visible.
This commit is contained in:
parent
a96dde25c0
commit
529be8c55e
1 changed files with 21 additions and 13 deletions
|
@ -420,7 +420,7 @@ class Notifications {
|
|||
});
|
||||
}
|
||||
|
||||
_notify(message, body, closeTimeout = 20000) {
|
||||
_notify(message, body) {
|
||||
const config = {
|
||||
body: body,
|
||||
icon: '/images/logo_transparent_128x128.png',
|
||||
|
@ -435,14 +435,19 @@ class Notifications {
|
|||
}
|
||||
|
||||
// Notification is persistent on Android. We have to close it manually
|
||||
if (closeTimeout) {
|
||||
setTimeout(_ => notification.close(), closeTimeout);
|
||||
const visibilitychangeHandler = () => {
|
||||
if (document.visibilityState === 'visible') {
|
||||
notification.close();
|
||||
document.removeEventListener('visibilitychange', visibilitychangeHandler);
|
||||
}
|
||||
};
|
||||
document.addEventListener('visibilitychange', visibilitychangeHandler);
|
||||
|
||||
return notification;
|
||||
}
|
||||
|
||||
_messageNotification(message) {
|
||||
if (document.visibilityState !== 'visible') {
|
||||
if (isURL(message)) {
|
||||
const notification = this._notify(message, 'Click to open link');
|
||||
this._bind(notification, e => window.open(message, '_blank', null, true));
|
||||
|
@ -451,12 +456,15 @@ class Notifications {
|
|||
this._bind(notification, e => this._copyText(message, notification));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_downloadNotification(message) {
|
||||
if (document.visibilityState !== 'visible') {
|
||||
const notification = this._notify(message, 'Click to download');
|
||||
if (!window.isDownloadSupported) return;
|
||||
this._bind(notification, e => this._download(notification));
|
||||
}
|
||||
}
|
||||
|
||||
_download(notification) {
|
||||
document.querySelector('x-dialog [download]').click();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue