diff --git a/README.en.md b/README.en.md index 2c5ea32ce15515d048090768d8e02daeb8940703..cd5d037b578eab7b22087c3edd3d74073cdb9e2a 100644 --- a/README.en.md +++ b/README.en.md @@ -15,7 +15,9 @@ Instructions: ``` ├──entry/src/main/ets/ │ ├──common -│ │ └──Constants.ets // Common constant class +│ │ ├──BreakpointType.ets +│ │ ├──Constants.ets // Common constant class +│ │ └──ResourceUtil.ets │ ├──entryability │ │ └──EntryAbility.ets // Entry ability │ └──pages diff --git a/README.md b/README.md index a6c233bb4387e4a69c98b6b4398d0946451ea053..33f006bf98369203ba163cdf3fd1a70a1b6b49dd 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,9 @@ ``` ├──entry/src/main/ets/ │ ├──common -│ │ └──Constants.ets // 公共常量类 +│ │ ├──BreakpointType.ets +│ │ ├──Constants.ets // 公共常量类 +│ │ └──ResourceUtil.ets │ ├──entryability │ │ └──EntryAbility.ets // 程序入口类 │ └──pages diff --git a/entry/src/main/ets/common/BreakpointSystem.ets b/entry/src/main/ets/common/BreakpointType.ets similarity index 100% rename from entry/src/main/ets/common/BreakpointSystem.ets rename to entry/src/main/ets/common/BreakpointType.ets diff --git a/entry/src/main/ets/common/Constants.ets b/entry/src/main/ets/common/Constants.ets index 49c8670933d61ca597ceb40e6928dabe89499993..23dc95e54042d1211e1e1f0f9d7b77266dd14458 100644 --- a/entry/src/main/ets/common/Constants.ets +++ b/entry/src/main/ets/common/Constants.ets @@ -43,5 +43,5 @@ export class Constants { * Set the url whitelist of the current web */ public static readonly URL_TRUST: string = - '{\"UrlPermissionList\": [{\"scheme\": \"https\",\"host\": \"developer.huawei.com/consumer/cn/next\"}]}'; + '{\"UrlPermissionList\": [{\"scheme\": \"https\",\"host\": \"developer.huawei.com\"}]}'; } \ No newline at end of file diff --git a/entry/src/main/ets/common/ResourceUtil.ets b/entry/src/main/ets/common/ResourceUtil.ets index 9709127e94b6e164806eae81faf18ffb5ae9eba6..f26f38e1c31d39ec24445e92abc0e2a17bdcbab5 100644 --- a/entry/src/main/ets/common/ResourceUtil.ets +++ b/entry/src/main/ets/common/ResourceUtil.ets @@ -15,6 +15,7 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { JSON, util } from '@kit.ArkTS'; +import { BusinessError } from '@kit.BasicServicesKit'; export class ResourceUtil { /** @@ -30,7 +31,8 @@ export class ResourceUtil { try { resourceString = context.resourceManager.getStringSync(resource.id); } catch (error) { - hilog.error(0x0000, 'WebviewController', '%{public}s', `error: ${error}`); + hilog.error(0x0000, 'WebviewController', '%{public}s', + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); } return resourceString; } diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 4f3cf04372fbb2f75d6f5489eb91978449c2da53..0c556f4f759c04f0e2587022a7baa02fead753ad 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -22,7 +22,6 @@ import { createNWeb } from '../pages/WebPage'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; export default class EntryAbility extends UIAbility { - private windowObj?: window.Window; private curBp: string = ''; private updateBreakpoint(windowWidth: number): void { @@ -41,7 +40,8 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('currentBreakpoint', this.curBp); } } catch (error) { - hilog.error(0x0000, 'updateBreakpoint', '%{public}s', `updateBreakpoint fail, err: ${JSON.stringify(error)}`); + hilog.error(0x0000, 'updateBreakpoint', '%{public}s', + `updateBreakpoint fail, ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); } } @@ -74,7 +74,6 @@ export default class EntryAbility extends UIAbility { avoidArea = windowObj.getWindowAvoidArea(type); let topRectHeight = avoidArea.topRect.height; AppStorage.setOrCreate('topRectHeight', topRectHeight); - this.windowObj = windowObj; this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); windowObj.on('windowSizeChange', (windowSize) => { this.updateBreakpoint(windowSize.width); @@ -89,17 +88,17 @@ export default class EntryAbility extends UIAbility { createNWeb(ResourceUtil.getRawFileStringByKey(getContext(this) as common.UIAbilityContext, ConfigMapKey.GALLERY_URL), windowStage.getMainWindowSync().getUIContext()); if (err.code) { - hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + hilog.error(0x0000, 'testTag', 'Failed to load the content.'); return; } - hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.', JSON.stringify(data) ?? ''); let windowClass: window.Window = windowStage.getMainWindowSync(); let isLayoutFullScreen = true; windowClass.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { hilog.info(0x0000, 'testTag', '%{public}s', 'Succeeded in setting the window layout to full-screen mode.'); - }).catch((err: BusinessError) => { + }).catch(() => { hilog.error(0x0000, 'testTag', '%{public}s', - `Failed to set the window layout to full-screen mode. Cause:${err}`); + 'Failed to set the window layout to full-screen mode.'); }); }); } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index d3369744aea417f724044350462d9dfb1c492a99..af52f756c08a33d63cb2c6e0e7950ef084374faf 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -15,7 +15,7 @@ import { common } from '@kit.AbilityKit'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; -import { BreakpointType } from '../common/BreakpointSystem'; +import { BreakpointType } from '../common/BreakpointType'; import { Constants } from '../common/Constants'; import { getNWeb } from './WebPage'; diff --git a/entry/src/main/ets/pages/WebPage.ets b/entry/src/main/ets/pages/WebPage.ets index fe0baaaf3348a4868e18cd7ea5c382621521733b..4a4cb80290ca402b67abd0d8e90b54174cdbea99 100644 --- a/entry/src/main/ets/pages/WebPage.ets +++ b/entry/src/main/ets/pages/WebPage.ets @@ -13,12 +13,13 @@ * limitations under the License. */ -import { UIContext, NodeController, BuilderNode, FrameNode } from '@kit.ArkUI'; +import { BuilderNode, FrameNode, NodeController, UIContext } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { common } from '@kit.AbilityKit'; import { webview } from '@kit.ArkWeb'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; import { Constants } from '../common/Constants'; +import { BusinessError } from '@kit.BasicServicesKit'; class Data { public url: string = @@ -36,12 +37,12 @@ function webBuilder(data: Data) { // Set the whitelist to allow access to only the trust web page. data.controller.setUrlTrustList(Constants.URL_TRUST); } catch (error) { - hilog.error(0x0000, 'WebviewController', '%{public}s', `error: ${error}`); + hilog.error(0x0000, 'WebviewController', '%{public}s', + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); } }) .onSslErrorEventReceive((event) => { - hilog.info(0x0000, 'onSslErrorEventReceive', '%{public}s', - `ssl check failed, error is :${event.error.toString()}`); + hilog.info(0x0000, 'onSslErrorEventReceive', '%{public}s', 'ssl check failed'); event.handler.handleCancel(); }) .width($r('app.string.full_height_width'))