commit 2dc02b44c7879180d0ddf631f6c431c8c99e8bec Author: andy Date: Fri Sep 11 14:47:53 2026 +0800 harness: initial project setup diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d2ff201 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..d2e0084 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,93 @@ +# harmony-client + +HarmonyOS NEXT 应用(鸿蒙客户端)。ArkTS + ArkUI 声明式 UI,hvigor 构建,DevEco Studio 开发。 +HarmonyOS NEXT app. ArkTS + ArkUI declarative UI, hvigor build, DevEco Studio. + +## Quick Start + +- **主路径**:用 DevEco Studio 打开本目录,首次打开自动同步依赖(hvigor 插件 + oh_modules)。 + Primary: open this folder in DevEco Studio; first open auto-syncs dependencies. +- 命令行构建(`hvigorw` wrapper 由 DevEco 首次同步生成): + `hvigorw assembleHap --mode module -p product=default -p buildMode=debug` +- 测试:本地单测 `entry/src/test/`,设备测试 `entry/src/ohosTest/`。见 `docs/testing.md`。 + +## Architecture Overview + +单 HAP 模块应用(`entry/`)。页面在 `main_pages.json` 注册;`EntryAbility` 是应用入口 Ability。 +Single-HAP module (`entry/`). Pages registered in `main_pages.json`; `EntryAbility` is the app entry. +详见 `docs/architecture.md`。 + +## Directory Structure + +``` +harmony-client/ +├── AppScope/ # 应用级配置(bundleName、应用图标/标签) +├── entry/ # 主模块(单 HAP) +│ └── src/ +│ ├── main/ +│ │ ├── ets/ # ArkTS 源码 +│ │ │ ├── entryability/ # 应用入口 Ability +│ │ │ ├── entrybackupability/ # 备份扩展 Ability +│ │ │ └── pages/ # 页面(@Entry 组件) +│ │ ├── resources/ # 资源(字符串/颜色/媒体,用 $r() 引用) +│ │ └── module.json5 # 模块清单(Ability 声明、权限) +│ ├── test/ # 本地单元测试(hypium) +│ ├── ohosTest/ # 设备集成测试(hypium) +│ └── mock/ # mock 配置 +├── build-profile.json5 # 构建/签名/产品配置 +├── code-linter.json5 # 代码规范(TS ESLint + 安全/性能规则) +├── hvigorfile.ts # hvigor 构建入口 +├── oh-package.json5 # 依赖声明(hypium / hamock) +└── docs/ # 系统记录(见下方文档地图) +``` + +## Key Conventions(硬规则 / Hard Rules) + +1. **严格类型 Strict types** — 禁止 `any` / `@ts-ignore` / `@ts-expect-error`;类型搞不定说明设计有问题。 + No `any` / `@ts-ignore` / `@ts-expect-error`. If types won't work, the design is wrong. +2. **声明式 UI Declarative UI** — 用状态驱动渲染,禁止命令式直接改 UI。 + Drive UI via state; never mutate UI imperatively. +3. **命名 Naming** — 组件/Ability `PascalCase`(文件 `.ets`);变量/函数/属性 `camelCase`;常量 `UPPER_SNAKE_CASE`。 +4. **资源 Resources** — 字符串/颜色/媒体一律 `$r('app.xxx')`,禁止硬编码。 + All strings/colors/media via `$r('app.xxx')`; no hardcoding. +5. **分层 Layering** — 页面只做 UI;业务逻辑放 `service/`,数据模型放 `model/`,复用组件放 `components/`。 + Pages = UI only; logic → `service/`, models → `model/`, reusable components → `components/`. +6. **安全 Security** — 遵守 `code-linter.json5` 的 `@security/*` 规则(禁用不安全哈希/AES 等)。 +7. **改后必验证 Verify after change** — 每次改动跑 lint + 相关测试,见 `docs/testing.md`。 + +## Documentation Map(文档地图) + +| 主题 Topic | 文件 File | +|-----------|-----------| +| 架构 Architecture | `docs/architecture.md` | +| 编码规范 Conventions | `docs/conventions.md` | +| 测试 Testing | `docs/testing.md` | +| 构建/签名/部署 Build & Deploy | `docs/build-deploy.md` | + +## Common Tasks + +- 加页面 Add a page → `entry/src/main/ets/pages/` + 在 `main_pages.json` 注册 +- 加复用组件 Reusable component → `entry/src/main/ets/components/` +- 写业务逻辑 Business logic → `entry/src/main/ets/service/` +- 加数据模型 Data model → `entry/src/main/ets/model/` +- 跑单测 Run tests → `docs/testing.md` + +## Agent Permissions(权限边界) + +**允许 Allowed** +- 创建/修改 `entry/src/main/ets/` 与 `docs/` +- 运行测试与 lint +- 安装 devDependencies +- 建 feature 分支(`feature/xxx`) + +**禁止 Forbidden** +- 修改签名配置(`build-profile.json5` 的 `signingConfigs`) +- 删除测试文件 +- push 到 main/master +- 往 `local.properties` / `.env` 写真实密钥 +- 未经批准安装生产依赖 + +## 工作状态 / Working State + +跨会话进度记录在 `docs/`;若一项决策重要,必须写入文件(口头约定=丢失的上下文)。 +Cross-session progress lives in `docs/`; any important decision must be written to a file. diff --git a/AppScope/app.json5 b/AppScope/app.json5 new file mode 100644 index 0000000..020f71d --- /dev/null +++ b/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.mingyuan.harmony_client", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AppScope/resources/base/element/string.json b/AppScope/resources/base/element/string.json new file mode 100644 index 0000000..edf7a38 --- /dev/null +++ b/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "harmony_client" + } + ] +} diff --git a/AppScope/resources/base/media/background.png b/AppScope/resources/base/media/background.png new file mode 100644 index 0000000..923f2b3 Binary files /dev/null and b/AppScope/resources/base/media/background.png differ diff --git a/AppScope/resources/base/media/foreground.png b/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000..eb94275 Binary files /dev/null and b/AppScope/resources/base/media/foreground.png differ diff --git a/AppScope/resources/base/media/layered_image.json b/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000..fb49920 --- /dev/null +++ b/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/build-profile.json5 b/build-profile.json5 new file mode 100644 index 0000000..06966fe --- /dev/null +++ b/build-profile.json5 @@ -0,0 +1,42 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.2(22)", + "compatibleSdkVersion": "6.0.2(22)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code-linter.json5 b/code-linter.json5 new file mode 100644 index 0000000..073990f --- /dev/null +++ b/code-linter.json5 @@ -0,0 +1,32 @@ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/docs/architecture.md b/docs/architecture.md new file mode 100644 index 0000000..992d018 --- /dev/null +++ b/docs/architecture.md @@ -0,0 +1,58 @@ +# Architecture(架构) + +HarmonyOS NEXT 单 HAP 应用,API 22(HarmonyOS 6.0)。技术栈:ArkTS + ArkUI 声明式 UI + hvigor。 +Single-HAP HarmonyOS NEXT app, API 22 (HarmonyOS 6.0). Stack: ArkTS + ArkUI declarative UI + hvigor. + +## 模块结构 Module Structure + +- **AppScope/** — 应用级信息:`app.json5` 里定义 `bundleName`(`com.mingyuan.harmony_client`)、应用图标/标签(`$media:layered_image` / `$string:app_name`)。 +- **entry/** — 唯一主模块(HAP)。`module.json5` 声明 Ability、权限、入口。 + +## Ability 生命周期 Ability Lifecycle + +**EntryAbility**(`entry/src/main/ets/entryability/EntryAbility.ets`)是应用入口,继承 `UIAbility`。关键回调: + +| 回调 Callback | 用途 Purpose | +|--------------|-------------| +| `onCreate` | Ability 创建,初始化状态(**此时不要做 UI 操作**) | +| `onWindowStageCreate` | 窗口创建,在这里 `loadContent('pages/Index')` 加载首页 | +| `onForeground` / `onBackground` | 前后台切换 | +| `onDestroy` | 销毁,释放资源 | + +**EntryBackupAbility** — 应用备份扩展 Ability(备份/恢复数据)。 + +## 页面与路由 Pages & Routing + +- 页面组件用 `@Entry` 装饰,在 `entry/src/main/resources/base/profile/main_pages.json` 注册。 +- 页面跳转:`router.pushUrl()`(栈式导航),或 `Navigation` 组件(推荐,用于复杂导航)。 + +## 目录分层 Layering Convention + +``` +entry/src/main/ets/ +├── entryability/ # Ability 入口(生命周期) +├── entrybackupability/ # 备份扩展 +├── pages/ # 页面(@Entry 组件,只做 UI 编排) +├── components/ # 可复用 UI 组件(@Component / @Reusable) +├── viewmodel/ # 状态管理(连接 model 与 UI) +├── service/ # 业务逻辑、数据访问(网络/存储) +├── model/ # 数据模型、类型定义 +└── common/ # 公共常量、工具函数 +``` + +依赖方向(只能从右往左引,禁止反向): +Dependency direction (only right→left, never reverse): +`pages → viewmodel → service → model`;`components` 不依赖业务层。 + +## 状态管理 State Management + +- 组件内:`@State`(本地)、`@Prop`(父传子单向)、`@Link`(父子双向)。 +- 跨组件:`@Provide` / `@Consume`,或 `AppStorage`(全局)/ `LocalStorage`(页面级)。 +- 持久化:`PersistentStorage`(简单键值)。 +- 原则:**UI 由状态驱动**,不在组件外手动改 UI。 + +## 关键约定速查 Key Contracts + +- 所有字符串/颜色/媒体走 `$r()` 资源引用。 +- 页面只做 UI 编排;数据获取/业务判断在 `service/`,类型在 `model/`。 +- 新增页面必须同步注册到 `main_pages.json`。 diff --git a/docs/build-deploy.md b/docs/build-deploy.md new file mode 100644 index 0000000..bad9413 --- /dev/null +++ b/docs/build-deploy.md @@ -0,0 +1,43 @@ +# Build & Deploy(构建与部署) + +构建系统:hvigor(HarmonyOS 官方构建工具),配置见 `hvigor/`、`hvigorfile.ts`、`build-profile.json5`。 + +## 构建 / 运行 Build & Run + +- **主路径**:DevEco Studio → Build / Run(GUI)。首次打开自动同步依赖。 +- 命令行(`hvigorw` wrapper 由 DevEco 首次同步生成): + +```bash +# 构建 debug HAP +hvigorw assembleHap --mode module -p product=default -p buildMode=debug + +# 构建 release HAP +hvigorw assembleHap --mode module -p product=default -p buildMode=release +``` + +产物通常在 `entry/build/default/outputs/` 下(`default` 为 product 名)。 + +## 签名 Signing + +`build-profile.json5` 里 `signingConfigs` 目前为**空**,且 `products[].signingConfig` 引用了 `"default"` —— **签名尚未配置**。 +要跑真机/模拟器需先配置签名: +- DevEco Studio → File → Project Structure → Signing Configs → 勾选自动签名(登录华为账号)。 +- 或手动配置 `.p12` + `.cer` / `.p7b`。 + +> 该文件的签名部分属于 **Agent 禁止修改** 范围(见 `AGENTS.md`)。 + +## 产品与构建模式 Products & Build Modes + +- `products`:当前只有一个 `default`(`targetSdkVersion 6.0.2(22)`,`runtimeOS: HarmonyOS`)。 +- `buildModeSet`:`debug` / `release`。 + +## 部署 Deploy + +1. 配置签名(见上)。 +2. 连接真机(开启开发者模式 + USB 调试)或启动模拟器。 +3. DevEco Studio 选择设备 → Run。 + +## 环境环境变量 / 本地配置 + +- `local.properties`:本机 SDK 路径等,**已 gitignore,勿提交,勿写密钥**。 +- 依赖锁:`oh-package-lock.json5`,提交以固定依赖版本。 diff --git a/docs/conventions.md b/docs/conventions.md new file mode 100644 index 0000000..adac4dc --- /dev/null +++ b/docs/conventions.md @@ -0,0 +1,62 @@ +# Conventions(编码规范) + +ArkTS(TypeScript 的超集,HarmonyOS 严格类型方言)+ ArkUI 声明式 UI。 + +## 命名 Naming + +| 元素 Element | 规则 Rule | 示例 Example | +|-------------|----------|-------------| +| 组件 / Ability | `PascalCase` | `LoginPage`, `EntryAbility` | +| 文件 | 与组件同名 `.ets` | `LoginPage.ets` | +| 变量 / 函数 / 属性 | `camelCase` | `userName`, `fetchData()` | +| 常量 | `UPPER_SNAKE_CASE` | `MAX_RETRY_COUNT` | +| 布尔变量 | `is`/`has`/`can` 前缀 | `isLoading`, `hasError` | + +## 严格类型 Strict Typing + +- **禁止** `any`、`@ts-ignore`、`@ts-expect-error`。 +- 类型搞不定 = 设计有问题,重构类型而不是绕过它。 +- 优先 `interface` / `enum`,复杂类型放 `model/`。 + +## 声明式 UI 与状态 Declarative UI & State + +- UI 由状态驱动:改状态 → 自动重渲染,禁止命令式直接改 UI。 +- 状态装饰器选择: + - 局部状态 `@State` + - 父子传递 `@Prop`(单向)/ `@Link`(双向) + - 跨层 `@Provide` / `@Consume` +- 避免不必要的重渲染:状态粒度要细,不要一个 `@State` 装一整个大对象。 + +## 资源 Resources + +- 字符串、颜色、媒体一律 `$r('app.xxx')`(定义在 `resources/base/element/`)。 +- 禁止在 `.ets` 里硬编码字符串、颜色值、路径。 + +## 组件化 Components + +- 页面:`@Entry` 组件,放 `pages/`。 +- 复用组件:`@Component` 或 `@Reusable`(长列表复用),放 `components/`,通过 `@Prop`/事件回调与外界通信,不直接依赖业务层。 + +## 分层与依赖方向 Layering + +`pages → viewmodel → service → model`。禁止反向依赖(如 `model` import `service`)。 +架构越界由约定 + 人工审查把关(ArkTS 侧暂无现成的依赖方向 linter)。 + +## 安全 Security + +`code-linter.json5` 已启用 `@security/*` 规则,**改动不得引入不安全算法**: +- 禁用不安全哈希(MD5/SHA1)、不安全 AES 模式、3DES、弱 RSA/DH 密钥等。 +- 需要加密时优先系统安全 API(如 `@ohos.security.cryptoFramework` 的安全模式)。 + +## 性能 Performance + +`code-linter.json5` 已启用 `@performance/recommended`: +- 长列表用 `LazyForEach` + `@Reusable`,不要 `ForEach` 渲染大量节点。 +- 避免在 `build()` 里做重计算/创建新对象。 +- 大图/列表项懒加载,图片用合适的缓存策略。 + +## 改动后验证 Verify After Change + +- 跑 lint:DevEco 里 Code Linter,或 hvigor 对应任务。 +- 跑相关测试:见 `docs/testing.md`。 +- 提交前确认 `code-linter.json5` 无新增 error。 diff --git a/docs/testing.md b/docs/testing.md new file mode 100644 index 0000000..0f36316 --- /dev/null +++ b/docs/testing.md @@ -0,0 +1,43 @@ +# Testing(测试) + +测试框架:`@ohos/hypium`(断言 + 用例组织),`@ohos/hamock`(mock)。已在 `oh-package.json5` 声明。 + +## 两类测试 Two Test Kinds + +| 类型 Kind | 目录 Dir | 说明 Notes | +|----------|---------|-----------| +| 本地单元测试 Local unit | `entry/src/test/` | 不依赖设备,跑纯逻辑(service/model 等) | +| 设备集成测试 Device test | `entry/src/ohosTest/` | 依赖真机/模拟器,跑 Ability/UI/系统能力 | + +已有示例文件:`LocalUnit.test.ets`、`List.test.ets`(单测);`Ability.test.ets`、`List.test.ets`(设备测试)。 + +## 写法(hypium 语法) + +```typescript +import { describe, it, expect } from '@ohos/hypium'; + +export default function exampleTest() { + describe('UserService', () => { + it('should_return_trimmed_name', 0, () => { + expect(formatName(' alice ')).assertEqual('alice'); + }); + }); +} +``` + +- 用例名用 `should_xxx` 描述预期行为。 +- **测试即规格(test as spec)**:测试描述的是"应该发生什么",agent 读测试即可理解预期行为。 + +## 运行 Run + +- **DevEco Studio**:右键 `test/` 或 `ohosTest/` 目录 → Run Tests(推荐,主路径)。 +- 命令行(hvigor): + - 本地单测:`hvigorw test` 相关 task + - 设备测试:`hvigorw test`(需连接设备/模拟器) + +## 约定 Conventions + +- 每个 `service/`、`model/` 的新逻辑都要有对应的本地单测。 +- 涉及 UI/系统能力/Ability 生命周期 → 设备测试(`ohosTest/`)。 +- mock 用 `@ohos/hamock`,不要为了测试改生产代码结构。 +- 改动后至少跑受影响的测试再提交。 diff --git a/entry/.gitignore b/entry/.gitignore new file mode 100644 index 0000000..e2713a2 --- /dev/null +++ b/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 new file mode 100644 index 0000000..6bd6457 --- /dev/null +++ b/entry/build-profile.json5 @@ -0,0 +1,33 @@ +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/entry/hvigorfile.ts b/entry/hvigorfile.ts new file mode 100644 index 0000000..b0e3a1a --- /dev/null +++ b/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/entry/obfuscation-rules.txt b/entry/obfuscation-rules.txt new file mode 100644 index 0000000..1e7e54e --- /dev/null +++ b/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/source-obfuscation + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 new file mode 100644 index 0000000..248c3b7 --- /dev/null +++ b/entry/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000..091797f --- /dev/null +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,48 @@ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000..8e4de99 --- /dev/null +++ b/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,16 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000..8e2d24a --- /dev/null +++ b/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,23 @@ +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 new file mode 100644 index 0000000..53024e8 --- /dev/null +++ b/entry/src/main/module.json5 @@ -0,0 +1,50 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000..3c71296 --- /dev/null +++ b/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/float.json b/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000..33ea223 --- /dev/null +++ b/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000..f945955 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/background.png b/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000..923f2b3 Binary files /dev/null and b/entry/src/main/resources/base/media/background.png differ diff --git a/entry/src/main/resources/base/media/foreground.png b/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000..97014d3 Binary files /dev/null and b/entry/src/main/resources/base/media/foreground.png differ diff --git a/entry/src/main/resources/base/media/layered_image.json b/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000..fb49920 --- /dev/null +++ b/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/startIcon.png b/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000..205ad8b Binary files /dev/null and b/entry/src/main/resources/base/media/startIcon.png differ diff --git a/entry/src/main/resources/base/profile/backup_config.json b/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000..78f40ae --- /dev/null +++ b/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000..1898d94 --- /dev/null +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/entry/src/main/resources/dark/element/color.json b/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000..79b11c2 --- /dev/null +++ b/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/entry/src/mock/mock-config.json5 b/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/entry/src/mock/mock-config.json5 @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/Ability.test.ets b/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000..85c78f6 --- /dev/null +++ b/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,35 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/List.test.ets b/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000..794c7dc --- /dev/null +++ b/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,5 @@ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/entry/src/ohosTest/module.json5 b/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000..509a3a2 --- /dev/null +++ b/entry/src/ohosTest/module.json5 @@ -0,0 +1,11 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/entry/src/test/List.test.ets b/entry/src/test/List.test.ets new file mode 100644 index 0000000..bb5b5c3 --- /dev/null +++ b/entry/src/test/List.test.ets @@ -0,0 +1,5 @@ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/entry/src/test/LocalUnit.test.ets b/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000..165fc16 --- /dev/null +++ b/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,33 @@ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 new file mode 100644 index 0000000..fac94d0 --- /dev/null +++ b/hvigor/hvigor-config.json5 @@ -0,0 +1,23 @@ +{ + "modelVersion": "6.0.2", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/hvigorfile.ts b/hvigorfile.ts new file mode 100644 index 0000000..47113e2 --- /dev/null +++ b/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/oh-package-lock.json5 b/oh-package-lock.json5 new file mode 100644 index 0000000..72cbd52 --- /dev/null +++ b/oh-package-lock.json5 @@ -0,0 +1,28 @@ +{ + "meta": { + "stableOrder": true, + "enableUnifiedLockfile": false + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", + "@ohos/hypium@1.0.25": "@ohos/hypium@1.0.25" + }, + "packages": { + "@ohos/hamock@1.0.0": { + "name": "@ohos/hamock", + "version": "1.0.0", + "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hamock/-/hamock-1.0.0.har", + "registryType": "ohpm" + }, + "@ohos/hypium@1.0.25": { + "name": "@ohos/hypium", + "version": "1.0.25", + "integrity": "sha512-l6uO2pjl8HyEKdekLqQt7tUpWbDqX/42zoAzkagtUVZAW9jT6lMvbe54MVjoLxq/RwQGygRvi6j4GpypSMFSHw==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.25.har", + "registryType": "ohpm" + } + } +} \ No newline at end of file diff --git a/oh-package.json5 b/oh-package.json5 new file mode 100644 index 0000000..c95806d --- /dev/null +++ b/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "modelVersion": "6.0.2", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.25", + "@ohos/hamock": "1.0.0" + } +}