Skip to content

feat(ohos): forward lifecycle events and fix Resumed/Suspended bridge - #14

Open
sb-fy-sb wants to merge 1 commit into
Eulogizethesun:ohdevfrom
sb-fy-sb:feat/ohos-lifecycle-events
Open

feat(ohos): forward lifecycle events and fix Resumed/Suspended bridge#14
sb-fy-sb wants to merge 1 commit into
Eulogizethesun:ohdevfrom
sb-fy-sb:feat/ohos-lifecycle-events

Conversation

@sb-fy-sb

@sb-fy-sb sb-fy-sb commented Jul 2, 2026

Copy link
Copy Markdown

Forward 4 OHOS lifecycle events to tao Event enum:

  • MainEvent::Start → Event::Started
  • MainEvent::SaveState → Event::SaveStateRequested
  • MainEvent::ContentRectChange → Event::ContentRectChanged
  • MainEvent::Pause → Event::Suspended

Also bridge Event::Resumed and Event::Suspended in tauri-runtime-wry, fixing a hidden bug where these events were never forwarded on any mobile platform (Android/iOS/OHOS).

@MingyuChen1 MingyuChen1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OHOS Code Review — tao#14

🔴 🟡 🔵 ℹ️
1 3 1 1

Architecture

cfg gates 正确一致(新 variant 与 ios 的 SceneRequested 模式对齐)。线程安全在现有 RefCell 模型内充分。

⚠️ 依赖 tauri#61 — 转发的事件由 tauri#61 在 tauri-runtime-wry 层消费。两笔 PR 需一起合入。

Findings

🔴 [D3] MainEvent::Stop 被静默丢弃 (mod.rs ~line 464)
openharmony-ability 的 Event 有 Stop 变体(StageEventType::Hidden,ability 进入后台隐藏)。本 PR 的 match 无 MainEvent::Stop arm,落入 unknown => trace。这是真实生命周期状态丢失——app 无法检测后台隐藏。建议添加 arm 或文档化有意丢弃。

🟡 [D3] Resume/SaveState 丢弃 SaveLoader/SaveSaver 句柄 (mod.rs ~line 388, 393)
这两个 MainEvent 携带状态恢复/持久化句柄,本 PR 用 { .. } 丢弃。SaveStateRequested 变为纯通知,app 无法实际写状态。至少文档化状态 I/O 未接通。

🟡 [G1] RectChangeReason.clone() as u32 冗余且有损 (mod.rs ~line 343)
.clone() 不必要,as u32 丢弃枚举类型安全。考虑在 Event::ContentRectChanged 中存储类型化枚举而非裸 u32。

🟡 [D1] Pause -> Suspended 语义可能偏移 (mod.rs ~line 398)
OHOS Pause 是即将进入后台,Stop/Hidden 才是完全后台化。映射 Pause -> Suspended 同时丢弃 Stop,app 看到的 Suspended 比 Android 早。验证是否符合 Tauri 在其他移动平台的 Suspended 语义。

🔵 cfg gates 与 ios 的 SceneRequested 模式一致,无构建破坏

ℹ️ 线程安全 — 所有转发经 self.event_loop.borrow_mut(),与现有 arm 一致

与 tauri#61 一起合入。 请处理 🔴 MainEvent::Stop 丢弃问题。

@sb-fy-sb
sb-fy-sb force-pushed the feat/ohos-lifecycle-events branch from 870886c to 1bf2c68 Compare July 9, 2026 01:37

@MingyuChen1 MingyuChen1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OHOS Code Review — tao#14 (re-review 2026-07-09)

🔴 🟡 🔵 ℹ️
0 0 0 2

概述

把 4 个原 warn!("TODO") 占位的 OHOS 生命周期 MainEvent 实现为真正转发:Start→StartedSaveState→SaveStateRequestedContentRectChange→ContentRectChangedPause→Suspended、并新增 Stop→Suspended。Event 新增 3 个 OHOS 变体均正确 #[cfg(target_env = "ohos")] 门控,Clone/to_static/to_non_exhaustive impl 同步更新。

Pause 与 Stop 都映射到 Suspended(OHOS 双发:Pause=surface 仍在、Stop=完全隐藏),在关联 tauri#61 的 RunEvent::Suspended doc 中已说明并要求 app 幂等——跨 PR 一致,合理。

ℹ️ I1 — RectChangeReason 跨 crate 双映射

platform_impl/ohos/mod.rsopenharmony_ability::RectChangeReason 枚举手动映射为 u32(0-6),tauri#61 app.rs 再用 From<u32> 映射回 tauri 的 RectChangeReason 枚举。enum→u32→enum 中转跨 crate 边界可接受,但若 openharmony_ability 未来新增 RectChangeReason 变体,本 match(无 wildcard)会编译失败——这是编译期 fail-loud,可接受,只需同步更新。

ℹ️ I2 — SaveLoader / SaveSaver 句柄有意丢弃

MainEvent::Resume 的 SaveLoader 与 MainEvent::SaveState 的 SaveSaver 句柄被丢弃,注释说明“state I/O 未接到 app,仅作通知”。属已知阶段限制,注释清晰。后续若要支持状态保存/恢复需补全。

无阻塞问题,可合入(配合 tauri#61)。

Cherry-picked from PR Eulogizethesun#14. Resolved ContentRectChange conflict by
keeping both Resized event (existing functionality) and new
ContentRectChanged lifecycle event.

Co-Authored-By: Claude <noreply@anthropic.com>
@sb-fy-sb
sb-fy-sb force-pushed the feat/ohos-lifecycle-events branch from 1bf2c68 to 1cba253 Compare July 22, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants