Skip to content

feat: add tauri-plugin-ohos-permissions - #15

Open
sb-fy-sb wants to merge 1 commit into
Eulogizethesun:ohdevfrom
sb-fy-sb:ohdev
Open

feat: add tauri-plugin-ohos-permissions#15
sb-fy-sb wants to merge 1 commit into
Eulogizethesun:ohdevfrom
sb-fy-sb:ohdev

Conversation

@sb-fy-sb

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

Copy link
Copy Markdown

OHOS permissions plugin matching tauri-plugin-macos-permissions API:

  • Camera + Microphone: real implementation via abilityAccessCtrl
  • Accessibility + ScreenRecording + InputMonitoring: stub (system_basic)
  • FullDiskAccess: stub (OHOS sandbox has no equivalent)

12 commands: check/request for each of 6 permission types. Includes ACL permissions, guest-js bindings, and test cases.

OHOS permissions plugin matching tauri-plugin-macos-permissions API:
- Camera + Microphone: real implementation via abilityAccessCtrl
- Accessibility + ScreenRecording + InputMonitoring: stub (system_basic)
- FullDiskAccess: stub (OHOS sandbox has no equivalent)

12 commands: check/request for each of 6 permission types.
Includes ACL permissions, guest-js bindings, and test cases.

@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 — plugins-workspace#15

🔴 🟡 🔵 ℹ️
1 1 0 0

🔴 F1 — src/lib.rs: OhosPermissionsExt trait 缺少 cfg 门控 → 桌面平台编译失败

OhosPermissionsExt trait 的声明没有 #[cfg(any(mobile, target_env = "ohos"))] 门控,但其方法签名 fn ohos_permissions(&self) -> &OhosPermissions<R> 引用了 OhosPermissions<R> 类型。该类型仅在 #[cfg(any(mobile, target_env = "ohos"))] 下通过 pub use mobile::OhosPermissions; 引入(且 mod mobile 也被同样门控,crate 内无任何 desktop 分支定义该类型)。

因此在桌面平台(Windows/macOS/Linux,非 mobile 非 ohos)编译此 crate 时,OhosPermissions 不在作用域 → Rust 报 cannot find type OhosPermissions in this scope。对比同仓 notification 插件:其 NotificationExt trait 虽也未门控,但 Notification 类型在 desktopmobile 两个分支都有定义,故桌面可解析。本插件缺少 desktop 分支,偏离了标准模板。

该 crate 在 examples/api/src-tauri/Cargo.toml 中被无条件添加为依赖,会导致桌面 cargo build 失败。

建议:给 trait 声明加 #[cfg(any(mobile, target_env = "ohos"))](与 impl 块一致),或在桌面分支提供一个占位类型/实现。

🟡 F2 — permissions/autogenerated/reference.mdbuild.rs 失同步

自生成的 reference.md 列出了 ohos-permissions:allow-open-permission-settings / deny-open-permission-settings 两个权限(对应 open_permission_settings 命令),但:

  • build.rs 的 COMMANDS 列表不含 open_permission_settings
  • autogenerated/commands/ 下无 open_permission_settings.toml
  • default.toml 不含 allow-open-permission-settings
  • guest-js/index.tsopenPermissionSettings 函数

说明该 reference.md 是更早版本(曾注册过该命令)的残留快照,与同 PR 提交的 build.rs/default.toml 失同步。建议:重新运行构建以重新生成 autogenerated 文件,或补齐/移除 open_permission_settings 命令使其一致。


由 tauri-ohos-pr-babysit 自动巡检生成。详细 inline comments 见下方各文件标注。

/// Extensions to [`tauri::App`], [`tauri::AppHandle`], [`tauri::WebviewWindow`],
/// [`tauri::Webview`] and [`tauri::Window`] to access the OHOS permissions APIs.
pub trait OhosPermissionsExt<R: Runtime> {
fn ohos_permissions(&self) -> &OhosPermissions<R>;

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.

🔴 [G/编译] 此 trait 声明缺少 #[cfg(any(mobile, target_env = "ohos"))] 门控,但其返回类型 OhosPermissions<R> 仅在该 cfg 下通过 pub use mobile::OhosPermissions; 引入。

桌面平台(非 mobile 非 ohos)编译此 crate 时 OhosPermissions 未定义 → cannot find type 编译错误。而本 crate 在 examples/api/src-tauri/Cargo.toml 中被无条件依赖,桌面 cargo build 会失败。

对比 notification 插件:其 Notification 类型在 desktop/mobile 两分支都有定义,故 trait 不门控也能编译。本插件无 desktop 分支,需给 trait 声明补上与 impl 块一致的 cfg 门控(或提供 desktop 占位类型)。

<tr>
<td>

`ohos-permissions:allow-open-permission-settings`

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.

🟡 [H/autogen] 此处列出的 ohos-permissions:allow-open-permission-settings / deny-open-permission-settings 对应的 open_permission_settings 命令,在 build.rs 的 COMMANDS、autogenerated/commands/*.tomldefault.tomlguest-js/index.ts 中均不存在。该自生成文件与同 PR 的源(build.rs)失同步,疑为更早版本残留。

建议重新生成 autogenerated 文件,或补齐/移除该命令使三者一致。

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