bug fixed

This commit is contained in:
crusader 2020-12-02 17:51:39 +09:00
parent cb61da113d
commit d6787baad8

View File

@ -90,7 +90,7 @@ export interface Notification {
'width' 'width'
>; >;
displayTime?: number; displayTime?: number;
template: Template; template?: Template;
data?: any; data?: any;
onShow?: OnShow4NotificationWindow; onShow?: OnShow4NotificationWindow;
onClose?: OnClose4NotificationWindow; onClose?: OnClose4NotificationWindow;
@ -151,6 +151,9 @@ class WindowPooler {
interface Activated { interface Activated {
notification: Notification; notification: Notification;
browserWindow: Electron.BrowserWindow; browserWindow: Electron.BrowserWindow;
callbacks: {
onCloseFunc: (reason?: any) => void;
};
} }
export class NotificationService { 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 { closeAll(): void {
this.__animationQueue.clear();
this.__activated.forEach(a => {
a.browserWindow.close();
});
this.__activated = [];
this.__delayQueue = []; this.__delayQueue = [];
this.__activated.forEach(a => {
a.callbacks.onCloseFunc();
});
this.__closed.clear(); this.__closed.clear();
this.__windowPooler.closeAll(); this.__windowPooler.closeAll();
} }
@ -224,11 +233,6 @@ export class NotificationService {
.__getWindow(notification) .__getWindow(notification)
.then(browserWindow => { .then(browserWindow => {
browserWindow.setPosition(nextPosition.x, nextPosition.y); browserWindow.setPosition(nextPosition.x, nextPosition.y);
__this.__activated.push({
notification,
browserWindow,
});
const displayTime = !!notification.displayTime const displayTime = !!notification.displayTime
? notification.displayTime ? notification.displayTime
: !!__this.__defaultOptions.displayTime : !!__this.__defaultOptions.displayTime
@ -243,6 +247,14 @@ export class NotificationService {
const onCloseFncGraceful = __this.__onCloseFnc4Graceful( const onCloseFncGraceful = __this.__onCloseFnc4Graceful(
onCloseFnc onCloseFnc
); );
__this.__activated.push({
notification,
browserWindow,
callbacks: {
onCloseFunc: onCloseFncGraceful,
},
});
timeoutId = setTimeout(() => { timeoutId = setTimeout(() => {
if (browserWindow.isDestroyed()) { if (browserWindow.isDestroyed()) {
return; return;
@ -352,7 +364,7 @@ export class NotificationService {
private __onCloseFnc4Graceful(onClose: OnClose4NotificationWindow) { private __onCloseFnc4Graceful(onClose: OnClose4NotificationWindow) {
const __this = this; const __this = this;
return (reason: any): void => { return (reason?: any): void => {
if (!reason) { if (!reason) {
reason = 'closedGracefully'; reason = 'closedGracefully';
} }
@ -505,12 +517,12 @@ export class NotificationService {
return 'data:text/html,' + encodeURIComponent(html); return 'data:text/html,' + encodeURIComponent(html);
}; };
if (!!notification.template.filePath) { if (!!notification.template?.filePath) {
return filePath2Url(notification.template.filePath); return filePath2Url(notification.template?.filePath);
} }
if (!!notification.template.html) { if (!!notification.template?.html) {
return html2Url(notification.template.html); return html2Url(notification.template?.html);
} }
if (!!this.__defaultOptions.template.filePath) { if (!!this.__defaultOptions.template.filePath) {