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
29 changes: 29 additions & 0 deletions plugins/ohos-permissions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "tauri-plugin-ohos-permissions"
version = "0.1.0"
description = "Check and request OHOS system permissions (Camera, Microphone, etc.) in Tauri applications."
edition = { workspace = true }
authors = { workspace = true }
license = { workspace = true }
rust-version = { workspace = true }
repository = { workspace = true }
links = "tauri-plugin-ohos-permissions"

[package.metadata.docs.rs]
targets = ["aarch64-unknown-linux-ohos"]

[package.metadata.platforms.support]
windows = { level = "none", notes = "Stub only — all checks return true." }
linux = { level = "none", notes = "Stub only — all checks return true." }
macos = { level = "none", notes = "Stub only — all checks return true. Use tauri-plugin-macos-permissions instead." }
android = { level = "none", notes = "Not implemented." }
ios = { level = "none", notes = "Not implemented." }
ohos = { level = "partial", notes = "Camera and Microphone via abilityAccessCtrl. Accessibility/ScreenRecording/InputMonitoring in Phase 2." }

[build-dependencies]
tauri-plugin = { workspace = true, features = ["build"] }

[dependencies]
tauri = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
1 change: 1 addition & 0 deletions plugins/ohos-permissions/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions plugins/ohos-permissions/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

const COMMANDS: &[&str] = &[
"check_accessibility_permission",
"request_accessibility_permission",
"check_camera_permission",
"request_camera_permission",
"check_microphone_permission",
"request_microphone_permission",
"check_full_disk_access_permission",
"request_full_disk_access_permission",
"check_screen_recording_permission",
"request_screen_recording_permission",
"check_input_monitoring_permission",
"request_input_monitoring_permission",
];

fn main() {
tauri_plugin::Builder::new(COMMANDS)
.ohos_path("openharmony")
.build();
}
117 changes: 117 additions & 0 deletions plugins/ohos-permissions/guest-js/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

/**
* Check and request OHOS system permissions.
*
* @module
*/

import { invoke } from '@tauri-apps/api/core'

// ─── Accessibility (stub: OHOS third-party apps cannot register accessibility services) ───

/**
* Check accessibility permission.
*
* OHOS `AccessibilityExtensionAbility` is deprecated since API 12.
* Always returns `false` for third-party apps.
*/
export async function checkAccessibilityPermission(): Promise<boolean> {
return invoke<boolean>('plugin:ohos-permissions|check_accessibility_permission')
}

/**
* Request accessibility permission.
*
* OHOS has no equivalent API. This is a no-op.
*/
export async function requestAccessibilityPermission(): Promise<void> {
await invoke('plugin:ohos-permissions|request_accessibility_permission')
}

// ─── Camera ───

export async function checkCameraPermission(): Promise<boolean> {
return invoke<boolean>('plugin:ohos-permissions|check_camera_permission')
}

export async function requestCameraPermission(): Promise<void> {
await invoke('plugin:ohos-permissions|request_camera_permission')
}

// ─── Microphone ───

export async function checkMicrophonePermission(): Promise<boolean> {
return invoke<boolean>('plugin:ohos-permissions|check_microphone_permission')
}

export async function requestMicrophonePermission(): Promise<void> {
await invoke('plugin:ohos-permissions|request_microphone_permission')
}

// ─── Full Disk Access (stub: OHOS has no equivalent) ───

/**
* Check full disk access permission.
*
* OHOS has a different sandbox model and no equivalent concept.
* Always returns `true`.
*/
export async function checkFullDiskAccessPermission(): Promise<boolean> {
return invoke<boolean>('plugin:ohos-permissions|check_full_disk_access_permission')
}

/**
* Request full disk access permission.
*
* OHOS has no equivalent operation. This is a no-op.
*/
export async function requestFullDiskAccessPermission(): Promise<void> {
await invoke('plugin:ohos-permissions|request_full_disk_access_permission')
}

// ─── Screen Recording (stub: system_basic, unavailable to third-party apps) ───

/**
* Check screen recording permission.
*
* OHOS `ohos.permission.CAPTURE_SCREEN` is `system_basic` level.
* Always returns `false` for third-party apps.
*/
export async function checkScreenRecordingPermission(): Promise<boolean> {
return invoke<boolean>('plugin:ohos-permissions|check_screen_recording_permission')
}

/**
* Request screen recording permission.
*
* OHOS `ohos.permission.CAPTURE_SCREEN` is `system_basic` level.
* This is a no-op for third-party apps.
*/
export async function requestScreenRecordingPermission(): Promise<void> {
await invoke('plugin:ohos-permissions|request_screen_recording_permission')
}

// ─── Input Monitoring (stub: system_basic, unavailable to third-party apps) ───

/**
* Check input monitoring permission.
*
* OHOS `ohos.permission.INPUT_MONITORING` is `system_basic` level.
* Always returns `false` for third-party apps.
*/
export async function checkInputMonitoringPermission(): Promise<boolean> {
return invoke<boolean>('plugin:ohos-permissions|check_input_monitoring_permission')
}

/**
* Request input monitoring permission.
*
* OHOS `ohos.permission.INPUT_MONITORING` is `system_basic` level.
* This is a no-op for third-party apps.
*/
export async function requestInputMonitoringPermission(): Promise<void> {
await invoke('plugin:ohos-permissions|request_input_monitoring_permission')
}
29 changes: 29 additions & 0 deletions plugins/ohos-permissions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@tauri-apps/plugin-ohos-permissions",
"version": "0.1.0",
"license": "MIT OR Apache-2.0",
"authors": [
"Tauri Programme within The Commons Conservancy"
],
"repository": "https://github.com/tauri-apps/plugins-workspace",
"type": "module",
"types": "./dist-js/index.d.ts",
"main": "./dist-js/index.cjs",
"module": "./dist-js/index.js",
"exports": {
"types": "./dist-js/index.d.ts",
"import": "./dist-js/index.js",
"require": "./dist-js/index.cjs"
},
"scripts": {
"build": "rollup -c"
},
"files": [
"dist-js",
"README.md",
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "^2.11.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-check-accessibility-permission"
description = "Enables the check_accessibility_permission command without any pre-configured scope."
commands.allow = ["check_accessibility_permission"]

[[permission]]
identifier = "deny-check-accessibility-permission"
description = "Denies the check_accessibility_permission command without any pre-configured scope."
commands.deny = ["check_accessibility_permission"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-check-camera-permission"
description = "Enables the check_camera_permission command without any pre-configured scope."
commands.allow = ["check_camera_permission"]

[[permission]]
identifier = "deny-check-camera-permission"
description = "Denies the check_camera_permission command without any pre-configured scope."
commands.deny = ["check_camera_permission"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-check-full-disk-access-permission"
description = "Enables the check_full_disk_access_permission command without any pre-configured scope."
commands.allow = ["check_full_disk_access_permission"]

[[permission]]
identifier = "deny-check-full-disk-access-permission"
description = "Denies the check_full_disk_access_permission command without any pre-configured scope."
commands.deny = ["check_full_disk_access_permission"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-check-input-monitoring-permission"
description = "Enables the check_input_monitoring_permission command without any pre-configured scope."
commands.allow = ["check_input_monitoring_permission"]

[[permission]]
identifier = "deny-check-input-monitoring-permission"
description = "Denies the check_input_monitoring_permission command without any pre-configured scope."
commands.deny = ["check_input_monitoring_permission"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-check-microphone-permission"
description = "Enables the check_microphone_permission command without any pre-configured scope."
commands.allow = ["check_microphone_permission"]

[[permission]]
identifier = "deny-check-microphone-permission"
description = "Denies the check_microphone_permission command without any pre-configured scope."
commands.deny = ["check_microphone_permission"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-check-screen-recording-permission"
description = "Enables the check_screen_recording_permission command without any pre-configured scope."
commands.allow = ["check_screen_recording_permission"]

[[permission]]
identifier = "deny-check-screen-recording-permission"
description = "Denies the check_screen_recording_permission command without any pre-configured scope."
commands.deny = ["check_screen_recording_permission"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-request-accessibility-permission"
description = "Enables the request_accessibility_permission command without any pre-configured scope."
commands.allow = ["request_accessibility_permission"]

[[permission]]
identifier = "deny-request-accessibility-permission"
description = "Denies the request_accessibility_permission command without any pre-configured scope."
commands.deny = ["request_accessibility_permission"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-request-camera-permission"
description = "Enables the request_camera_permission command without any pre-configured scope."
commands.allow = ["request_camera_permission"]

[[permission]]
identifier = "deny-request-camera-permission"
description = "Denies the request_camera_permission command without any pre-configured scope."
commands.deny = ["request_camera_permission"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-request-full-disk-access-permission"
description = "Enables the request_full_disk_access_permission command without any pre-configured scope."
commands.allow = ["request_full_disk_access_permission"]

[[permission]]
identifier = "deny-request-full-disk-access-permission"
description = "Denies the request_full_disk_access_permission command without any pre-configured scope."
commands.deny = ["request_full_disk_access_permission"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-request-input-monitoring-permission"
description = "Enables the request_input_monitoring_permission command without any pre-configured scope."
commands.allow = ["request_input_monitoring_permission"]

[[permission]]
identifier = "deny-request-input-monitoring-permission"
description = "Denies the request_input_monitoring_permission command without any pre-configured scope."
commands.deny = ["request_input_monitoring_permission"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-request-microphone-permission"
description = "Enables the request_microphone_permission command without any pre-configured scope."
commands.allow = ["request_microphone_permission"]

[[permission]]
identifier = "deny-request-microphone-permission"
description = "Denies the request_microphone_permission command without any pre-configured scope."
commands.deny = ["request_microphone_permission"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-request-screen-recording-permission"
description = "Enables the request_screen_recording_permission command without any pre-configured scope."
commands.allow = ["request_screen_recording_permission"]

[[permission]]
identifier = "deny-request-screen-recording-permission"
description = "Denies the request_screen_recording_permission command without any pre-configured scope."
commands.deny = ["request_screen_recording_permission"]
Loading