svelte-toast icon indicating copy to clipboard operation
svelte-toast copied to clipboard

Support page visibility API

Open Prinzhorn opened this issue 3 years ago • 4 comments

https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API

Among other things I'm using toasts to display warnings when something didn't work. If you tab out of the browser (or the Electron app in my case) you might miss it.

I don't know how easy this would be to implement. In a perfect world the toasts would pause (progress bar, timers) when document.hidden and continue when it becomes visible again. If that's too complex then an easier approach would be to queue toasts if document.hidden and insert them on visibilitychange.

Oh well, heureka! The pausable feature literally already exists, so it should actually be trivial to pause all toasts when the document becomes invisible. But this should be a separate feature (you might not want pausable via hover but still pause them when the document is invisible). What I'm saying is that the functionality to pause the toast/timers exists and it would just be a second boolean (global, not per toast hover) that triggers it.

Prinzhorn avatar Sep 04 '22 08:09 Prinzhorn

Hey, yes it should be quite trivial to add this feature, especially since the pause() and resume() functions are already there. I kind of think this should be the default behaviour actually - notifications should by nature ensure that they're seen.

Will love a PR on this, else I might take a stab at it soon.

zerodevx avatar Sep 05 '22 07:09 zerodevx

Not sure when I have time for it. If you start working on it please assign the issue to yourself so that we don't both do. I'll comment here when I do.

Prinzhorn avatar Sep 05 '22 08:09 Prinzhorn

I kind of think this should be the default behaviour actually - notifications should by nature ensure that they're seen.

I agree. And it's hardly a breaking change, I don't think anyone actually cared yet or realized that's how it works. So maybe we don't even need an option to turn it off.

Prinzhorn avatar Sep 05 '22 08:09 Prinzhorn

Cool, we'll leave this open for now for tracking - leave a comment when either of us (or anyone else for that matter) starts work on this. Thanks for the suggestion!

zerodevx avatar Sep 05 '22 08:09 zerodevx

I'm working on this!

zerodevx avatar Oct 09 '22 20:10 zerodevx

Nice, ping me for a review when you got the PR up

Prinzhorn avatar Oct 10 '22 08:10 Prinzhorn