fix: SDA-2811 - Replace native electron notification with same tag (#1163)

This commit is contained in:
Kiran Niranjan 2020-12-30 17:44:25 +05:30 committed by GitHub
parent 420dee0d48
commit 6fdb80857f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,9 +7,11 @@ import { ElectronNotification } from './electron-notification';
class NotificationHelper { class NotificationHelper {
private electronNotification: Map<number, ElectronNotification>; private electronNotification: Map<number, ElectronNotification>;
private activeElectronNotification: Map<string, ElectronNotification>;
constructor() { constructor() {
this.electronNotification = new Map<number, ElectronNotification>(); this.electronNotification = new Map<number, ElectronNotification>();
this.activeElectronNotification = new Map<string, ElectronNotification>();
} }
/** /**
@ -22,8 +24,19 @@ class NotificationHelper {
if (options.isElectronNotification) { if (options.isElectronNotification) {
// MacOS: Electron notification only supports static image path // MacOS: Electron notification only supports static image path
options.icon = this.getIcon(options); options.icon = this.getIcon(options);
// This is replace notification with same tag
if (this.activeElectronNotification.has(options.tag)) {
const electronNotification = this.activeElectronNotification.get(options.tag);
if (electronNotification) {
electronNotification.close();
}
this.activeElectronNotification.delete(options.tag);
}
const electronToast = new ElectronNotification(options, this.notificationCallback); const electronToast = new ElectronNotification(options, this.notificationCallback);
this.electronNotification.set(options.id, electronToast); this.electronNotification.set(options.id, electronToast);
this.activeElectronNotification.set(options.tag, electronToast);
electronToast.show(); electronToast.show();
return; return;
} }