• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import common from '@ohos.app.ability.common';
2
3export class GlobalContext {
4  private static TAG: string = 'GlobalContext'
5
6  private constructor() {
7  }
8
9  private static instance: GlobalContext
10  private _objects = new Map<string, Object>()
11  private cameraSettingContext: common.UIAbilityContext | undefined = undefined
12
13  public static get(): GlobalContext {
14    if (!Boolean(GlobalContext.instance).valueOf()) {
15      GlobalContext.instance = new GlobalContext()
16    }
17    return GlobalContext.instance
18  }
19
20  getT<T>(value: string): T {
21    return this._objects.get(value) as T
22  }
23
24  setObject(key: string, objectClass: Object): void {
25    this._objects.set(key, objectClass)
26  }
27
28  apply(value: string): void {
29    const func = this._objects.get(value)
30    if (func) {
31      (func as Function)()
32    }
33  }
34
35  public setCameraSettingContext(context: common.UIAbilityContext): void {
36    this.cameraSettingContext = context
37  }
38
39  public getCameraSettingContext(): common.UIAbilityContext | undefined {
40    return this.cameraSettingContext
41  }
42}