zerodevx / svelte-toast

Simple elegant toast notifications
https://zerodevx.github.io/svelte-toast/
ISC License
835 stars 49 forks source link

Option to disable the visibilitychange event listener #103

Open ForrestFire0 opened 4 months ago

ForrestFire0 commented 4 months ago

My application is receiving notifications from a server. I push a toast... but if the user leaves the page in the background, the notifications pile up and are excessive when returning. I would like the ability to disable the notification. (Without changing the source code of your library, that is...) The user expects missed notifications to show up in the notification tray but that is another part of the application.

Also, if there is a little snippet of code I could insert in the meantime to my app to get this behavior... that would be great. Maybe modifying the event listeners of document? But since the visibility check is made when the components are created, this would only work for components created when the document is visible.

If you want a pull request I could probably finagle one...

zerodevx commented 4 months ago

Hmm if you add a visiblity check condition before pushing the toast, does that meet your requirements? Like:

if (!document.hidden) toast.push('The Message')
ForrestFire0 commented 4 months ago

This would fix some. The other case is when some notifications come in while the user is looking, but then are paused until the user comes back. In the case where the user gets a message like "robot A disconnected", they see the little blue line ticking down, they might be confused when they come back to the window and see the same notification again. (They might think robot A disconnected a 2nd time)

ForrestFire0 commented 4 months ago

Also, if say "robot A disconnected", the user expects that notification to persist for the 3 seconds it typically does. If they know the robot disconnects, but don't see it because they returned to the app too quickly, that could be confusing.

zerodevx commented 4 months ago

Agree that visibilitychange should be configurable. A setting should be exposed that allows it to be disabled.

I've been waiting for Svelte 5 to land on stable (so I can rewrite the store for performance) but that's taking awhile. I think I'll work on cutting a new release first and add this feature.