Skip to content

Commit

Permalink
SDA-4675 - Debounce hide notification (#2205)
Browse files Browse the repository at this point in the history
* SDA-4675 - Debounce hide notification

* SDA-4675 - Add sequential function queue for showing notification

* SDA-4675 - Add delay for notification position animation

* SDA-4675 - Remove move top

* SDA-4675 - Revert delay
  • Loading branch information
KiranNiranjan authored Oct 2, 2024
1 parent c8508aa commit d702a55
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 20 deletions.
64 changes: 64 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 19 additions & 17 deletions src/renderer/notification-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export default class NotificationHandler {
if (window && !window.isDestroyed()) {
try {
window.setPosition(parseInt(String(x), 10), parseInt(String(y), 10));
window.moveTop();
} catch (err) {
console.warn(
`Failed to set window position. x: ${x} y: ${y}. Contact the developers for more details`,
Expand Down Expand Up @@ -429,26 +428,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
3 changes: 0 additions & 3 deletions src/renderer/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ class Notification extends NotificationHandler {
notificationSettings.height,
true,
);
// Move notification to top
notificationWindow.moveTop();

if (!data.sticky) {
timeoutId = setTimeout(async () => {
Expand Down Expand Up @@ -590,7 +588,6 @@ class Notification extends NotificationHandler {
windowId: notificationWindow.id,
});
this.activeNotifications.push(notificationWindow);
notificationWindow.moveTop();
}

/**
Expand Down

0 comments on commit d702a55

Please sign in to comment.