Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .claude/skills/tauri-ohos-design/references/ohos-constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@
| Tray `rect()` 始终返回 None | StatusBar API 不提供图标位置/尺寸。`AvoidArea.topRect` 返回整个状态栏区域, 不是单个图标 |
| Tray 事件数据有限 | 只有 `iconClickType` ("leftClick"/"rightClick") 和 `menuCode`。无坐标、无双击、无 hover、无中键 |

### 1.5 tao OHOS 层 ExternalError 错误转换限制

| 规则 | 说明 |
|------|------|
| `ExternalError` 无 `From<String>` | tao 的 `ExternalError` 仅 `NotSupported(NotSupportedError)` / `Os(OsError)` 两变体,OHOS `OsError` 是 unit struct(`pub struct OsError;`)不携带消息字符串。**不能** `ExternalError::from(e.to_string())` 编译 |
| ability 函数失败只能 `warn! + NotSupported` | tao OHOS 层调 `openharmony_ability::xxx()` 失败时,用 `warn!` 记录错误详情(`{:?}`),返回 `ExternalError::NotSupported(NotSupportedError::new())`(唯一可用变体) |
| 匹配文件 idiom | 对齐 `set_focus`/`set_focusable`/`set_decorations` 等:`warn!` 记录 + 静默/返回默认值,不携带具体错误消息到上层 |
| Err 仅表示桥接未就绪 | TSFN fire-and-forget 函数(`set_window_blur`/`set_window_touchable` 等)返回 Err 仅当 TSFN 未初始化或 call status 非 Ok(init/编程错误),**不是** 1300002/1300003 运行时失败 — 那些 Promise reject 在 ArkTS `.catch` 捕获、不反向通知 Rust |

> 来源:ohos-window-ignore-cursor-events Phase 2 实现期审计(design D4 原写的 `ExternalError::from(e.to_string())` 无法编译)。

---

## 2. NAPI / TSFN 规则
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
},
{
"name": "ohos.permission.SET_WINDOW_TRANSPARENT"
},
{
"name": "ohos.permission.PRINT"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
},
{
"name": "ohos.permission.SET_WINDOW_TRANSPARENT"
},
{
"name": "ohos.permission.PRINT"
}
]
}
Expand Down
8 changes: 8 additions & 0 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5260,6 +5260,14 @@ You may have it installed on another user account, but it is not available for t
if let Some(window_id) = window.window_id() {
webview_builder = webview_builder.with_window_id(window_id);
}
// Forward use_https_scheme to wry (OHOS branch was missing this — Windows/Android
// branch above sets it, but OHOS didn't, so pl_attrs.use_https was always false
// and rewrite_https_url_if_matching never triggered). See ohos-webview-https-scheme.
webview_builder = webview_builder.with_https_scheme(webview_attributes.use_https_scheme);
// Forward drag_drop_overlay to wry (OHOS-only: transparent Stack that receives
// ArkUI drag events when ArkWeb doesn't bubble OS file drags to Web handlers).
// See ohos-webview-drag-drop-overlay.
webview_builder = webview_builder.with_drag_drop_overlay(webview_attributes.drag_drop_overlay);
}

if let Some(background_throttling) = webview_attributes.background_throttling {
Expand Down
19 changes: 19 additions & 0 deletions crates/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ pub struct WebviewAttributes {
pub initialization_scripts: Vec<InitializationScript>,
pub data_directory: Option<PathBuf>,
pub drag_drop_handler_enabled: bool,
/// Whether to render a transparent overlay Stack that receives ArkUI drag events
/// and forwards them to drag_drop_handler. OHOS-only (ArkWeb may not bubble OS file
/// drags to Web-level handlers; the overlay is the fallback). See ohos-webview-drag-drop-overlay.
#[cfg(target_env = "ohos")]
pub drag_drop_overlay: bool,
pub clipboard: bool,
pub accept_first_mouse: bool,
pub additional_browser_args: Option<String>,
Expand Down Expand Up @@ -519,6 +524,8 @@ impl WebviewAttributes {
initialization_scripts: Vec::new(),
data_directory: None,
drag_drop_handler_enabled: true,
#[cfg(target_env = "ohos")]
drag_drop_overlay: false,
clipboard: false,
accept_first_mouse: false,
additional_browser_args: None,
Expand Down Expand Up @@ -744,6 +751,18 @@ impl WebviewAttributes {
self
}

/// Sets whether to render a transparent drag-drop overlay (OHOS-only).
///
/// When enabled, a transparent Stack with `HitTestMode.Transparent` is rendered
/// above the Web component to receive ArkUI drag events (ArkWeb may not bubble
/// OS file drags to Web-level handlers). Pointer events pass through to the Web.
#[cfg(target_env = "ohos")]
#[must_use]
pub fn drag_drop_overlay(mut self, enabled: bool) -> Self {
self.drag_drop_overlay = enabled;
self
}

/// Whether web inspector, which is usually called browser devtools, is enabled or not. Enabled by default.
///
/// This API works in **debug** builds, but requires `devtools` feature flag to enable it in **release** builds.
Expand Down
12 changes: 12 additions & 0 deletions crates/tauri/src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,18 @@ fn main() {
self
}

/// Sets whether to render a transparent drag-drop overlay (OHOS-only).
///
/// When enabled, a transparent Stack with `HitTestMode.Transparent` is rendered
/// above the Web component to receive ArkUI drag events (ArkWeb may not bubble
/// OS file drags to Web-level handlers). Pointer events pass through to the Web.
#[cfg(target_env = "ohos")]
#[must_use]
pub fn drag_drop_overlay(mut self, enabled: bool) -> Self {
self.webview_attributes.drag_drop_overlay = enabled;
self
}

/// Whether web inspector, which is usually called browser devtools, is enabled or not. Enabled by default.
///
/// This API works in **debug** builds, but requires `devtools` feature flag to enable it in **release** builds.
Expand Down
6 changes: 4 additions & 2 deletions crates/tauri/src/webview/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ mod desktop_commands {
pub fn init<R: Runtime>() -> TauriPlugin<R> {
#[allow(unused_mut)]
let mut init_script = String::new();
// window.print works on Linux/Windows; need to use the API on macOS
#[cfg(any(target_os = "macos", target_os = "ios"))]
// window.print works on Linux/Windows; need to use the API on macOS/iOS/OHOS.
// OHOS ArkWeb has no native window.print, so the print.js shim (which invokes
// plugin:webview|print → wry OHOS print → createPdf → @ohos.print) is required.
#[cfg(any(target_os = "macos", target_os = "ios", target_env = "ohos"))]
{
init_script.push_str(include_str!("./scripts/print.js"));
}
Expand Down
12 changes: 12 additions & 0 deletions crates/tauri/src/webview/webview_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,18 @@ impl<R: Runtime, M: Manager<R>> WebviewWindowBuilder<'_, R, M> {
self
}

/// Sets whether to render a transparent drag-drop overlay (OHOS-only).
///
/// When enabled, a transparent Stack with `HitTestMode.Transparent` is rendered
/// above the Web component to receive ArkUI drag events. Pointer events pass
/// through to the Web. See `WebviewBuilder::drag_drop_overlay`.
#[cfg(target_env = "ohos")]
#[must_use]
pub fn drag_drop_overlay(mut self, enabled: bool) -> Self {
self.webview_builder = self.webview_builder.drag_drop_overlay(enabled);
self
}

/// Whether web inspector, which is usually called browser devtools, is enabled or not. Enabled by default.
///
/// This API works in **debug** builds, but requires `devtools` feature flag to enable it in **release** builds.
Expand Down
Loading
Loading