diff --git a/build-profile.json5 b/build-profile.json5 index 1e69556b3411622cb2e87a87389653bb34f1b148..03ac3a3ae9dd397844173066e5d5ee21b49455a1 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -5,7 +5,7 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.0(12)", + "compatibleSdkVersion": "5.0.4(16)", "runtimeOS": "HarmonyOS", "buildOption": { "strictMode": { diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 2070f9634a477f7fee56b29f6c0425a91f66f7ac..94b5b08c5a76d62d6b6a4091df9c371e1a2d3195 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -33,6 +33,8 @@ export default class EntryAbility extends UIAbility { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Index', (err) => { + AppStorage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); + const uiContext: UIContext | undefined = AppStorage.get('uiContext'); if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; @@ -44,8 +46,8 @@ export default class EntryAbility extends UIAbility { const avoidAreaBottom = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); const topRectHeight = avoidAreaTop.topRect.height; const bottomRectHeight = avoidAreaBottom.bottomRect.height; - AppStorage.setOrCreate('topRectHeight', px2vp(topRectHeight)); - AppStorage.setOrCreate('bottomRectHeight', px2vp(bottomRectHeight)); + AppStorage.setOrCreate('topRectHeight', uiContext?.px2vp(topRectHeight)); + AppStorage.setOrCreate('bottomRectHeight', uiContext?.px2vp(bottomRectHeight)); let uiContext: UIContext | undefined = windowStage.getMainWindowSync().getUIContext() AppStorage.setOrCreate('uiContext', uiContext); }); diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 3e51a752cf208f97b4105a3996706ff208b951f8..be21325b971a3b23a91622e900903e7705a77eb1 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -37,7 +37,7 @@ struct Index { private webWidth: number = 0; private webHeight: number = 0; private windowClass: window.Window | null = null; - private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + private context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; private manager: WebDownloadManager = WebDownloadManager.getInstance(); private ctx: UIContext = this.getUIContext(); private options: promptAction.BaseDialogOptions = { @@ -123,8 +123,8 @@ struct Index { return false; } this.result = event.result; - this.pressPosX = px2vp(event.param.x()); - this.pressPosY = px2vp(event.param.y()); + this.pressPosX = this.getUIContext().px2vp(event.param.x()); + this.pressPosY = this.getUIContext().px2vp(event.param.y()); this.linkUrl = event.param.getSourceUrl(); this.isShow = true; return true; diff --git a/entry/src/main/ets/utils/CustomFunction.ets b/entry/src/main/ets/utils/CustomFunction.ets index 75499565666c798b9acf42b39dbdd85e4ffeb5f1..5164e4311f6d35163e6a8f072d6a933b8ca62b87 100644 --- a/entry/src/main/ets/utils/CustomFunction.ets +++ b/entry/src/main/ets/utils/CustomFunction.ets @@ -13,7 +13,6 @@ * limitations under the License. */ -import { promptAction } from '@kit.ArkUI'; import { common, Want } from '@kit.AbilityKit'; import { pasteboard } from '@kit.BasicServicesKit'; import { fileIo as fs, picker } from '@kit.CoreFileKit'; @@ -22,6 +21,7 @@ import { WebDownloadManager } from './WebDownloadManager'; import { hilog } from '@kit.PerformanceAnalysisKit'; const uiContext: UIContext | undefined = AppStorage.get('uiContext'); +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); /** * Copies a URI to the system clipboard. * @@ -35,7 +35,7 @@ export function copyLink(uri: string) { hilog.error(0x000, Constants.TAG, JSON.stringify(err)); return; } - uiContext!.getPromptAction().showToast({ + uiContext?.getPromptAction().showToast({ message: $r('app.string.copy_success') }) }) @@ -61,14 +61,14 @@ export async function saveVideoToGallery( let documentPicker = new picker.DocumentViewPicker(context); documentPicker.save(documentSaveOptions).then(async (uris: Array) => { if (uris.length === 0) { - uiContext!.getPromptAction().showToast({ message: $r('app.string.user_cancelled_authorization') }) + uiContext?.getPromptAction().showToast({ message: $r('app.string.user_cancelled_authorization') }) return; } openDownloadDialog(); // open dialog const path = await webDownloadManager.start(Constants.INDEX_WEB_CONTROLLER, context.filesDir, uri); closeDownloadDialog(); // close dialog webDownloadManager.clearProgress(); - uiContext!.getPromptAction().showToast({ message: $r('app.string.download_success') }) + uiContext?.getPromptAction().showToast({ message: $r('app.string.download_success') }) const targetFile = fs.openSync(uris[0], fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); const sourceFile = fs.openSync(path, fs.OpenMode.READ_ONLY); let buf = new ArrayBuffer(1024);