From d6787baad80adba6ce9a61f994798b06056b8380 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 2 Dec 2020 17:51:39 +0900 Subject: [PATCH] bug fixed --- .../src/lib/services/notification.service.ts | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/projects/notification-electron/src/lib/services/notification.service.ts b/projects/notification-electron/src/lib/services/notification.service.ts index 86471a1..766e856 100644 --- a/projects/notification-electron/src/lib/services/notification.service.ts +++ b/projects/notification-electron/src/lib/services/notification.service.ts @@ -90,7 +90,7 @@ export interface Notification { 'width' >; displayTime?: number; - template: Template; + template?: Template; data?: any; onShow?: OnShow4NotificationWindow; onClose?: OnClose4NotificationWindow; @@ -151,6 +151,9 @@ class WindowPooler { interface Activated { notification: Notification; browserWindow: Electron.BrowserWindow; + callbacks: { + onCloseFunc: (reason?: any) => void; + }; } export class NotificationService { @@ -201,13 +204,19 @@ export class NotificationService { }); } + close(id: number): void { + const activated = this.__findActivatedByNotificationId(id); + if (!activated) { + return; + } + activated.callbacks.onCloseFunc(); + } + closeAll(): void { - this.__animationQueue.clear(); - this.__activated.forEach(a => { - a.browserWindow.close(); - }); - this.__activated = []; this.__delayQueue = []; + this.__activated.forEach(a => { + a.callbacks.onCloseFunc(); + }); this.__closed.clear(); this.__windowPooler.closeAll(); } @@ -224,11 +233,6 @@ export class NotificationService { .__getWindow(notification) .then(browserWindow => { browserWindow.setPosition(nextPosition.x, nextPosition.y); - __this.__activated.push({ - notification, - browserWindow, - }); - const displayTime = !!notification.displayTime ? notification.displayTime : !!__this.__defaultOptions.displayTime @@ -243,6 +247,14 @@ export class NotificationService { const onCloseFncGraceful = __this.__onCloseFnc4Graceful( onCloseFnc ); + __this.__activated.push({ + notification, + browserWindow, + callbacks: { + onCloseFunc: onCloseFncGraceful, + }, + }); + timeoutId = setTimeout(() => { if (browserWindow.isDestroyed()) { return; @@ -352,7 +364,7 @@ export class NotificationService { private __onCloseFnc4Graceful(onClose: OnClose4NotificationWindow) { const __this = this; - return (reason: any): void => { + return (reason?: any): void => { if (!reason) { reason = 'closedGracefully'; } @@ -505,12 +517,12 @@ export class NotificationService { return 'data:text/html,' + encodeURIComponent(html); }; - if (!!notification.template.filePath) { - return filePath2Url(notification.template.filePath); + if (!!notification.template?.filePath) { + return filePath2Url(notification.template?.filePath); } - if (!!notification.template.html) { - return html2Url(notification.template.html); + if (!!notification.template?.html) { + return html2Url(notification.template?.html); } if (!!this.__defaultOptions.template.filePath) {