From aa4ef3a42c2240b22863c64ba972c08fa9b224f3 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 14 Nov 2018 15:50:25 +0100 Subject: [PATCH] only add focus change listener once --- .../parts/notifications/notificationsToasts.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/browser/parts/notifications/notificationsToasts.ts b/src/vs/workbench/browser/parts/notifications/notificationsToasts.ts index bd3e64742eb..a5daf01b9f4 100644 --- a/src/vs/workbench/browser/parts/notifications/notificationsToasts.ts +++ b/src/vs/workbench/browser/parts/notifications/notificationsToasts.ts @@ -211,7 +211,10 @@ export class NotificationsToasts extends Themable { // Install Timers to Purge Notification let purgeTimeoutHandle: any; + let listener: IDisposable; + const hideAfterTimeout = () => { + purgeTimeoutHandle = setTimeout(() => { // If the notification is sticky or prompting and the window does not have @@ -220,11 +223,14 @@ export class NotificationsToasts extends Themable { // could immediately hide the notification because the timeout was triggered // again. if ((item.sticky || item.hasPrompt()) && !this.windowHasFocus) { - disposables.push(this.windowService.onDidChangeFocus(focus => { - if (focus) { - hideAfterTimeout(); - } - })); + if (!listener) { + listener = this.windowService.onDidChangeFocus(focus => { + if (focus) { + hideAfterTimeout(); + } + }); + disposables.push(listener); + } } // Otherwise... @@ -509,4 +515,4 @@ export class NotificationsToasts extends Themable { private isVisible(toast: INotificationToast): boolean { return !!toast.container.parentElement; } -} \ No newline at end of file +}