import { ANDROID, IOS } from 'cc/env'; import type { AppEventMap } from './AppEvents'; import { EventManager } from '../framework/event/EventManager'; import { ResourceManager } from '../framework/resource/ResourceManager'; import { RedpointManager } from '../framework/redpoint/RedpointManager'; import { SceneNavigator } from '../framework/scene/SceneNavigator'; import { SoundManager } from '../framework/sound/SoundManager'; import { UIManager } from '../framework/ui/UIManager'; import { AndroidPlatformBridge } from '../platform/AndroidPlatformBridge'; import { H5PlatformBridge } from '../platform/H5PlatformBridge'; import { IOSPlatformBridge } from '../platform/IOSPlatformBridge'; import { PlatformBridge } from '../platform/PlatformBridge'; import { HotUpdateService } from '../services/hotupdate/HotUpdateService'; import { VersionService } from '../services/version/VersionService'; import * as stores from '../store'; import * as services from '../services'; import fb from '@scripts/platform/FaceBook/Facebook'; import google from '@scripts/platform/Google/Google'; import iosAuth from '@scripts/platform/IOS/IOSAuth'; import iap from '@scripts/platform/IAP/IAP'; import * as i18n from '../i18n'; export class AppKernel { private static instance: AppKernel | null = null; static initialize(): AppKernel { if (!this.instance) { this.instance = new AppKernel(); } return this.instance; } static get Instance(): AppKernel { if (!this.instance) throw new Error('AppKernel has not been initialized'); return this.instance; } static get events(): EventManager { return this.Instance.events; } static get resources(): ResourceManager { return this.Instance.resources; } static get redpoint(): RedpointManager { return this.Instance.redpoint; } static get ui(): UIManager { return this.Instance.ui; } static get scenes(): SceneNavigator { return this.Instance.scenes; } static get sound(): SoundManager { return this.Instance.sound; } static get version(): VersionService { return this.Instance.version; } static get hotUpdate(): HotUpdateService { return this.Instance.hotUpdate; } static get platform(): PlatformBridge { return this.Instance.platform; } static get stores(): typeof stores { return this.Instance.stores; } static get services(): typeof services { return this.Instance.services; } static get appLobby(): typeof services.appLobby { return this.services.appLobby; } static get fb(): typeof fb { return this.Instance.fb; } static get google(): typeof google { return this.Instance.google; } static get i18n(): typeof i18n { return i18n; } static get iap(): typeof iap { return iap; } static get iosAuth(): typeof iosAuth { return iosAuth; } readonly events = new EventManager(); readonly redpoint = new RedpointManager(); readonly resources = new ResourceManager(); readonly sound = new SoundManager(this.resources); readonly ui = new UIManager(this.resources); readonly scenes = new SceneNavigator(this.resources); readonly version = new VersionService(); readonly hotUpdate = new HotUpdateService(); readonly platform: PlatformBridge; readonly stores = stores; readonly services = services; readonly fb = fb; readonly google = google; readonly i18n = i18n; readonly iap = iap; readonly iosAuth = iosAuth; private constructor() { this.platform = this.createPlatformBridge(); if (IOS && this.platform instanceof IOSPlatformBridge) { this.platform.requestTrackingAuthorization(); } this.fb.init(); this.google.init(); } private createPlatformBridge(): PlatformBridge { if (ANDROID) return new AndroidPlatformBridge(); if (IOS) return new IOSPlatformBridge(); return new H5PlatformBridge(); } }