Skip to content

feat(ohos): vibrancy runtime backdropBlur/backgroundColor refresh via AttributeUpdater - #28

Merged
Eulogizethesun merged 1 commit into
Eulogizethesun:ohdevfrom
hardtohavename:ohdev
Jul 9, 2026
Merged

feat(ohos): vibrancy runtime backdropBlur/backgroundColor refresh via AttributeUpdater#28
Eulogizethesun merged 1 commit into
Eulogizethesun:ohdevfrom
hardtohavename:ohdev

Conversation

@hardtohavename

@hardtohavename hardtohavename commented Jun 17, 2026

Copy link
Copy Markdown

Runtime refresh of backdropBlur/backgroundColor for vibrancy effects, plus FnArgs fix for set_window_background_color.

Changes

  • DefaultWebview.ets: BlurModifier (AttributeUpdater<CommonAttribute>) refreshes backdropBlur/backgroundColor at runtime — BuilderNode.update does not refresh these, so modifier.attribute?.backdropBlur(radius) / .backgroundColor(color) triggers an immediate component update. WebBuilder Stack attaches the modifier; setAllWebviewsBlurRadius and updateWebviewStyle use the modifier instead of node.update. EmbeddedWebviewManager.setAllWebviewsBlurRadius is a no-op (embedded path not used for vibrancy).
  • WindowManager.ets: applyWindowBlur now calls controller.setAllWebviewsBlurRadius for already-registered windows (runtime refresh), in addition to queueing pendingBlurs for not-yet-built windows (registerController inject at build time).
  • window/mod.rs: set_window_background_color uses FnArgs (7bd67be fixed set_window_blur with FnArgs but missed set_window_background_color — Acrylic/Mica tints now reach ArkTS).
  • ArkHelper.ets: setWindowBlur catch block no longer calls hilog (NAPI-reentrant context throws "Argc mismatch", masking the original error).

Pairs with tauri PR (Eulogizethesun/tauri#63) for full vibrancy adaptation.

Test results

  • Vibrancy runtime setEffects (Blur/Acrylic/TabbedDark/TabbedLight) + clearEffects: ✅ all apply visually
  • Build-time effects (registerController inject): ✅
  • Tints (Acrylic/Mica) visible and distinct from pure Blur

🤖 Generated with Claude Code

@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 — openharmony-ability#28

🔴 🟡 🔵 ℹ️
0 0 1 0

0.4.0-beta.8 发版 chore:CHANGELOG + LICENSE 修复 + pack.sh 加固。

🔵 F1 [G2] package/LICENSE

LICENSE 从 broken symlink reference(../LICENSE)改为完整 MIT 文本,版权人为 richerfu。pack.sh 的修复逻辑(检测 ../ 前缀则从根 LICENSE 复制)正确且幂等。

建议:确认 richerfu 是本仓的合法版权持有者。若仓有多个贡献者,可能需要补充 Copyright (c) 2025-present richerfu and contributors。另外注意:现在 package/LICENSE 与根 LICENSE 是两份独立副本,后续变更需同步两处(pack.sh 仅在检测到 broken reference 时才同步,不会自动同步正常副本)。

ℹ️ 通过项

  • CHANGELOG 0.4.0-beta.8 条目准确(webPageSnapshot、WebViewExtOhos、timeout 修复)✅
  • pack.sh LICENSE 修复逻辑幂等正确 ✅
  • pack.sh 注释为英文 ✅

@hardtohavename hardtohavename changed the title chore: add 0.4.0-beta.8 changelog, fix LICENSE, improve pack.sh feat(ohos): vibrancy runtime backdropBlur/backgroundColor refresh via AttributeUpdater Jul 7, 2026

@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 — openharmony-ability#28

🔴 🟡 🔵 ℹ️
0 1 0 2

🟡 F1 — ArkHelper.ets setWindowBlur 的 try/catch 吞掉错误,注释关于错误上报的描述不准确

setWindowBlurtry { applyWindowBlur(...) } catch (_err) { /* 注释:错误经 Rust 侧 set_window_blur Err 上报 */ }。但 catch 块既不 rethrow 也不记录,ArkTS 函数正常返回 void。于是 Rust 侧 func.call(FnArgs{...}) 返回 Ok(())(无 JS 异常传播),错误在两侧都丢失——这与注释“error is surfaced via the Rust-side set_window_blur Err return instead”矛盾。

这属于 checklist F3(ArkTS↔Rust 错误传播对称性) 的反模式:ArkTS 端调用失败被吞,Rust 仍返回 Ok(()),导致 Rust 侧认为已生效但实际未生效。

建议:若希望错误真的上报到 Rust,应在 catch 中 throw _err(让 func.call 返回 Err),或返回一个错误码;若确实要静默(因 applyWindowBlur 内部已有兜底),则修正注释,不要声称“经 Rust Err 上报”。

ℹ️ I1 — 本 PR 修复了 set_window_background_color 的 FnArgs bug(跨 PR 依赖)

crates/ability/src/window/mod.rs 行 9-12 把 set_window_background_colorFunction<'_, (i64, u32), ()> + func.call((window_id, color))(裸 tuple,只传 1 个参数)改为 Function<'_, FnArgs<(i64, u32)>, ()> + func.call(FnArgs { data: (window_id, color) })。这正是关联 PR tauri#63 的 openspec/window-vibrancy-plan.md「已知遗留项」中列出的待修复项,也是 window-vibrancy#1 的 acrylic/mica tint 能否生效的前提。

合并顺序提醒:window-vibrancy#1 的 acrylic/mica tint 依赖本 PR 的这个修复。若 window-vibrancy#1 先于本 PR 合入,tint 将不生效。建议本 PR 先合或同批合入。

ℹ️ I2 — PR 标题与内容不符

PR 标题为 “chore: add 0.4.0-beta.8 changelog, fix LICENSE, improve pack.sh”,但最新 commit(2026-07-07)内容是 “feat(ohos): vibrancy runtime backdropBlur/backgroundColor refresh”,实际 diff 全是 vibrancy 相关文件(window/mod.rs、ArkHelper.ets、DefaultWebview.ets、WindowManager.ets 等),无 changelog/LICENSE/pack.sh 改动。疑似 force-push 后标题未更新。建议更新标题以反映实际内容。


整体评价:实现质量高——set_window_blur NAPI 用 FnArgs 正确传参、错误处理完整;ArkTS 侧遵守“NAPI 回调禁用 hilog”约束(setWindowBlur/applyWindowBlur 均 avoid hilog 并注释说明);BlurModifier + AttributeUpdater 的运行时刷新机制与 design.md 一致;EmbeddedWebviewManager 的 no-op 诚实地标注了限制。主要问题是 F1 的错误吞掉+注释矛盾。F1 inline comment 见下方 ArkHelper.ets 标注。

setWindowBlur: (windowId: number, radius: number): void => {
try {
WindowManager.getInstance().applyWindowBlur(windowId, radius);
} catch (_err) {

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.

🟡 [F3] 此注释声称“error is surfaced via the Rust-side set_window_blur Err return instead”,但实际 catch 块不 rethrow,ArkTS setWindowBlur 正常返回 void → Rust func.call(FnArgs{...}) 返回 Ok(())。错误在两侧都丢失,并未上报到 Rust。

这违反 F3(ArkTS↔Rust 错误传播对称性):ArkTS 调用失败被吞,Rust 仍认为已生效。

建议:catch 中 throw _err 让错误经 func.call 返回 Err 上报到 Rust;或若确需静默,修正注释不要声称“经 Rust Err 上报”。

@hardtohavename
hardtohavename force-pushed the ohdev branch 3 times, most recently from 5d9c7de to b30b69d Compare July 7, 2026 08:56

@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 — openharmony-ability#28 (re-review 2026-07-07)

🔴 🟡 🔵 ℹ️
0 0 0 0

✅ F1(上轮 🟡)已解决

上轮指出 ArkHelper.etssetWindowBlur try/catch 吞掉错误,且注释错误地声称“错误经 Rust Err 上报”。

本轮确认:

  1. 注释已修正——准确说明“error is NOT propagated to Rust — set_window_blur uses TSFN fire-and-forget (NonBlocking, no return value wait), so Rust receives Ok regardless”,并给出未来需要同步错误传播时的路径(call_with_return_value + oneshot)。
  2. 架构已重构匹配注释:Rust 侧新增 init_vibrancy_tsfn(在 ArkHelper setup 时调用)+ TSFN_SET_WINDOW_BLUR / TSFN_SET_WINDOW_BG_COLOR 静态 TSFN。set_window_blur / set_window_background_color 改为 TSFN NonBlocking 调用,callee_handled::<false>() + FnArgs 传参,符合 checklist C2/C3/C4。TSFN 可在任意线程调用,不再依赖 thread_local MAIN_THREAD_ENVrun_on_main_thread

附带收益:set_window_background_color 的 FnArgs bug 也随 TSFN 重构一并修复(build_callback 返回 FnArgs { data: ctx.value }),解除了关联 window-vibrancy#1 acrylic/mica tint 的依赖。


无新增问题,可合入。

… AttributeUpdater

- DefaultWebview.ets: BlurModifier (AttributeUpdater<CommonAttribute>) refreshes
  backdropBlur/backgroundColor at runtime — BuilderNode.update does not refresh these,
  so modifier.attribute?.backdropBlur(radius) / .backgroundColor(color) triggers an
  immediate component update. WebBuilder Stack attaches the modifier; setAllWebviewsBlurRadius
  and updateWebviewStyle use the modifier instead of node.update.
- WindowManager.ets: applyWindowBlur now calls controller.setAllWebviewsBlurRadius for
  already-registered windows (runtime refresh), in addition to queueing pendingBlurs
  for not-yet-built windows (registerController inject at build time).
- window/mod.rs: set_window_background_color uses FnArgs (7bd67be fixed set_window_blur
  with FnArgs but missed set_window_background_color — Acrylic/Mica tints now reach ArkTS).

Co-Authored-By: Claude <noreply@anthropic.com>

@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 — openharmony-ability#28 (re-review 2026-07-08)

🔴 🟡 🔵 ℹ️
0 0 0 0

✅ F1(🟡,上轮已解决)维持 + TSFN 初始化入口显式化

本轮新增 crates/ability/src/render/xcomponent.rsrender() 中显式调用 crate::window::init_vibrancy_tsfn(env),确认 TSFN(TSFN_SET_WINDOW_BLUR / TSFN_SET_WINDOW_BG_COLOR)在 NAPI render 初始化阶段建立。set_window_blur / set_window_background_color 仍走 TSFN NonBlocking + FnArgs + callee_handled::<false>()(符合 C2/C3/C4),ArkTS setWindowBlur catch 注释准确(上轮已确认)。

无新增问题。


可合入。本 PR 同时修复了 set_window_background_color 的 FnArgs bug,是关联 window-vibrancy#1 acrylic/mica tint 生效的前提(合并顺序:#28 先于或同批 #1)。

@Eulogizethesun
Eulogizethesun merged commit b8dfbbd into Eulogizethesun:ohdev Jul 9, 2026
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.

3 participants