feat: Add deafen to pc, fix mobiel view, fix freeze on startup
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
|
||||
import { resolveMobileAdapter } from '../logic/mobile-capacitor-adapter.rules';
|
||||
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';
|
||||
|
||||
@@ -9,7 +9,8 @@ import { MobilePlatformService } from './mobile-platform.service';
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class MobileAppLifecycleService {
|
||||
private readonly mobilePlatform = inject(MobilePlatformService);
|
||||
private readonly adapter: MobileAppLifecycleAdapter = this.createAdapter();
|
||||
private adapter: MobileAppLifecycleAdapter = new WebMobileAppLifecycleAdapter();
|
||||
private adapterReady: Promise<MobileAppLifecycleAdapter> | null = null;
|
||||
private initialized = false;
|
||||
|
||||
async initialize(): Promise<void> {
|
||||
@@ -17,7 +18,9 @@ export class MobileAppLifecycleService {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.adapter.initialize();
|
||||
const adapter = await this.ensureAdapter();
|
||||
|
||||
await adapter.initialize();
|
||||
this.mobilePlatform.refreshRuntimeDetection();
|
||||
this.initialized = true;
|
||||
}
|
||||
@@ -26,9 +29,22 @@ export class MobileAppLifecycleService {
|
||||
this.adapter.onAppStateChange(handler);
|
||||
}
|
||||
|
||||
private createAdapter(): MobileAppLifecycleAdapter {
|
||||
return this.mobilePlatform.isCapacitor()
|
||||
? new CapacitorMobileAppLifecycleAdapter()
|
||||
: new WebMobileAppLifecycleAdapter();
|
||||
private ensureAdapter(): Promise<MobileAppLifecycleAdapter> {
|
||||
if (!this.adapterReady) {
|
||||
this.adapterReady = resolveMobileAdapter(
|
||||
this.mobilePlatform.runtime(),
|
||||
this.adapter,
|
||||
async () => {
|
||||
const { CapacitorMobileAppLifecycleAdapter } = await import('../adapters/capacitor/capacitor-mobile-app-lifecycle.adapter');
|
||||
|
||||
return new CapacitorMobileAppLifecycleAdapter();
|
||||
}
|
||||
).then((adapter) => {
|
||||
this.adapter = adapter;
|
||||
return adapter;
|
||||
});
|
||||
}
|
||||
|
||||
return this.adapterReady;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user