angular-patternfly icon indicating copy to clipboard operation
angular-patternfly copied to clipboard

RFE: Start Toast Notification timeout when page is focused

Open vkrizan opened this issue 8 years ago • 5 comments

Notifications service allows to set a delay for a Toast notifications with NotificationsProvider.setDelay(int). However, if a notification comes when a user switches to other tab/window (blur), the user may miss the notification when the timeout is reached.

Notification service could start the timeout (for auto-close) when user focuses to the page/window. Until then, all non-persistent notifications will stack up.

vkrizan avatar Apr 03 '17 15:04 vkrizan

This seems to be harder to do than it sounds. And here is why:

Browsers do not have API that would tell you whether the window is focused or not. You have to register blur and focus events, and keep the state in a variable. But you still have to assume the initial state, e.g. focused window as default.

As for the notification timeouts, there have to be a system tracking time of unfocused window. And that would have to be for each notification, since it can be created at different time point. Even when the window is focused. The timeout set on a created notification can fire when the window is not focused, therefore it has to be renewed. The question would be for how much of a delay (you cannot predict time of next window focus). The only viable, solution that I think would work, is to have ticks (e.g. every second) and handle all opened notifications. But still there is a danger of reliability.

How I've solved it, is that (successful) messages are made persistent only, when the window is not focused. Focused window is assumed as initial state.

Feel free to close this issue.

vkrizan avatar Apr 25 '18 16:04 vkrizan

Hi @vkrizan, thanks for working on this. It sounds like we would need a NotificationManager that could keep track of all toast notifications and associate a notification with a viewId to determine when it is in focus to start the countdown. Would another possibility be to have toast notifications appear 'always on top', regardless of which window/tab is in focus?

dtaylor113 avatar Apr 26 '18 13:04 dtaylor113

NotificationManager sound good.

Would another possibility be to have toast notifications appear 'always on top', regardless of which window/tab is in focus?

I am not sure how 'always on top' would solve different browser tabs/windows opened/focused.

vkrizan avatar Apr 26 '18 13:04 vkrizan

Oh, you are saying different browser tabs/windows, not different views/navigation-areas/pages of a SPA.

dtaylor113 avatar Apr 26 '18 15:04 dtaylor113

Oh, you are saying different browser tabs/windows, not different views/navigation-areas/pages of a SPA.

Yes.

vkrizan avatar Apr 26 '18 16:04 vkrizan