|
@@ -4,10 +4,11 @@
|
|
|
|
|
|
import type common from '@ohos.app.ability.common';
|
|
|
import { WindowHelper } from './utils/WindowHelper';
|
|
|
+import { BusinessError } from '@kit.BasicServicesKit';
|
|
|
|
|
|
declare namespace globalThis {
|
|
|
let _brushEngineContext: common.UIAbilityContext;
|
|
|
- let _uiUIContext: UIContext[];
|
|
|
+ let _uiUIContext: UIContext;
|
|
|
};
|
|
|
|
|
|
export class GlobalContext {
|
|
@@ -17,22 +18,23 @@ export class GlobalContext {
|
|
|
|
|
|
static setContext(context: common.UIAbilityContext): void {
|
|
|
globalThis._brushEngineContext = context;
|
|
|
- WindowHelper.windowClass = context.windowStage.getMainWindowSync()
|
|
|
- }
|
|
|
- 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)
|
|
|
+
|
|
|
+ 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();
|
|
|
+ });
|
|
|
}
|
|
|
- static getUiContext(): UIContext|undefined {
|
|
|
+
|
|
|
+ static getUiContext(): UIContext | undefined {
|
|
|
if (globalThis._uiUIContext === undefined) {
|
|
|
return undefined;
|
|
|
}
|
|
|
- return globalThis._uiUIContext[globalThis._uiUIContext.length-1];
|
|
|
+ return globalThis._uiUIContext;
|
|
|
}
|
|
|
}
|
|
|
|