Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] tauri plugin check permission error #11610

Open
songjiachao opened this issue Nov 7, 2024 · 0 comments
Open

[bug] tauri plugin check permission error #11610

songjiachao opened this issue Nov 7, 2024 · 0 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@songjiachao
Copy link

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
image

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

@songjiachao songjiachao added status: needs triage This issue needs to triage, applied to new issues type: bug labels Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

1 participant