diff --git a/docs/product/ARKTS_RUNTIME_IMPORT_RESET_PROGRESS_V0.md b/docs/product/ARKTS_RUNTIME_IMPORT_RESET_PROGRESS_V0.md new file mode 100644 index 0000000..e4cf66c --- /dev/null +++ b/docs/product/ARKTS_RUNTIME_IMPORT_RESET_PROGRESS_V0.md @@ -0,0 +1,27 @@ +# RunPage mock 启动过渡与 ImportPage 重置进展 v0 + +项目:MRP 模拟器鸿蒙化 +角色:RD Frontend + +## 本轮完成 + +### 1. Runtime mock 启动过渡已补齐 +- `NativeRuntimeAdapter.startSession()` 增加 600ms mock 延迟 +- `NativeRuntimeAdapter.restartSession()` 增加 400ms mock 延迟 +- `RuntimeSessionStore` 在 start/restart 时显式进入 `starting` +- 运行页现在可观察到 `starting -> running` 状态过渡 + +### 2. ImportPage 返回/成功后重置已补齐 +- 新增 `onBackClick()` +- 返回列表前调用 `store.reset()` +- 导入成功后先 `store.reset()` 再回调 `onImportSuccess()` +- `aboutToDisappear()` 兜底重置导入态 + +## 当前结论 +- 运行页已具备最小 mock 启动状态演示能力 +- 导入页不会把旧预览/旧错误带回下一轮导入 + +## 下一步 +1. 让 RunPage 在不可 restart 时禁用重启按钮 +2. 给 AppList 增加“导入成功后新应用高亮”占位 +3. 补一份 POC 演示路径说明 diff --git a/entry/src/main/ets/adapters/NativeRuntimeAdapter.ts b/entry/src/main/ets/adapters/NativeRuntimeAdapter.ts index 1ae3e91..9a63dbc 100644 --- a/entry/src/main/ets/adapters/NativeRuntimeAdapter.ts +++ b/entry/src/main/ets/adapters/NativeRuntimeAdapter.ts @@ -1,10 +1,12 @@ +const sleep = (ms: number): Promise => new Promise((resolve) => setTimeout(resolve, ms)) + export class NativeRuntimeAdapter { async startSession(_appId: string): Promise { - return + await sleep(600) } async restartSession(_appId: string): Promise { - return + await sleep(400) } async stopSession(): Promise { diff --git a/entry/src/main/ets/pages/ImportPage.ets b/entry/src/main/ets/pages/ImportPage.ets index 5a6bbdc..cd9e363 100644 --- a/entry/src/main/ets/pages/ImportPage.ets +++ b/entry/src/main/ets/pages/ImportPage.ets @@ -28,6 +28,14 @@ export struct ImportPage { this.unsubscribe() this.unsubscribe = undefined } + this.store.reset() + } + + private onBackClick(): void { + this.store.reset() + if (this.onBack) { + this.onBack() + } } private async onPickFile(): Promise { @@ -37,8 +45,11 @@ export struct ImportPage { private async onImport(): Promise { await this.store.startImport() - if (this.store.phase === 'success' && this.onImportSuccess) { - this.onImportSuccess() + if (this.store.phase === 'success') { + this.store.reset() + if (this.onImportSuccess) { + this.onImportSuccess() + } } } @@ -48,7 +59,7 @@ export struct ImportPage { PageHeader({ title: '导入应用' }) if (this.onBack) { Button('返回列表').onClick(() => { - this.onBack && this.onBack() + this.onBackClick() }).margin({ bottom: 8, left: 16, right: 16 }) } if (this.store.error) { diff --git a/entry/src/main/ets/store/RuntimeSessionStore.ts b/entry/src/main/ets/store/RuntimeSessionStore.ts index 0690be1..0456e54 100644 --- a/entry/src/main/ets/store/RuntimeSessionStore.ts +++ b/entry/src/main/ets/store/RuntimeSessionStore.ts @@ -18,6 +18,8 @@ export class RuntimeSessionStore extends StoreObserver { this.currentAppId = appId this.phase = 'starting' this.error = null + this.canRestart = false + this.canExit = false this.notify() try { await this.service.start(appId) @@ -35,9 +37,15 @@ export class RuntimeSessionStore extends StoreObserver { if (!this.currentAppId) { return } + this.phase = 'starting' + this.error = null + this.canRestart = false + this.notify() try { await this.service.restart(this.currentAppId) this.phase = 'running' + this.canRestart = true + this.canExit = true } catch (_error) { this.phase = 'error' this.error = { message: '重启失败', retryable: true }