From 635a70d8c99c5eadd1186849bede1dcbb40f70b0 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Mon, 30 Sep 2024 09:29:34 +0530 Subject: [PATCH] SDA-4675 - Add delay for notification position animation --- src/renderer/notification-handler.ts | 35 +++++++++++++++------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/renderer/notification-handler.ts b/src/renderer/notification-handler.ts index 58fa9c605..962b8f29c 100644 --- a/src/renderer/notification-handler.ts +++ b/src/renderer/notification-handler.ts @@ -429,26 +429,29 @@ export default class NotificationHandler { newX: number, ) { const [startX, startY] = notificationWindow.getPosition(); - const stepY = (newY - startY) / this.settings.animationSteps; - const stepX = (newX - startX) / this.settings.animationSteps; + const duration = this.settings.animationSteps; + const startTime = Date.now(); - let curStep = 1; - const animationInterval = setInterval(() => { - // Abort condition - if (curStep === this.settings.animationSteps) { + const animateStep = () => { + const elapsed = Date.now() - startTime; + const progress = Math.min(elapsed / duration, 1); + + const currentX = startX + (newX - startX) * progress; + const currentY = startY + (newY - startY) * progress; + + // Set new position + this.setWindowPosition(notificationWindow, currentX, currentY); + + if (progress < 1) { + setTimeout(animateStep, 16); + } else { + // Ensure final position is set this.setWindowPosition(notificationWindow, newX, newY); - clearInterval(animationInterval); - return; } + }; - // Move one step in both x and y directions - this.setWindowPosition( - notificationWindow, - startX + curStep * stepX, - startY + curStep * stepY, - ); - curStep++; - }, this.settings.animationStepMs); + // Start the animation + setTimeout(animateStep, 16); } /**