feat(api): permission types for mobile plugins (#10799)

* feat(api): permission types for mobile plugins

let's have a central place to keep the permission types
ref https://github.com/tauri-apps/plugins-workspace/issues/979

* build
This commit is contained in:
Lucas Fernandes Nogueira 2024-08-28 11:49:05 -03:00 committed by GitHub
parent d1c97bce7b
commit f81929e251
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"@tauri-apps/api": patch:enhance
---
Added `PermissionState`, `checkPermissions` and `requestPermissions` base APIs to the core module, designed for plugin authors to extend.

File diff suppressed because one or more lines are too long

View File

@ -123,6 +123,26 @@ async function addPluginListener<T>(
)
}
type PermissionState = 'granted' | 'denied' | 'prompt' | 'prompt-with-rationale'
/**
* Get permission state for a plugin.
*
* This should be used by plugin authors to wrap their actual implementation.
*/
async function checkPermissions<T>(plugin: string): Promise<T> {
return invoke(`plugin:${plugin}|check_permissions`)
}
/**
* Request permissions.
*
* This should be used by plugin authors to wrap their actual implementation.
*/
async function requestPermissions<T>(plugin: string): Promise<T> {
return invoke(`plugin:${plugin}|request_permissions`)
}
/**
* Command arguments.
*
@ -249,6 +269,9 @@ export {
Channel,
PluginListener,
addPluginListener,
PermissionState,
checkPermissions,
requestPermissions,
invoke,
convertFileSrc,
isTauri