mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-13 18:50:29 +03:00
useAppVisibility change hook instead of baking into client root for cleanliness
This commit is contained in:
parent
4123299af5
commit
296a2463da
1 changed files with 1 additions and 32 deletions
|
|
@ -149,7 +149,6 @@ type ClientRootProps = {
|
||||||
export function ClientRoot({ children }: ClientRootProps) {
|
export function ClientRoot({ children }: ClientRootProps) {
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const { baseUrl } = getSecret();
|
const { baseUrl } = getSecret();
|
||||||
const clientConfig = useClientConfig();
|
|
||||||
|
|
||||||
const [loadState, loadMatrix] = useAsyncCallback<MatrixClient, Error, []>(
|
const [loadState, loadMatrix] = useAsyncCallback<MatrixClient, Error, []>(
|
||||||
useCallback(() => initClient(getSecret() as any), [])
|
useCallback(() => initClient(getSecret() as any), [])
|
||||||
|
|
@ -160,6 +159,7 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||||
);
|
);
|
||||||
|
|
||||||
useLogoutListener(mx);
|
useLogoutListener(mx);
|
||||||
|
useAppVisibility(mx);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (loadState.status === AsyncStatus.Idle) {
|
if (loadState.status === AsyncStatus.Idle) {
|
||||||
|
|
@ -173,37 +173,6 @@ 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((state) => {
|
useCallback((state) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue