mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-30 11:39:14 -04:00
Merge pull request #497 from Haocen/patch-3
QoL: Native notification improvements
This commit is contained in:
commit
112bed3730
2 changed files with 25 additions and 13 deletions
|
@ -512,6 +512,10 @@ class Events {
|
||||||
static on(type, callback) {
|
static on(type, callback) {
|
||||||
return window.addEventListener(type, callback, false);
|
return window.addEventListener(type, callback, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static off(type, callback) {
|
||||||
|
return window.removeEventListener(type, callback, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -420,7 +420,7 @@ class Notifications {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_notify(message, body, closeTimeout = 20000) {
|
_notify(message, body) {
|
||||||
const config = {
|
const config = {
|
||||||
body: body,
|
body: body,
|
||||||
icon: '/images/logo_transparent_128x128.png',
|
icon: '/images/logo_transparent_128x128.png',
|
||||||
|
@ -435,27 +435,35 @@ class Notifications {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notification is persistent on Android. We have to close it manually
|
// Notification is persistent on Android. We have to close it manually
|
||||||
if (closeTimeout) {
|
const visibilitychangeHandler = () => {
|
||||||
setTimeout(_ => notification.close(), closeTimeout);
|
if (document.visibilityState === 'visible') {
|
||||||
}
|
notification.close();
|
||||||
|
Events.off('visibilitychange', visibilitychangeHandler);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Events.on('visibilitychange', visibilitychangeHandler);
|
||||||
|
|
||||||
return notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
_messageNotification(message) {
|
_messageNotification(message) {
|
||||||
if (isURL(message)) {
|
if (document.visibilityState !== 'visible') {
|
||||||
const notification = this._notify(message, 'Click to open link');
|
if (isURL(message)) {
|
||||||
this._bind(notification, e => window.open(message, '_blank', null, true));
|
const notification = this._notify(message, 'Click to open link');
|
||||||
} else {
|
this._bind(notification, e => window.open(message, '_blank', null, true));
|
||||||
const notification = this._notify(message, 'Click to copy text');
|
} else {
|
||||||
this._bind(notification, e => this._copyText(message, notification));
|
const notification = this._notify(message, 'Click to copy text');
|
||||||
|
this._bind(notification, e => this._copyText(message, notification));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_downloadNotification(message) {
|
_downloadNotification(message) {
|
||||||
const notification = this._notify(message, 'Click to download');
|
if (document.visibilityState !== 'visible') {
|
||||||
if (!window.isDownloadSupported) return;
|
const notification = this._notify(message, 'Click to download');
|
||||||
this._bind(notification, e => this._download(notification));
|
if (!window.isDownloadSupported) return;
|
||||||
|
this._bind(notification, e => this._download(notification));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_download(notification) {
|
_download(notification) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue