fix(ui): improve visibility condition and push notification handling (#199)

Resolve visibility state for beacon reporting to handle focus correctly
Normalize push subscriptions per UI session and send to each endpoint
Suppress push notifications when a visible window exists to avoid redundant alerts
This commit is contained in:
Bohdan Triapitsyn
2026-01-23 01:51:22 +02:00
committed by GitHub
parent 51922d7b23
commit 71b9ec6e3d
3 changed files with 77 additions and 75 deletions
@@ -4,6 +4,12 @@ import { getRegisteredRuntimeAPIs } from '@/contexts/runtimeAPIRegistry';
const HEARTBEAT_MS = 10000;
const resolveVisibilityState = (): 'visible' | 'hidden' => {
if (typeof document === 'undefined') return 'visible';
const state = document.visibilityState;
return state === 'hidden' && document.hasFocus() ? 'visible' : state;
};
const sendVisibility = (visible: boolean) => {
if (!isWebRuntime()) {
return;
@@ -24,11 +30,11 @@ export const usePushVisibilityBeacon = () => {
}
const report = () => {
sendVisibility(document.visibilityState === 'visible');
sendVisibility(resolveVisibilityState() === 'visible');
};
const reportVisibleOnly = () => {
if (document.visibilityState === 'visible') {
if (resolveVisibilityState() === 'visible') {
sendVisibility(true);
}
};