1/** 2 * @file Describe the file 3 * Copyright (c) 2023 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import common from '@ohos.app.ability.common'; 18 19export class GlobalThis { 20 private static ins: GlobalThis; 21 UiAbilityContext: common.UIAbilityContext | null = null; 22 ExtensionContext: common.ExtensionContext | null = null; 23 24 private constructor() { 25 } 26 27 public static getInstance(): GlobalThis { 28 if (!GlobalThis.ins) { 29 GlobalThis.ins = new GlobalThis(); 30 } 31 return GlobalThis.ins; 32 } 33 34 public static getUiAbilityContext(): common.UIAbilityContext | null { 35 return GlobalThis.getInstance().UiAbilityContext; 36 } 37 38 public static setUiAbilityContext(UiAbilityContext: common.UIAbilityContext): void { 39 GlobalThis.getInstance().UiAbilityContext = UiAbilityContext; 40 } 41 42 public static getExtensionContext(): common.ExtensionContext | null { 43 return GlobalThis.getInstance().ExtensionContext; 44 } 45 46 public static setExtensionContext(ExtensionContext: common.ExtensionContext): void { 47 GlobalThis.getInstance().ExtensionContext = ExtensionContext; 48 } 49}