From a041d8ef287938efac11ebe8071d76959445743f Mon Sep 17 00:00:00 2001 From: "DESKTOP-9FJNTIC\\gyb" <121287102@qq.com> Date: Thu, 18 Sep 2025 11:49:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=95=B4=E6=94=B9log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 22 +++++++-- componentstacklibrary/Index.ets | 4 +- .../src/main/ets/utils/BreakpointSystem.ets | 6 +-- .../src/main/ets/utils/Logger.ets | 45 +++++++++++++++++++ .../src/main/ets/utils/WindowUtil.ets | 14 +++--- .../src/main/ets/view/ProductList.ets | 6 ++- .../main/resources/base/element/string.json | 4 ++ .../main/resources/en_US/element/string.json | 4 ++ .../main/resources/zh_CN/element/string.json | 4 ++ .../main/resources/en_US/element/string.json | 4 -- 10 files changed, 91 insertions(+), 22 deletions(-) create mode 100644 componentstacklibrary/src/main/ets/utils/Logger.ets diff --git a/build-profile.json5 b/build-profile.json5 index 468b2e7..329baea 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,17 +1,31 @@ { "app": { - "signingConfigs": [], + "signingConfigs": [ + { + "name": "default", + "type": "HarmonyOS", + "material": { + "certpath": "C:\\Users\\gyb\\.ohos\\config\\default_component-stack2_yXX7QxUHzyHkjI8uTaQlG6nbka5rvSJ-joYVuTE1MBU=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001B96932818AB7578DED7C2D5FA79053A3686D0FB8018BEC69393A4CFC8021E7AEDEED5762879B7DC", + "profile": "C:\\Users\\gyb\\.ohos\\config\\default_component-stack2_yXX7QxUHzyHkjI8uTaQlG6nbka5rvSJ-joYVuTE1MBU=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:\\Users\\gyb\\.ohos\\config\\default_component-stack2_yXX7QxUHzyHkjI8uTaQlG6nbka5rvSJ-joYVuTE1MBU=.p12", + "storePassword": "0000001B7FF23E45E321A0123AA47C8076202BF9C083264AE3FFFE1FB170016F5287DD66720C06D5085728" + } + } + ], "products": [ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.0(12)", - "runtimeOS": "HarmonyOS", + "compatibleSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS" } ], "buildModeSet": [ { - "name": "debug", + "name": "debug" }, { "name": "release" diff --git a/componentstacklibrary/Index.ets b/componentstacklibrary/Index.ets index baab691..c3c48fe 100644 --- a/componentstacklibrary/Index.ets +++ b/componentstacklibrary/Index.ets @@ -1,3 +1,5 @@ export { ComponentStackComponent } from './src/main/ets/component/ComponentStackComponent'; -export { ComponentStackController } from './src/main/ets/ComponentStackController.ets'; \ No newline at end of file +export { ComponentStackController } from './src/main/ets/ComponentStackController'; + +export { default as Logger } from './src/main/ets/utils/Logger'; \ No newline at end of file diff --git a/componentstacklibrary/src/main/ets/utils/BreakpointSystem.ets b/componentstacklibrary/src/main/ets/utils/BreakpointSystem.ets index 02feb55..aab1217 100644 --- a/componentstacklibrary/src/main/ets/utils/BreakpointSystem.ets +++ b/componentstacklibrary/src/main/ets/utils/BreakpointSystem.ets @@ -14,9 +14,8 @@ */ import { window } from '@kit.ArkUI'; -import type { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { CommonConstants } from '../constants/CommonConstants'; +import Logger from './Logger'; const TAG: string = '[BreakpointSystem]'; @@ -111,8 +110,7 @@ export class BreakpointSystem { } this.updateCurrentBreakpoint(widthBp); } catch (error) { - const err: BusinessError = error as BusinessError; - hilog.error(0x0000, TAG, `UpdateBreakpoint fail, error code: ${err.code}, message: ${err.message}`); + Logger.error(TAG, `UpdateBreakpoint fail.`); } } } \ No newline at end of file diff --git a/componentstacklibrary/src/main/ets/utils/Logger.ets b/componentstacklibrary/src/main/ets/utils/Logger.ets new file mode 100644 index 0000000..7307614 --- /dev/null +++ b/componentstacklibrary/src/main/ets/utils/Logger.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + public constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0x0000; + } + + public debug(...args: Object[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + public info(...args: Object[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + public warn(...args: Object[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + public error(...args: Object[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + +export default new Logger('[ComponentStack]'); \ No newline at end of file diff --git a/componentstacklibrary/src/main/ets/utils/WindowUtil.ets b/componentstacklibrary/src/main/ets/utils/WindowUtil.ets index 6a37e2b..408685e 100644 --- a/componentstacklibrary/src/main/ets/utils/WindowUtil.ets +++ b/componentstacklibrary/src/main/ets/utils/WindowUtil.ets @@ -15,10 +15,10 @@ import { window } from '@kit.ArkUI'; import type { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { common, Configuration, ConfigurationConstant } from '@kit.AbilityKit'; +import { common, ConfigurationConstant } from '@kit.AbilityKit'; import { CommonConstants } from '../constants/CommonConstants'; import { BreakpointSystem } from './BreakpointSystem'; +import Logger from './Logger'; const TAG: string = '[WindowUtil]'; @@ -35,7 +35,7 @@ export class WindowUtil { WindowUtil.registerBreakPoint(windowStage); WindowUtil.requestFullScreen(windowStage); } catch (err) { - hilog.error(0x0000, TAG, `WindowUtil initialize failed. Cause: ${err.code} ${err.message}`); + Logger.error(TAG, `WindowUtil initialize failed. Cause: ${err.code} ${err.message}`); } } @@ -49,13 +49,13 @@ export class WindowUtil { try { const promise: Promise = windowClass.setWindowLayoutFullScreen(true); promise.then(() => { - hilog.info(0x0000, TAG, 'Succeeded in setting the window layout to full-screen mode.'); + Logger.info(TAG, 'Succeeded in setting the window layout to full-screen mode.'); }).catch((err: BusinessError) => { - hilog.error(0x0000, TAG, + Logger.error(TAG, `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); }); } catch { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode.'); + Logger.error(TAG, 'Failed to set the window layout to full-screen mode.'); } }); } @@ -63,7 +63,7 @@ export class WindowUtil { public static registerBreakPoint(windowStage: window.WindowStage) { windowStage.getMainWindow((err: BusinessError, data: window.Window) => { if (err.code) { - hilog.error(0x0000, TAG, `Failed to get main window: ${err.message}`); + Logger.error(TAG, `Failed to get main window: ${err.message}`); return; } BreakpointSystem.getInstance().updateWidthBp(data); diff --git a/componentstacklibrary/src/main/ets/view/ProductList.ets b/componentstacklibrary/src/main/ets/view/ProductList.ets index b063158..9e8a6e4 100644 --- a/componentstacklibrary/src/main/ets/view/ProductList.ets +++ b/componentstacklibrary/src/main/ets/view/ProductList.ets @@ -16,10 +16,12 @@ import { ProductDataModel } from '../viewmodel/IconViewModel'; import { ProductDataSource } from '../viewmodel/DataSource'; import { PRODUCT_DATA } from '../model/IconModel'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { CommonConstants } from '../constants/CommonConstants'; import { BreakpointTypeEnum } from '../utils/BreakpointSystem'; +import Logger from '../utils/Logger'; + +const TAG: string = '[ProductList]'; @Component export struct ProductList { @@ -79,7 +81,7 @@ export struct ProductList { this.getUIContext().getPromptAction().showToast({ message: $r('app.string.component_stack_other_function') }); } catch (error) { const err = error as BusinessError; - hilog.error(0x000, 'ProductList', `showToast catch error, code: ${err.code}, message: ${err.message}`); + Logger.error(TAG, `showToast catch error, code: ${err.code}, message: ${err.message}`); } }); } diff --git a/componentstacklibrary/src/main/resources/base/element/string.json b/componentstacklibrary/src/main/resources/base/element/string.json index bc32604..62493b4 100644 --- a/componentstacklibrary/src/main/resources/base/element/string.json +++ b/componentstacklibrary/src/main/resources/base/element/string.json @@ -1,5 +1,9 @@ { "string": [ + { + "name": "product_title00", + "value": "充电宝" + }, { "name": "product_title01", "value": "笔记本电脑" diff --git a/componentstacklibrary/src/main/resources/en_US/element/string.json b/componentstacklibrary/src/main/resources/en_US/element/string.json index f3cda33..c098fbe 100644 --- a/componentstacklibrary/src/main/resources/en_US/element/string.json +++ b/componentstacklibrary/src/main/resources/en_US/element/string.json @@ -1,5 +1,9 @@ { "string": [ + { + "name": "product_title00", + "value": "powerbank" + }, { "name": "product_title01", "value": "laptop" diff --git a/componentstacklibrary/src/main/resources/zh_CN/element/string.json b/componentstacklibrary/src/main/resources/zh_CN/element/string.json index bc32604..62493b4 100644 --- a/componentstacklibrary/src/main/resources/zh_CN/element/string.json +++ b/componentstacklibrary/src/main/resources/zh_CN/element/string.json @@ -1,5 +1,9 @@ { "string": [ + { + "name": "product_title00", + "value": "充电宝" + }, { "name": "product_title01", "value": "笔记本电脑" diff --git a/componentstacksample/src/main/resources/en_US/element/string.json b/componentstacksample/src/main/resources/en_US/element/string.json index 3ddc584..6c097bd 100644 --- a/componentstacksample/src/main/resources/en_US/element/string.json +++ b/componentstacksample/src/main/resources/en_US/element/string.json @@ -11,10 +11,6 @@ { "name": "EntryAbility_label", "value": "Component stacking" - }, - { - "name": "product_title00", - "value": "powerbank" } ] } \ No newline at end of file -- Gitee From 97e544e73c602a68a47ac5d7cd58a386efe4d67d Mon Sep 17 00:00:00 2001 From: "DESKTOP-9FJNTIC\\gyb" <121287102@qq.com> Date: Thu, 18 Sep 2025 21:58:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?logger=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/utils/WindowUtil.ets | 6 +++++- .../main/ets/entryability/EntryAbility.ets | 21 +++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/componentstacklibrary/src/main/ets/utils/WindowUtil.ets b/componentstacklibrary/src/main/ets/utils/WindowUtil.ets index 408685e..d537e53 100644 --- a/componentstacklibrary/src/main/ets/utils/WindowUtil.ets +++ b/componentstacklibrary/src/main/ets/utils/WindowUtil.ets @@ -96,6 +96,10 @@ export class WindowUtil { } public static updatedColorMode(context: common.UIAbilityContext): void { - context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + Logger.error(TAG, `updatedColorMode fail.`); + } } } \ No newline at end of file diff --git a/componentstacksample/src/main/ets/entryability/EntryAbility.ets b/componentstacksample/src/main/ets/entryability/EntryAbility.ets index 097d761..b1e5bbf 100644 --- a/componentstacksample/src/main/ets/entryability/EntryAbility.ets +++ b/componentstacksample/src/main/ets/entryability/EntryAbility.ets @@ -13,49 +13,48 @@ * limitations under the License. */ -import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; +import { UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; -import { ComponentStackController } from '@ohos_sample/componentstacklibrary'; +import { ComponentStackController, Logger } from '@ohos_sample/componentstacklibrary'; const TAG = '[EntryAbility]'; export default class EntryAbility extends UIAbility { onCreate(): void { - hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); + Logger.info(TAG, '%{public}s', 'Ability onCreate'); ComponentStackController.updatedColorMode(this.context); } onDestroy(): void { - hilog.info(0x0000, TAG, '%{public}s', 'Ability onDestroy'); + Logger.info(TAG, '%{public}s', 'Ability onDestroy'); } onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability. - hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate'); + Logger.info(TAG, '%{public}s', 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Index', (err) => { if (err.code) { - hilog.error(0x0000, TAG, `Failed to load the content, err code: ${err.code}, message: ${err.message}`); + Logger.error(TAG, `Failed to load the content, err code: ${err.code}, message: ${err.message}`); return; } ComponentStackController.initWindowConfig(windowStage); - hilog.info(0x0000, TAG, 'Succeeded in loading the content.'); + Logger.info(TAG, 'Succeeded in loading the content.'); }); } onWindowStageDestroy(): void { // Main window is destroyed, release UI related resources - hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageDestroy'); + Logger.info(TAG, '%{public}s', 'Ability onWindowStageDestroy'); } onForeground(): void { // Ability has brought to foreground - hilog.info(0x0000, TAG, '%{public}s', 'Ability onForeground'); + Logger.info(TAG, '%{public}s', 'Ability onForeground'); } onBackground(): void { // Ability has back to background - hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground'); + Logger.info(TAG, '%{public}s', 'Ability onBackground'); } } \ No newline at end of file -- Gitee