Skip to content

Commit

Permalink
feat(api): permission types for mobile plugins
Browse files Browse the repository at this point in the history
let's have a central place to keep the permission types
ref tauri-apps/plugins-workspace#979
  • Loading branch information
lucasfernog committed Aug 27, 2024
1 parent fbe76a9 commit 9250b5b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/api-permissions-plugin.md
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 23 additions & 0 deletions tooling/api/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -249,6 +269,9 @@ export {
Channel,
PluginListener,
addPluginListener,
PermissionState,
checkPermissions,
requestPermissions,
invoke,
convertFileSrc,
isTauri
Expand Down

0 comments on commit 9250b5b

Please sign in to comment.