feat: Android APP V1 - Experimental Alpha
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
|
||||
import type { MobileAppLifecycleAdapter } from '../contracts/mobile.contracts';
|
||||
import { CapacitorMobileAppLifecycleAdapter } from '../adapters/capacitor/capacitor-mobile-app-lifecycle.adapter';
|
||||
import { WebMobileAppLifecycleAdapter } from '../adapters/web/web-mobile-app-lifecycle.adapter';
|
||||
import { MobilePlatformService } from './mobile-platform.service';
|
||||
|
||||
/** Facade for foreground/background lifecycle events. */
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class MobileAppLifecycleService {
|
||||
private readonly mobilePlatform = inject(MobilePlatformService);
|
||||
private readonly adapter: MobileAppLifecycleAdapter = this.createAdapter();
|
||||
private initialized = false;
|
||||
|
||||
async initialize(): Promise<void> {
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.adapter.initialize();
|
||||
this.mobilePlatform.refreshRuntimeDetection();
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
onAppStateChange(handler: (isActive: boolean) => void): void {
|
||||
this.adapter.onAppStateChange(handler);
|
||||
}
|
||||
|
||||
private createAdapter(): MobileAppLifecycleAdapter {
|
||||
return this.mobilePlatform.isCapacitor()
|
||||
? new CapacitorMobileAppLifecycleAdapter()
|
||||
: new WebMobileAppLifecycleAdapter();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user