HarmonyOSBaseLibs/src/main/ets/ContextConfig.ets

39 行
1.1 KiB
Plaintext

2024-09-04 18:19:18 +08:00
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
*/
import type common from '@ohos.app.ability.common';
2024-10-22 19:36:59 +08:00
import { WindowHelper } from './utils/WindowHelper';
2024-09-04 18:19:18 +08:00
declare namespace globalThis {
let _brushEngineContext: common.UIAbilityContext;
let _uiUIContext: UIContext[];
2024-09-04 18:19:18 +08:00
};
export class GlobalContext {
static getContext(): common.UIAbilityContext {
return globalThis._brushEngineContext;
}
static setContext(context: common.UIAbilityContext): void {
globalThis._brushEngineContext = context;
2024-10-22 19:36:59 +08:00
WindowHelper.windowClass = context.windowStage.getMainWindowSync()
2024-09-04 18:19:18 +08:00
}
static pushUIContext(context: UIContext): void {
if (!globalThis._uiUIContext) {
globalThis._uiUIContext = []
}
globalThis._uiUIContext.push(context);
}
static popUIContext(): void {
globalThis._uiUIContext.splice(globalThis._uiUIContext.length-1,1)
}
static getUiContext(): UIContext|undefined {
if (globalThis._uiUIContext === undefined) {
return undefined;
}
return globalThis._uiUIContext[globalThis._uiUIContext.length-1];
}
2024-09-04 18:19:18 +08:00
}