| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- 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<AppEventMap> {
- 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<AppEventMap>();
- 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();
- }
- }
|