Skip to content

Commit

Permalink
SDA-4675 - Add delay for notification position animation
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranNiranjan committed Sep 30, 2024
1 parent 01272a3 commit 635a70d
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/renderer/notification-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 635a70d

Please sign in to comment.