Files
Toju/toju-app/src/app/infrastructure/mobile/adapters/web/web-mobile-app-lifecycle.adapter.ts

21 lines
595 B
TypeScript

import type { MobileAppLifecycleAdapter } from '../../contracts/mobile.contracts';
/** Visibility API fallback for browser runtimes. */
export class WebMobileAppLifecycleAdapter implements MobileAppLifecycleAdapter {
private handler: ((isActive: boolean) => void) | null = null;
async initialize(): Promise<void> {
if (typeof document === 'undefined') {
return;
}
document.addEventListener('visibilitychange', () => {
this.handler?.(!document.hidden);
});
}
onAppStateChange(handler: (isActive: boolean) => void): void {
this.handler = handler;
}
}