diff options
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/dispatch.ts | 1 | ||||
-rw-r--r-- | cli/js/lib.deno_runtime.d.ts | 9 | ||||
-rw-r--r-- | cli/js/permissions.ts | 13 |
3 files changed, 23 insertions, 0 deletions
diff --git a/cli/js/dispatch.ts b/cli/js/dispatch.ts index d66467011..c2690ad32 100644 --- a/cli/js/dispatch.ts +++ b/cli/js/dispatch.ts @@ -38,6 +38,7 @@ export let OP_GLOBAL_TIMER: number; export let OP_NOW: number; export let OP_QUERY_PERMISSION: number; export let OP_REVOKE_PERMISSION: number; +export let OP_REQUEST_PERMISSION: number; export let OP_CREATE_WORKER: number; export let OP_HOST_GET_WORKER_CLOSED: number; export let OP_HOST_POST_MESSAGE: number; diff --git a/cli/js/lib.deno_runtime.d.ts b/cli/js/lib.deno_runtime.d.ts index 1f01f1384..87da83e9a 100644 --- a/cli/js/lib.deno_runtime.d.ts +++ b/cli/js/lib.deno_runtime.d.ts @@ -933,6 +933,15 @@ declare namespace Deno { * assert(status.state !== "granted") */ revoke(d: PermissionDescriptor): Promise<PermissionStatus>; + /** Requests the permission. + * const status = await Deno.permissions.request({ name: "env" }); + * if (status.state === "granted") { + * console.log(Deno.homeDir()); + * } else { + * console.log("'env' permission is denied."); + * } + */ + request(desc: PermissionDescriptor): Promise<PermissionStatus>; } export const permissions: Permissions; diff --git a/cli/js/permissions.ts b/cli/js/permissions.ts index 16ea3e5c2..c3530e970 100644 --- a/cli/js/permissions.ts +++ b/cli/js/permissions.ts @@ -68,6 +68,19 @@ export class Permissions { const { state } = sendSync(dispatch.OP_REVOKE_PERMISSION, desc); return new PermissionStatus(state); } + + /** Requests the permission. + * const status = await Deno.permissions.request({ name: "env" }); + * if (status.state === "granted") { + * console.log(Deno.homeDir()); + * } else { + * console.log("'env' permission is denied."); + * } + */ + async request(desc: PermissionDescriptor): Promise<PermissionStatus> { + const { state } = sendSync(dispatch.OP_REQUEST_PERMISSION, desc); + return new PermissionStatus(state); + } } export const permissions = new Permissions(); |