mirror of
				https://github.com/cinnyapp/cinny.git
				synced 2025-11-04 14:30: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 { togglePusher } from '../../features/settings/notifications/PushNotifications';
 | 
			
		||||
import { ClientConfig, useClientConfig } from '../../hooks/useClientConfig';
 | 
			
		||||
import { appEvents } from '../../utils/appEvents';
 | 
			
		||||
 | 
			
		||||
function ClientRootLoading() {
 | 
			
		||||
  return (
 | 
			
		||||
| 
						 | 
				
			
			@ -178,17 +179,44 @@ export function ClientRoot({ children }: ClientRootProps) {
 | 
			
		|||
    }
 | 
			
		||||
  }, [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(
 | 
			
		||||
    mx,
 | 
			
		||||
    useCallback(
 | 
			
		||||
      (state) => {
 | 
			
		||||
        if (state === 'PREPARED') {
 | 
			
		||||
          setLoading(false);
 | 
			
		||||
          pushNotificationListener(mx, clientConfig);
 | 
			
		||||
        }
 | 
			
		||||
      },
 | 
			
		||||
      [clientConfig, mx]
 | 
			
		||||
    )
 | 
			
		||||
    useCallback((state) => {
 | 
			
		||||
      if (state === 'PREPARED') {
 | 
			
		||||
        setLoading(false);
 | 
			
		||||
      }
 | 
			
		||||
    }, [])
 | 
			
		||||
  );
 | 
			
		||||
  return (
 | 
			
		||||
    <SpecVersions baseUrl={baseUrl!}>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue