-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Add permissions.request #3296
Add permissions.request #3296
Conversation
13991a1
to
82d03c8
Compare
I have a side question: so with recent changes we don't show prompt by default (but instead fail with |
@kt3k I'm happy to have this feature - but it needs some test. We removed the interactive prompt tests in 8f571ef. Ideally this would be done in Rust using something like nix::pty::openpty(). |
}); | ||
set_prompt_result(false); | ||
assert_eq!(perms1.request_hrtime(), PermissionAccessorState::Deny); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry - I didn't see these tests when I wrote my previous comment.
But these still don't seem to be using openpty... I need to look into it more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests replace permission_prompt
with stub function and its returning values are controlled by set_prompt_result
calls.
@bartlomieju I think this isn't simply step backward compared to the previous API with |
Thanks for the answer, let me rephrase my concern: with |
No such way as long as the program is started from interactive terminal.
The prompt function checks the tty of stdin and stderr. So if we start the program from a non-tty environment, the program fails without displaying a prompt. I think most production envrionments don't have a tty terminal, so I don't think this cause that problem (stuck at prompt) such often. |
async request(desc: PermissionDescriptor): Promise<PermissionStatus> { | ||
const { state } = sendSync(dispatch.OP_REQUEST_PERMISSION, desc); | ||
return new PermissionStatus(state); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be added to lib.deno_runtime.d.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight error in the example too. I got this when trying to run it:
️⚠️ Deno requests to access to environment variables.. Grant? [g/d (g = grant, d = deny)] g
error: Uncaught ReferenceError: home is not defined
► file:///Users/rld/src/deno/x.js:3:8
3 home = Deno.homeDir();
^
at file:///Users/rld/src/deno/x.js:3:8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for catching!
cli/js/lib.deno_runtime.d.ts
Outdated
/** Requests the permission. | ||
* const status = await Deno.permissions.request({ name: "env" }); | ||
* if (status.state === "granted") { | ||
* home = Deno.homeDir(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you make this line console.log(Deno.homeDir()) then this snippet of code becomes copy/paste able
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Makes sense. I'll update!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR implements
permissions.request
API based on WICG's permissions-request spec. This PR follows #3200closes #2767 (though it's already closed).