[bug] tauri plugin check permission error
Open
Nobody has claimed this yet.
status: needs triage
type: bug
- Dominant language
- Rust
- Stars
- 111k
- Forks
- 4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 44
Description
Describe the bug
I follow this article to add permission for my plugin
https://tauri.app/develop/plugins/develop-mobile/#permissions
@TauriPlugin(
permissions = [
Permission(strings = [Manifest.permission.ACCESS_FINE_LOCATION], alias = "accessFileLocation")
]
)
class FunProxyPlugin(private val activity: Activity) : Plugin(activity){....}
import { invoke, PermissionState } from '@tauri-apps/api/core';
type PermissionType = 'accessFileLocation' | 'otherPermission'; // 可以扩展其他权限类型
interface Permissions {
[key: string]: PermissionState;
}
const handlePermissionRequest = async (type: PermissionType) => {
const permission = await invoke<Permissions>('plugin:funproxy|checkPermissions');
const state = permission[type];
if (state === 'prompt-with-rationale') {
// 显示解释信息,告诉用户为什么需要这个权限
// 例如弹出对话框或提示用户权限的重要性
}
if (state.startsWith('prompt')) {
await invoke<Permissions>('plugin:funproxy|requestPermissions', { permissions: [type] });
return checkPermission(type); // 请求后重新检查
}
};
export const checkPermission = async (type: PermissionType) => {
try {
await handlePermissionRequest(type);
} catch (error) {
window.$message?.error(error as string);
}
};
export const initPermission = async () => {
// 这里可以添加更多权限类型
await checkPermission('accessFileLocation');
};
But I got this error
Reproduction
No response
Expected behavior
No response
Full tauri info output
❯ cargo tauri info
[✔] Environment
- OS: Mac OS 15.1.0 arm64 (X64)
✔ Xcode Command Line Tools: installed
✔ rustc: 1.82.0 (f6e511eec 2024-10-15)
✔ cargo: 1.82.0 (8f40fc59f 2024-08-21)
✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
✔ Rust toolchain: stable-aarch64-apple-darwin (environment override by RUSTUP_TOOLCHAIN)
- node: 20.18.0
- pnpm: 9.12.3
- npm: 10.8.2
- bun: 1.1.24
[-] Packages
- tauri-cli 🦀: 2.0.2
[-] Plugins
[-] App
Stack trace
No response
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked mobile plugin permissions article and the Kotlin @TauriPlugin declaration, then trace the checkPermissions and requestPermissions calls shown in the TypeScript example. Reproduce the reported permission error using the provided environment details; done means the permission can be checked and requested without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, typescript
- Domain
- mobile-dev, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100