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';
|
2025-05-12 12:21:16 +08:00
|
|
|
import { BusinessError } from '@kit.BasicServicesKit';
|
2024-09-04 18:19:18 +08:00
|
|
|
|
|
|
|
|
declare namespace globalThis {
|
|
|
|
|
let _brushEngineContext: common.UIAbilityContext;
|
2025-05-12 12:21:16 +08:00
|
|
|
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;
|
2025-05-12 12:21:16 +08:00
|
|
|
|
|
|
|
|
context.windowStage.getMainWindow((err: BusinessError, data) => {
|
|
|
|
|
let errCode: number = err.code;
|
|
|
|
|
if (errCode) {
|
|
|
|
|
console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
WindowHelper.windowClass = data;
|
|
|
|
|
globalThis._uiUIContext = WindowHelper.windowClass.getUIContext();
|
|
|
|
|
});
|
2025-04-10 19:46:57 +08:00
|
|
|
}
|
2025-05-12 12:21:16 +08:00
|
|
|
|
|
|
|
|
static getUiContext(): UIContext | undefined {
|
2025-04-29 18:03:54 +08:00
|
|
|
if (globalThis._uiUIContext === undefined) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
2025-05-12 12:21:16 +08:00
|
|
|
return globalThis._uiUIContext;
|
2025-04-10 19:46:57 +08:00
|
|
|
}
|
2024-09-04 18:19:18 +08:00
|
|
|
}
|
|
|
|
|
|