import { ANDROID, HTML5, IOS } from 'cc/env'; import type { AppEventMap } from './AppEvents'; import { EventManager } from '../framework/event/EventManager'; import { ResourceManager } from '../framework/resource/ResourceManager'; import { SceneNavigator } from '../framework/scene/SceneNavigator'; 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'; 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 ui(): UIManager { return this.Instance.ui; } static get scenes(): SceneNavigator { return this.Instance.scenes; } 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; } readonly events = new EventManager(); readonly resources = new ResourceManager(); 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; private constructor() { this.platform = this.createPlatformBridge(); } private createPlatformBridge(): PlatformBridge { if (ANDROID) return new AndroidPlatformBridge(); if (IOS) return new IOSPlatformBridge(); return new H5PlatformBridge(); } }