mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-04 22:40:29 +03:00
Swap our visibility handler and notification implementation to use the global app events
This commit is contained in:
parent
2861ccdc46
commit
ff7c40ec85
1 changed files with 37 additions and 9 deletions
|
|
@ -39,6 +39,7 @@ import { stopPropagation } from '../../utils/keyboard';
|
||||||
import { SyncStatus } from './SyncStatus';
|
import { SyncStatus } from './SyncStatus';
|
||||||
import { togglePusher } from '../../features/settings/notifications/PushNotifications';
|
import { togglePusher } from '../../features/settings/notifications/PushNotifications';
|
||||||
import { ClientConfig, useClientConfig } from '../../hooks/useClientConfig';
|
import { ClientConfig, useClientConfig } from '../../hooks/useClientConfig';
|
||||||
|
import { appEvents } from '../../utils/appEvents';
|
||||||
|
|
||||||
function ClientRootLoading() {
|
function ClientRootLoading() {
|
||||||
return (
|
return (
|
||||||
|
|
@ -178,17 +179,44 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||||
}
|
}
|
||||||
}, [mx, startMatrix]);
|
}, [mx, startMatrix]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleVisibilityChange = () => {
|
||||||
|
const isVisible = document.visibilityState === 'visible';
|
||||||
|
appEvents.onVisibilityChange?.(isVisible);
|
||||||
|
if (!isVisible) {
|
||||||
|
appEvents.onVisibilityHidden?.();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('visibilitychange', handleVisibilityChange);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!mx) return;
|
||||||
|
|
||||||
|
const handleVisibilityForNotifications = (isVisible: boolean) => {
|
||||||
|
togglePusher(mx, clientConfig, isVisible);
|
||||||
|
};
|
||||||
|
|
||||||
|
appEvents.onVisibilityChange = handleVisibilityForNotifications;
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
appEvents.onVisibilityChange = null;
|
||||||
|
};
|
||||||
|
}, [mx, clientConfig]);
|
||||||
|
|
||||||
useSyncState(
|
useSyncState(
|
||||||
mx,
|
mx,
|
||||||
useCallback(
|
useCallback((state) => {
|
||||||
(state) => {
|
if (state === 'PREPARED') {
|
||||||
if (state === 'PREPARED') {
|
setLoading(false);
|
||||||
setLoading(false);
|
}
|
||||||
pushNotificationListener(mx, clientConfig);
|
}, [])
|
||||||
}
|
|
||||||
},
|
|
||||||
[clientConfig, mx]
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<SpecVersions baseUrl={baseUrl!}>
|
<SpecVersions baseUrl={baseUrl!}>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue