diff --git a/zh-cn/application-dev/reference/apis/js-apis-application-windowExtensionAbility.md b/zh-cn/application-dev/reference/apis/js-apis-application-windowExtensionAbility.md
index a977546199a950cafb414d64a6fad24a5713480d..f26f7ed912fc87047d0e6c6488954bcedd18608a 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-application-windowExtensionAbility.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-application-windowExtensionAbility.md
@@ -41,12 +41,13 @@ onConnect(want: Want): void
**示例:**
```ts
-export default class MyWindowExtensionAbility extends WindowExtensionAbility {
+import WindowExtensionAbility from '@ohos.application.WindowExtensionAbility';
+import Want from '@ohos.app.ability.Want';
- onConnect(want) {
+export default class MyWindowExtensionAbility extends WindowExtensionAbility {
+ onConnect(want: Want) {
console.info('WindowExtAbility onConnect, abilityName: ${want.abilityName}');
}
-
}
```
@@ -68,12 +69,13 @@ onDisconnect(want: Want): void
**示例:**
```ts
-export default class MyWindowExtensionAbility extends WindowExtensionAbility {
+import WindowExtensionAbility from '@ohos.application.WindowExtensionAbility';
+import Want from '@ohos.app.ability.Want';
- onDisconnect(want) {
+export default class MyWindowExtensionAbility extends WindowExtensionAbility {
+ onDisconnect(want: Want) {
console.info('WindowExtAbility onDisconnect, abilityName: ${want.abilityName}');
}
-
}
```
@@ -95,16 +97,20 @@ onWindowReady(window: window.Window): void
**示例:**
```ts
+import WindowExtensionAbility from '@ohos.application.WindowExtensionAbility';
+import window from '@ohos.window';
+
+let windowStage: window.WindowStage | null = null
+
export default class MyWindowExtensionAbility extends WindowExtensionAbility {
+ onWindowReady(windowClass: window.Window) {
- onWindowReady(window) {
- window.loadContent('WindowExtAbility/pages/index1').then(() => {
- window.getProperties().then((pro) => {
+ windowStage!.loadContent('WindowExtAbility/pages/index1').then(() => {
+ windowClass.getProperties().then((pro: window.WindowProperties) => {
console.log('WindowExtension pro: ${JSON.stringify(pro)}');
});
- window.show();
+ windowClass.show();
});
}
-
}
```
\ No newline at end of file
diff --git a/zh-cn/application-dev/reference/apis/js-apis-window.md b/zh-cn/application-dev/reference/apis/js-apis-window.md
index 5f38585a1c35fc7235379801e5b2f9769ca9e28a..de3acbbf06b129c20b5aecb5fcde07db987dc321 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-window.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-window.md
@@ -2652,27 +2652,33 @@ getUIContext(): UIContext
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
+import { BusinessError } from '@ohos.base';
+import { UIContext } from '@ohos.arkui.UIContext';
export default class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage) {
+ onWindowStageCreate(windowStage: window.WindowStage) {
// 为主窗口加载对应的目标页面。
- windowStage.loadContent("pages/page2", (err) => {
- if (err.code) {
+ windowStage.loadContent("pages/page2", (err: BusinessError) => {
+ let errCode: number = err.code;
+ if (errCode) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content.');
// 获取应用主窗口。
- let windowClass = null;
- windowStage.getMainWindow((err, data) => {
- if (err.code) {
+ let windowClass: window.Window | null = null;
+ windowStage.getMainWindow((err: BusinessError, data) => {
+ let errCode: number = err.code;
+ if (errCode) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
// 获取UIContext实例。
- globalThis.uiContext = windowClass.getUIContext();
+ let uiContext: UIContext | null = null;
+ uiContext = windowClass.getUIContext();
})
});
}
@@ -2793,20 +2799,37 @@ loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void
**示例:**
```ts
-let storage = new LocalStorage();
-storage.setOrCreate('storageSimpleProp',121);
-console.log('onWindowStageCreate');
-try {
- windowClass.loadContent('pages/page2', storage, (err) => {
- if (err.code) {
+import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
+import { BusinessError } from '@ohos.base';
+
+export default class EntryAbility extends UIAbility {
+ // ...
+
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ let windowClass: window.Window | null = null;
+ let storage: LocalStorage = new LocalStorage();
+ storage.setOrCreate('storageSimpleProp', 121);
+ try {
+ if (!windowClass) {
+ console.info('Failed to load the content. Cause: windowClass is null');
+ }
+ else {
+ (windowClass as window.Window).loadContent('pages/page2', storage, (err: BusinessError) => {
+ const errCode: number = err.code;
+ if (errCode) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
- }
- console.info('Succeeded in loading the content.');
- });
-} catch (exception) {
- console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
-}
+ }
+ console.info('Succeeded in loading the content.');
+ });
+ }
+ } catch (exception) {
+ console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
+ }
+ }
+};
```
### loadContent9+
@@ -2844,19 +2867,35 @@ loadContent(path: string, storage: LocalStorage): Promise<void>
**示例:**
```ts
-let storage = new LocalStorage();
-storage.setOrCreate('storageSimpleProp',121);
-console.log('onWindowStageCreate');
-try {
- let promise = windowClass.loadContent('pages/page2', storage);
- promise.then(() => {
- console.info('Succeeded in loading the content.');
- }).catch((err) => {
- console.error('Failed to load the content. Cause:' + JSON.stringify(err));
- });
-} catch (exception) {
- console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
-}
+import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
+import { BusinessError } from '@ohos.base';
+
+export default class EntryAbility extends UIAbility {
+ // ...
+
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ let windowClass: window.Window | null = null;
+ let storage: LocalStorage = new LocalStorage();
+ storage.setOrCreate('storageSimpleProp', 121);
+ try {
+ if (!windowClass) {
+ console.info('Failed to load the content. Cause: windowClass is null');
+ }
+ else {
+ let promise = (windowClass as window.Window).loadContent('pages/page2', storage);
+ promise.then(() => {
+ console.info('Succeeded in loading the content.');
+ }).catch((err: BusinessError) => {
+ console.error('Failed to load the content. Cause:' + JSON.stringify(err));
+ });
+ }
+ } catch (exception) {
+ console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
+ }
+ }
+};
```
### isWindowShowing9+
@@ -6893,22 +6932,25 @@ getMainWindow(callback: AsyncCallback<Window>): void
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
+import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility {
- // ...
-
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = null;
- windowStage.getMainWindow((err, data) => {
- if (err.code) {
- console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
- });
- }
+ // ...
+
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ let windowClass: window.Window | null = null;
+ windowStage.getMainWindow((err: BusinessError, data) => {
+ const errCode: number = err.code;
+ if (errCode) {
+ console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
+ return;
+ }
+ windowClass = data;
+ console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
+ });
+ }
};
```
@@ -6941,21 +6983,23 @@ getMainWindow(): Promise<Window>
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
+import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility {
- // ...
-
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = null;
- let promise = windowStage.getMainWindow();
- promise.then((data) => {
- windowClass = data;
- console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
- }).catch((err) => {
- console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
- });
- }
+ // ...
+
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ let windowClass: window.Window | null = null;
+ let promise = windowStage.getMainWindow();
+ promise.then((data) => {
+ windowClass = data;
+ console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
+ }).catch((err: BusinessError) => {
+ console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
+ });
+ }
};
```
@@ -6988,18 +7032,19 @@ getMainWindowSync(): Window
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
- // ...
+ // ...
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- try {
- let windowClass = windowStage.getMainWindowSync();
- } catch (exception) {
- console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(exception));
- };
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ try {
+ let windowClass = windowStage.getMainWindowSync();
+ } catch (exception) {
+ console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(exception));
}
+ }
};
```
@@ -7033,27 +7078,30 @@ createSubWindow(name: string, callback: AsyncCallback<Window>): void
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
+import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility {
- // ...
+ // ...
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = null;
- try {
- windowStage.createSubWindow('mySubWindow', (err, data) => {
- if (err.code) {
- console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
- windowClass.resetSize(500, 1000);
- });
- } catch (exception) {
- console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception));
- };
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ let windowClass: window.Window | null = null;
+ try {
+ windowStage.createSubWindow('mySubWindow', (err: BusinessError, data) => {
+ const errCode: number = err.code;
+ if (errCode) {
+ console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
+ return;
+ }
+ windowClass = data;
+ console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
+ windowClass.resetSize(500, 1000);
+ });
+ } catch (exception) {
+ console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception));
}
+ }
};
```
### createSubWindow9+
@@ -7091,25 +7139,27 @@ createSubWindow(name: string): Promise<Window>
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
+import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility {
- // ...
+ // ...
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = null;
- try {
- let promise = windowStage.createSubWindow('mySubWindow');
- promise.then((data) => {
- windowClass = data;
- console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
- }).catch((err) => {
- console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
- });
- } catch (exception) {
- console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception));
- };
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ let windowClass: window.Window | null = null;
+ try {
+ let promise = windowStage.createSubWindow('mySubWindow');
+ promise.then((data) => {
+ windowClass = data;
+ console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
+ }).catch((err: BusinessError) => {
+ console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
+ });
+ } catch (exception) {
+ console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception));
}
+ }
};
```
@@ -7141,22 +7191,25 @@ getSubWindow(callback: AsyncCallback<Array<Window>>): void
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
+import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility {
- // ...
-
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = null;
- windowStage.getSubWindow((err, data) => {
- if (err.code) {
- console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err));
- return;
- }
- windowClass = data;
- console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
- });
- }
+ // ...
+
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ let windowClass: window.Window[] = [];
+ windowStage.getSubWindow((err: BusinessError, data) => {
+ const errCode: number = err.code;
+ if (errCode) {
+ console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err));
+ return;
+ }
+ windowClass = data;
+ console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
+ });
+ }
};
```
### getSubWindow9+
@@ -7187,21 +7240,23 @@ getSubWindow(): Promise<Array<Window>>
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
+import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility {
- // ...
-
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- let windowClass = null;
- let promise = windowStage.getSubWindow();
- promise.then((data) => {
- windowClass = data;
- console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
- }).catch((err) => {
- console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err));
- })
- }
+ // ...
+
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ let windowClass: window.Window[] = [];
+ let promise = windowStage.getSubWindow();
+ promise.then((data) => {
+ windowClass = data;
+ console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data));
+ }).catch((err: BusinessError) => {
+ console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err));
+ })
+ }
};
```
### loadContent9+
@@ -7235,27 +7290,30 @@ loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
+import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility {
- // ...
+ // ...
- storage : LocalStorage
- onWindowStageCreate(windowStage) {
- this.storage = new LocalStorage();
- this.storage.setOrCreate('storageSimpleProp',121);
- console.log('onWindowStageCreate');
- try {
- windowStage.loadContent('pages/page2',this.storage,(err) => {
- if (err.code) {
- console.error('Failed to load the content. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in loading the content.');
- });
- } catch (exception) {
- console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
- };
+ storage: LocalStorage = new LocalStorage();
+
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ this.storage.setOrCreate('storageSimpleProp', 121);
+ console.log('onWindowStageCreate');
+ try {
+ windowStage.loadContent('pages/page2', this.storage, (err: BusinessError) => {
+ const errCode: number = err.code;
+ if (errCode) {
+ console.error('Failed to load the content. Cause:' + JSON.stringify(err));
+ return;
+ }
+ console.info('Succeeded in loading the content.');
+ });
+ } catch (exception) {
+ console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
}
+ }
};
```
@@ -7295,26 +7353,29 @@ loadContent(path: string, storage?: LocalStorage): Promise<void>
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
+import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility {
- // ...
+ // ...
- storage : LocalStorage
- onWindowStageCreate(windowStage) {
- this.storage = new LocalStorage();
- this.storage.setOrCreate('storageSimpleProp',121);
- console.log('onWindowStageCreate');
- try {
- let promise = windowStage.loadContent('pages/page2',this.storage);
- promise.then(() => {
- console.info('Succeeded in loading the content.');
- }).catch((err) => {
- console.error('Failed to load the content. Cause:' + JSON.stringify(err));
- });
- } catch (exception) {
- console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
- };
+ storage: LocalStorage = new LocalStorage();
+
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ this.storage.setOrCreate('storageSimpleProp', 121);
+ console.log('onWindowStageCreate');
+ try {
+ let promise = windowStage.loadContent('pages/page2', this.storage);
+ promise.then(() => {
+ console.info('Succeeded in loading the content.');
+ }).catch((err: BusinessError) => {
+ console.error('Failed to load the content. Cause:' + JSON.stringify(err));
+ });
+ } catch (exception) {
+ console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
}
+ ;
+ }
};
```
@@ -7348,24 +7409,27 @@ loadContent(path: string, callback: AsyncCallback<void>): void
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
+import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility {
- // ...
+ // ...
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- try {
- windowStage.loadContent('pages/page2', (err) => {
- if (err.code) {
- console.error('Failed to load the content. Cause:' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in loading the content.');
- });
- } catch (exception) {
- console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
- };
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ try {
+ windowStage.loadContent('pages/page2', (err: BusinessError) => {
+ const errCode: number = err.code;
+ if (errCode) {
+ console.error('Failed to load the content. Cause:' + JSON.stringify(err));
+ return;
+ }
+ console.info('Succeeded in loading the content.');
+ });
+ } catch (exception) {
+ console.error('Failed to load the content. Cause:' + JSON.stringify(exception));
}
+ }
};
```
@@ -7399,22 +7463,23 @@ on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
- // ...
+ // ...
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- try {
- windowStage.on('windowStageEvent', (data) => {
- console.info('Succeeded in enabling the listener for window stage event changes. Data: ' +
- JSON.stringify(data));
- });
- } catch (exception) {
- console.error('Failed to enable the listener for window stage event changes. Cause:' +
- JSON.stringify(exception));
- };
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ try {
+ windowStage.on('windowStageEvent', (data) => {
+ console.info('Succeeded in enabling the listener for window stage event changes. Data: ' +
+ JSON.stringify(data));
+ });
+ } catch (exception) {
+ console.error('Failed to enable the listener for window stage event changes. Cause:' +
+ JSON.stringify(exception));
}
+ }
};
```
@@ -7448,19 +7513,20 @@ off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType&g
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
- // ...
+ // ...
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- try {
- windowStage.off('windowStageEvent');
- } catch (exception) {
- console.error('Failed to disable the listener for window stage event changes. Cause:' +
- JSON.stringify(exception));
- };
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ try {
+ windowStage.off('windowStageEvent');
+ } catch (exception) {
+ console.error('Failed to disable the listener for window stage event changes. Cause:' +
+ JSON.stringify(exception));
}
+ }
};
```
@@ -7489,14 +7555,15 @@ disableWindowDecor(): void
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
- // ...
+ // ...
- onWindowStageCreate(windowStage) {
- console.log('disableWindowDecor');
- windowStage.disableWindowDecor();
- }
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('disableWindowDecor');
+ windowStage.disableWindowDecor();
+ }
};
```
@@ -7531,18 +7598,19 @@ setShowOnLockScreen(showOnLockScreen: boolean): void
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
+import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
- // ...
+ // ...
- onWindowStageCreate(windowStage) {
- console.log('onWindowStageCreate');
- try {
- windowStage.setShowOnLockScreen(true);
- } catch (exception) {
- console.error('Failed to show on lockscreen. Cause:' + JSON.stringify(exception));
- };
+ onWindowStageCreate(windowStage: window.WindowStage) {
+ console.log('onWindowStageCreate');
+ try {
+ windowStage.setShowOnLockScreen(true);
+ } catch (exception) {
+ console.error('Failed to show on lockscreen. Cause:' + JSON.stringify(exception));
}
+ }
};
```
## TransitionContext9+