diff --git a/docs/product/ARKTS_NATIVE_BOUNDARY_LIST_V0.md b/docs/product/ARKTS_NATIVE_BOUNDARY_LIST_V0.md new file mode 100644 index 0000000..82c4cc3 --- /dev/null +++ b/docs/product/ARKTS_NATIVE_BOUNDARY_LIST_V0.md @@ -0,0 +1,168 @@ +# ArkTS 页面与 Native 边界清单 v0 + +项目:MRP 模拟器鸿蒙化 +角色:RD Frontend +范围:FE-003 + +## 1. 可以留在 ArkTS 的逻辑 + +### 1.1 页面与路由 +- 应用列表页导航 +- 导入页导航 +- 运行页导航 +- 页面返回与确认弹窗 + +### 1.2 纯展示逻辑 +- 列表渲染 +- 空态展示 +- 加载态展示 +- 导入结果展示 +- 运行状态展示 +- 错误 Banner / Dialog 展示 + +### 1.3 轻量交互逻辑 +- 点击应用进入运行页 +- 点击导入按钮进入导入页 +- 点击重试/重启/退出 +- 页面 show/hide 生命周期事件转发 + +### 1.4 ViewModel 级状态整理 +- 把 Service 返回的数据映射为页面展示态 +- 按 phase 切换不同组件 +- 管理页面局部临时状态 + +--- + +## 2. 必须走 Adapter / Native 的逻辑 + +### 2.1 导入链路 +- 文件选择器底层接入 +- URI / 沙箱路径转换 +- 文件合法性校验 +- 包解析 +- 文件复制 / 解压 / 注册 +- 导入失败原因原始采集 + +### 2.2 应用元数据链路 +- 已安装应用扫描 +- 图标与元数据读取 +- 应用可运行性判定 +- 本地注册表 / 索引读取 + +### 2.3 运行链路 +- 创建运行会话 +- 渲染容器绑定 +- surface / XComponent / native handle 管理 +- 输入事件注入 +- 音频输出 +- 暂停 / 恢复 / 停止运行 +- 异常退出与 native 层资源释放 + +### 2.4 持久化与底层能力 +- 存档路径管理 +- 配置落盘 +- 日志写入 +- 权限与沙箱细节 +- 生命周期与系统事件底层适配 + +--- + +## 3. 页面层禁止下沉的内容清单 + +### 3.1 禁止进入页面的 native 细节 +- native error code +- session handle +- surface id / window id +- 线程 id +- 原始路径 +- 文件描述符 +- 原始导入阶段枚举 +- 原始运行时回调对象 + +### 3.2 禁止进入页面的实现逻辑 +- 文件复制与解压 +- 包头解析 +- 存档目录拼接 +- 输入协议映射实现 +- 音频设备初始化 +- 渲染线程管理 +- native 生命周期恢复逻辑 + +### 3.3 禁止页面直接做的调用 +- 页面直接调 NAPI 原始方法 +- 页面直接管理 native listener +- 页面直接订阅 native 高频事件流 +- 页面直接判断兼容性底层规则 + +--- + +## 4. 页面层允许拿到的唯一形态 + +页面只允许拿到: +- `AppItemVM` +- `PackagePreviewVM` +- `RuntimePhase` +- `UiError` +- `canRestart / canExit` 这类布尔控制量 + +页面不允许拿到: +- 原始导入结构 +- 原始会话结构 +- 原始渲染对象 +- 原始路径对象 + +--- + +## 5. 各页面边界结论 + +### 5.1 AppListPage +ArkTS 保留: +- 列表渲染 +- 空态/错误态 +- 页面跳转 + +必须下沉: +- 扫描应用 +- 读取应用元数据 +- 判断是否可运行 + +### 5.2 ImportPage +ArkTS 保留: +- 选择文件后的流程编排 +- 预览展示 +- 导入成功/失败展示 + +必须下沉: +- 文件选择器底层接入 +- 包解析与合法性验证 +- 导入执行 + +### 5.3 RunPage +ArkTS 保留: +- 容器占位与工具栏 +- 状态切换展示 +- 重启/退出按钮 + +必须下沉: +- 运行会话创建 +- 渲染绑定 +- 输入/音频/资源释放 + +--- + +## 6. 边界原则 + +1. ArkTS 负责用户意图与页面编排。 +2. Service 负责业务组织与错误归一。 +3. Adapter 负责 native 能力收口。 +4. 页面层不得因省事而直接接 native 原始对象。 +5. native 命名变化只能影响 Adapter,不允许扩散到页面层。 + +--- + +## 7. 结论 + +POC 阶段边界已经固定: +- ArkTS 做页面、组件、状态编排 +- Adapter / Native 做导入、运行、渲染、输入、音频、存档、路径、日志 +- 页面层严格禁止下沉到底层实现细节 diff --git a/docs/product/ARKTS_SHELL_CONTRACTS_V0.md b/docs/product/ARKTS_SHELL_CONTRACTS_V0.md new file mode 100644 index 0000000..878b02a --- /dev/null +++ b/docs/product/ARKTS_SHELL_CONTRACTS_V0.md @@ -0,0 +1,291 @@ +# ArkTS 壳层页面-Store-Service-Adapter 契约 v0 + +项目:MRP 模拟器鸿蒙化 +角色:RD Frontend +范围:FE-002 + +## 1. 页面输入输出边界 + +### 1.1 AppListPage +输入: +- `AppCatalogStore.items` +- `AppCatalogStore.loading` +- `AppCatalogStore.error` + +输出: +- `loadApps()` +- `refreshApps()` +- `openImportPage()` +- `openRunPage(appId)` + +页面只消费: +- 应用列表 ViewModel +- 加载态 +- 错误态 + +页面不消费: +- native 列表原始结构 +- 本地存储路径 +- 运行句柄 + +--- + +### 1.2 ImportPage +输入: +- `ImportStore.phase` +- `ImportStore.selectedFile` +- `ImportStore.previewInfo` +- `ImportStore.error` + +输出: +- `pickFile()` +- `analyzeSelectedFile()` +- `startImport()` +- `backToListAfterSuccess()` +- `retryImport()` + +页面只消费: +- 导入阶段 +- 预览信息 +- 成功/失败结果 + +页面不消费: +- 文件复制进度实现 +- 包校验细节 +- URI 到沙箱路径转换逻辑 + +--- + +### 1.3 RunPage +输入: +- `RuntimeSessionStore.currentAppId` +- `RuntimeSessionStore.phase` +- `RuntimeSessionStore.error` +- `RuntimeSessionStore.canRestart` +- `RuntimeSessionStore.canExit` + +输出: +- `startSession(appId)` +- `restartSession()` +- `stopSession()` +- `leaveRunPage()` +- `notifyPageShow()` +- `notifyPageHide()` + +页面只消费: +- 会话状态 +- 控件可用性 +- 结构化错误提示 + +页面不消费: +- runtime native handle +- surface/XComponent 生命周期对象 +- 输入注入协议 + +--- + +## 2. Store 最小接口 + +### 2.1 AppCatalogStore +```ts +interface AppCatalogStore { + items: AppItemVM[] + loading: boolean + error: UiError | null + + loadApps(): Promise + refreshApps(): Promise + clearError(): void +} +``` + +### 2.2 ImportStore +```ts +type ImportPhase = 'idle' | 'picking' | 'analyzing' | 'importing' | 'success' | 'failed' + +interface ImportStore { + phase: ImportPhase + selectedFile: string | null + previewInfo: PackagePreviewVM | null + error: UiError | null + + pickFile(): Promise + analyzeSelectedFile(): Promise + startImport(): Promise + reset(): void +} +``` + +### 2.3 RuntimeSessionStore +```ts +type RuntimePhase = 'idle' | 'starting' | 'running' | 'error' | 'stopped' + +interface RuntimeSessionStore { + currentAppId: string | null + phase: RuntimePhase + error: UiError | null + canRestart: boolean + canExit: boolean + + startSession(appId: string): Promise + restartSession(): Promise + stopSession(): Promise + clearError(): void +} +``` + +--- + +## 3. Service 最小接口 + +### 3.1 AppService +```ts +interface AppService { + listApps(): Promise +} +``` + +职责: +- 从 NativeAppAdapter 拉取应用元数据 +- 转换为 AppItemVM +- 屏蔽 native 原始字段 + +### 3.2 ImportService +```ts +interface ImportService { + pickMrpFile(): Promise + analyzePackage(fileUri: string): Promise + importPackage(fileUri: string): Promise<{ appId: string }> +} +``` + +职责: +- 编排文件选择 +- 解析包预览信息 +- 发起导入 +- 输出标准化错误 + +### 3.3 RuntimeService +```ts +interface RuntimeService { + start(appId: string): Promise + restart(appId: string): Promise + stop(): Promise + onPageShow(): Promise + onPageHide(): Promise +} +``` + +职责: +- 编排运行会话生命周期 +- 管理启动/停止/重启 +- 转换 runtime 错误为 UiError + +--- + +## 4. Adapter 占位契约 + +### 4.1 NativeAppAdapter +```ts +interface NativeAppAdapter { + listInstalledApps(): Promise> +} +``` + +### 4.2 NativeImportAdapter +```ts +interface NativeImportAdapter { + pickFile(): Promise + inspectPackage(fileUri: string): Promise<{ + name: string + version?: string + icon?: string + size?: number + valid: boolean + }> + importPackage(fileUri: string): Promise<{ + appId: string + }> +} +``` + +### 4.3 NativeRuntimeAdapter +```ts +interface NativeRuntimeAdapter { + startSession(appId: string): Promise + restartSession(appId: string): Promise + stopSession(): Promise + notifyPageShow(): Promise + notifyPageHide(): Promise +} +``` + +--- + +## 5. 模型最小定义 + +### 5.1 AppItemVM +```ts +interface AppItemVM { + id: string + name: string + icon?: string + version?: string + status: 'ready' | 'invalid' +} +``` + +### 5.2 PackagePreviewVM +```ts +interface PackagePreviewVM { + name: string + version?: string + icon?: string + sizeText?: string + valid: boolean +} +``` + +### 5.3 UiError +```ts +interface UiError { + message: string + retryable: boolean +} +``` + +--- + +## 6. 契约约束 + +### ArkTS 页面必须遵守 +- 只调用 Store Action +- 不直接调用 NativeAdapter +- 不持有 native 返回原始对象 +- 不解析 native 错误码 + +### Store 必须遵守 +- 不处理 UI 组件逻辑 +- 不暴露 native 对象给页面 +- 所有异步状态先转成 ArkTS 可消费状态 + +### Service 必须遵守 +- 只做业务编排与错误归一 +- 不承载页面导航 +- 不输出 native 路径和句柄 + +### Adapter 必须遵守 +- 封装所有 native 细节 +- 允许后续替换命名,不影响页面层 + +--- + +## 7. 结论 + +该契约用于先冻结 ArkTS 壳层输入输出边界,不等待 native 最终接口命名冻结。后续 native 能力接入时,仅允许在 Adapter 层收敛变化。 diff --git a/docs/product/ARKTS_SHELL_POC_STRUCTURE_FINAL.md b/docs/product/ARKTS_SHELL_POC_STRUCTURE_FINAL.md new file mode 100644 index 0000000..2cbc1d5 --- /dev/null +++ b/docs/product/ARKTS_SHELL_POC_STRUCTURE_FINAL.md @@ -0,0 +1,164 @@ +# ArkTS 壳层 POC 目录结构最终版 + +项目:MRP 模拟器鸿蒙化 +角色:RD Frontend +范围:FE-001 + +## 1. 目录树最终版 + +```text +entry/src/main/ets/ +├─ pages/ +│ ├─ AppListPage.ets +│ ├─ ImportPage.ets +│ └─ RunPage.ets +├─ components/ +│ ├─ common/ +│ │ ├─ PageHeader.ets +│ │ ├─ LoadingBlock.ets +│ │ ├─ StatusBanner.ets +│ │ ├─ ConfirmDialog.ets +│ │ └─ EmptyState.ets +│ ├─ appList/ +│ │ ├─ AppListView.ets +│ │ ├─ AppCard.ets +│ │ └─ ImportEntryButton.ets +│ ├─ import/ +│ │ ├─ ImportSourceSelector.ets +│ │ ├─ PackagePreviewCard.ets +│ │ ├─ ImportProgressPanel.ets +│ │ └─ ImportResultPanel.ets +│ └─ runtime/ +│ ├─ RuntimeContainer.ets +│ ├─ RuntimeToolbar.ets +│ └─ RuntimeStatusOverlay.ets +├─ store/ +│ ├─ AppCatalogStore.ts +│ ├─ ImportStore.ts +│ └─ RuntimeSessionStore.ts +├─ services/ +│ ├─ AppService.ts +│ ├─ ImportService.ts +│ └─ RuntimeService.ts +├─ adapters/ +│ ├─ NativeAppAdapter.ts +│ ├─ NativeImportAdapter.ts +│ └─ NativeRuntimeAdapter.ts +└─ models/ + ├─ AppItemVM.ts + ├─ PackagePreviewVM.ts + ├─ RuntimeSessionState.ts + └─ UiError.ts +``` + +--- + +## 2. 页面职责分工 + +### 2.1 AppListPage +职责: +- 展示已导入应用列表 +- 空态引导导入 +- 触发列表刷新 +- 选择应用并进入 RunPage +- 跳转 ImportPage + +不负责: +- 包解析 +- 文件导入实现 +- native 路径/数据库细节 +- runtime 会话细节 + +### 2.2 ImportPage +职责: +- 选择本地 MRP 文件 +- 展示包预览信息 +- 发起导入 +- 展示导入中状态 +- 展示导入成功/失败结果 +- 导入成功后通知列表刷新 + +不负责: +- URI 转沙箱路径规则 +- 解压/校验/复制实现 +- 导入兼容性底层规则 +- native 错误码判断 + +### 2.3 RunPage +职责: +- 承载模拟器运行区域 +- 展示启动中/运行中/异常/已退出状态 +- 提供返回/重启/退出操作 +- 响应页面生命周期并转发给 RuntimeService + +不负责: +- 渲染句柄管理 +- surface / XComponent 细节 +- 输入注入协议 +- 模拟器核心线程与事件循环 + +--- + +## 3. 首版明确不做的页面 + +### 3.1 SettingsPage +不做原因: +- 不属于 POC 最小闭环 +- 容易过早暴露 native 配置细节 +- 首版使用默认配置即可 + +### 3.2 AppDetailPage +不做原因: +- 与列表页信息重叠 +- 不影响导入/运行主链路 + +### 3.3 ImportHistoryPage +不做原因: +- 需要额外持久化与查询逻辑 +- POC 验证价值低 + +### 3.4 ErrorDiagnosisPage / LogPage +不做原因: +- 首版只需要结构化错误提示 +- 独立诊断页会过早耦合 native 日志格式与路径 + +### 3.5 SessionRecoveryPage +不做原因: +- 依赖会话恢复协议与异常恢复机制 +- 二阶段再进入 + +--- + +## 4. 页面层保留原则 + +页面层只保留: +- 页面路由 +- UI 组件组合 +- 用户交互 +- 状态展示 +- 调用 Store Action + +页面层不保留: +- native 原始对象 +- 文件系统路径 +- 导入实现细节 +- 渲染句柄 +- 错误码映射 + +--- + +## 5. 结论 + +ArkTS 壳层 POC 最小页面结构固定为: +- 3 个页面:AppListPage / ImportPage / RunPage +- 13 个组件 +- 3 个 Store +- 3 个 Service +- 3 个 Adapter +- 4 个最小模型 + +该结构用于支撑: +- 本地导入 +- 应用列表展示 +- 单实例运行 +- 基础错误反馈