Add permissions.request (#3296)

This commit is contained in:
Yoshiya Hinosawa 2019-11-12 00:33:29 +09:00 committed by Ry Dahl
parent b3baab6d14
commit 31115067cd
5 changed files with 393 additions and 64 deletions

View file

@ -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();