feat: connect run page to native smoke startup flow

This commit is contained in:
OpenClaw committed 2026-03-09 18:39:38 +08:00
1 parent 06f4a95020
commit a14b10d62f
4 files changed
+52 -14

No files matched your search

@@ -1,23 +1,43 @@
const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms)) import nativeMrp from 'libmrp_napi.so'
function assertOk(result: { ok: boolean; errorCode?: number; errorMessage?: string }, action: string): void {
if (!result.ok) {
throw new Error(`${action} failed: ${result.errorCode ?? -1} ${result.errorMessage ?? ''}`.trim())
}
}
export class NativeRuntimeAdapter { export class NativeRuntimeAdapter {
async startSession(_appId: string): Promise<void> { async startSession(appId: string): Promise<void> {
await sleep(600) assertOk(nativeMrp.init({
workDir: '/data/storage/el2/base/files/mrp',
width: 240,
height: 320,
debug: true,
}), 'init')
assertOk(nativeMrp.loadPackage(appId), 'loadPackage')
assertOk(nativeMrp.start(), 'start')
} }
async restartSession(_appId: string): Promise<void> { async restartSession(appId: string): Promise<void> {
await sleep(400) await this.stopSession()
await this.startSession(appId)
} }
async stopSession(): Promise<void> { async stopSession(): Promise<void> {
return assertOk(nativeMrp.release(), 'release')
} }
async notifyPageShow(): Promise<void> { async notifyPageShow(): Promise<void> {
return const result = nativeMrp.resume()
if (!result.ok) {
return
}
} }
async notifyPageHide(): Promise<void> { async notifyPageHide(): Promise<void> {
return const result = nativeMrp.pause()
if (!result.ok) {
return
}
} }
} }
@@ -1,10 +1,19 @@
@Component @Component
export struct RuntimeContainer { export struct RuntimeContainer {
@Prop hint: string = 'Runtime Surface Placeholder'
build() { build() {
Column() { Column({ space: 12 }) {
Text('Runtime Surface Placeholder') Text('MRP Runtime Surface Placeholder')
.fontSize(18)
.fontWeight(FontWeight.Medium)
Text(this.hint)
.fontSize(14)
.fontColor('#666666')
} }
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Center)
.width('100%') .width('100%')
.height('100%') .layoutWeight(1)
} }
} }
+2 -1
View File
@@ -59,6 +59,7 @@ export struct RunPage {
if (this.appId) { if (this.appId) {
StatusBanner({ text: `当前应用:${this.appId}` }) StatusBanner({ text: `当前应用:${this.appId}` })
} }
StatusBanner({ text: this.store.runtimeHint })
if (this.store.error) { if (this.store.error) {
StatusBanner({ text: this.store.error.message }) StatusBanner({ text: this.store.error.message })
} }
@@ -67,7 +68,7 @@ export struct RunPage {
onRestart: () => this.onRestart(), onRestart: () => this.onRestart(),
onExit: () => this.onExit() onExit: () => this.onExit()
}) })
RuntimeContainer() RuntimeContainer({ hint: this.store.runtimeHint })
if (this.store.phase !== 'running') { if (this.store.phase !== 'running') {
RuntimeStatusOverlay({ text: `当前状态:${this.store.phase}` }) RuntimeStatusOverlay({ text: `当前状态:${this.store.phase}` })
} }
@@ -9,6 +9,7 @@ export class RuntimeSessionStore extends StoreObserver {
error: UiError | null = null error: UiError | null = null
canRestart: boolean = false canRestart: boolean = false
canExit: boolean = false canExit: boolean = false
runtimeHint: string = '等待启动'
constructor(private readonly service: RuntimeService = new RuntimeService()) { constructor(private readonly service: RuntimeService = new RuntimeService()) {
super() super()
@@ -20,15 +21,18 @@ export class RuntimeSessionStore extends StoreObserver {
this.error = null this.error = null
this.canRestart = false this.canRestart = false
this.canExit = false this.canExit = false
this.runtimeHint = '正在初始化 Native/NAPI...'
this.notify() this.notify()
try { try {
await this.service.start(appId) await this.service.start(appId)
this.phase = 'running' this.phase = 'running'
this.canRestart = true this.canRestart = true
this.canExit = true this.canExit = true
} catch (_error) { this.runtimeHint = 'Native/NAPI 已连通,可进入后续拉帧联调'
} catch (error) {
this.phase = 'error' this.phase = 'error'
this.error = { message: '启动失败', retryable: true } this.error = { message: '启动失败', retryable: true }
this.runtimeHint = error instanceof Error ? error.message : 'Native/NAPI 启动失败'
} }
this.notify() this.notify()
} }
@@ -40,15 +44,18 @@ export class RuntimeSessionStore extends StoreObserver {
this.phase = 'starting' this.phase = 'starting'
this.error = null this.error = null
this.canRestart = false this.canRestart = false
this.runtimeHint = '正在重启 Native/NAPI...'
this.notify() this.notify()
try { try {
await this.service.restart(this.currentAppId) await this.service.restart(this.currentAppId)
this.phase = 'running' this.phase = 'running'
this.canRestart = true this.canRestart = true
this.canExit = true this.canExit = true
} catch (_error) { this.runtimeHint = '重启完成,Native/NAPI 仍可用'
} catch (error) {
this.phase = 'error' this.phase = 'error'
this.error = { message: '重启失败', retryable: true } this.error = { message: '重启失败', retryable: true }
this.runtimeHint = error instanceof Error ? error.message : '重启失败'
} }
this.notify() this.notify()
} }
@@ -58,6 +65,7 @@ export class RuntimeSessionStore extends StoreObserver {
this.phase = 'stopped' this.phase = 'stopped'
this.canExit = false this.canExit = false
this.canRestart = false this.canRestart = false
this.runtimeHint = '运行会话已释放'
this.notify() this.notify()
} }