• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16export class GlobalContext {
17  currentPermissionGroup: string;
18  isVertical: boolean;
19  bundleName: string;
20  windowNum: number;
21  dialogSet: Set<String>;
22
23  public static getContext(): GlobalContext {
24    if (!GlobalContext.instance) {
25      GlobalContext.instance = new GlobalContext();
26    }
27    return GlobalContext.instance;
28  }
29
30  private constructor() {}
31  private static instance: GlobalContext;
32  private _objects = new Map<string, Object>();
33
34  static load(name: string): any {
35    return globalThis[name];
36  }
37
38  static store(name: string, obj: Object): void {
39    globalThis[name] = obj;
40  }
41
42  get(value: string): Object {
43    return this._objects.get(value);
44  }
45
46  set(key: string, objectClass: Object): void {
47    this._objects.set(key, objectClass);
48  }
49
50  public getWindowNum(): number {
51    return globalThis.windowNum || 0;
52  }
53
54  public increaseAndGetWindowNum(): number {
55    globalThis.windowNum ++;
56    return globalThis.windowNum;
57  }
58
59  public decreaseAndGetWindowNum(): number {
60    globalThis.windowNum --;
61    return globalThis.windowNum;
62  }
63
64  public setAndGetWindowNum(num: number): number {
65    globalThis.windowNum = num;
66    return globalThis.windowNum || 0;
67  }
68}