From f585d3b25d1deb8c89cb7782ff8b1c3cc9e26a2d Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Wed, 25 Sep 2024 11:59:42 +0530 Subject: [PATCH] SDA-4675 - Debounce hide notification --- package-lock.json | 64 ++++++++++++++++++++++++++++++++++++ src/renderer/notification.ts | 6 ++++ 2 files changed, 70 insertions(+) diff --git a/package-lock.json b/package-lock.json index b6caf4060..753c817e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "systeminformation": "5.21.7" }, "devDependencies": { + "@electron/fuses": "^1.8.0", "@types/cheerio": "^0.22.22", "@types/enzyme": "^3.10.7", "@types/fs-extra": "^9.0.0", @@ -1331,6 +1332,69 @@ "node": ">= 6" } }, + "node_modules/@electron/fuses": { + "version": "1.8.0", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/@electron/fuses/-/fuses-1.8.0.tgz", + "integrity": "sha512-zx0EIq78WlY/lBb1uXlziZmDZI4ubcCXIMJ4uGjXzZW0nS19TjSPeXPAjzzTmKQlJUZm0SbmZhPKP7tuQ1SsEw==", + "dev": true, + "dependencies": { + "chalk": "^4.1.1", + "fs-extra": "^9.0.1", + "minimist": "^1.2.5" + }, + "bin": { + "electron-fuses": "dist/bin.js" + } + }, + "node_modules/@electron/fuses/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@electron/fuses/node_modules/fs-extra": { + "version": "9.1.0", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/fs-extra/-/fs-extra-9.1.0.tgz", + "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", + "dev": true, + "dependencies": { + "at-least-node": "^1.0.0", + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@electron/fuses/node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/@electron/fuses/node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/@electron/get": { "version": "2.0.2", "dev": true, diff --git a/src/renderer/notification.ts b/src/renderer/notification.ts index 8b5b2f00f..3ea94a310 100644 --- a/src/renderer/notification.ts +++ b/src/renderer/notification.ts @@ -1,4 +1,5 @@ import { app, BrowserWindow, ipcMain } from 'electron'; +import * as debounce from 'lodash.debounce'; import { analytics } from '../app/bi/analytics-handler'; import { @@ -29,6 +30,7 @@ const animationQueue = new AnimationQueue(); const CONTAINER_HEIGHT = 104; // Notification container height const CONTAINER_HEIGHT_WITH_INPUT = 146; // Notification container height including input field const CONTAINER_WIDTH = 363; +const DEBOUNCE_DELAY = 50; interface ICustomBrowserWindow extends Electron.BrowserWindow { winName: string; notificationData: INotificationData; @@ -83,6 +85,10 @@ class Notification extends NotificationHandler { constructor(opts) { super(opts); + this.hideNotification = debounce( + this.hideNotification.bind(this), + DEBOUNCE_DELAY, + ); ipcMain.on('close-notification', (_event, windowId) => { const browserWindow = this.getNotificationWindow(windowId); if (