microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.75k stars 28.73k forks source link

Voice: detect missing permissions for microphone use #205721

Open Tyriar opened 7 months ago

Tyriar commented 7 months ago

Testing https://github.com/microsoft/vscode-copilot/issues/4203

Repro:

  1. On macOS
  2. Open chat via cmd+i, macOS mic access popup shows (this was unexpected as I just pressed cmd+i, not held)
  3. Click deny access, 🐛 blue pulse animation shows and doesn't stop
Screenshot 2024-02-20 at 09 08 58

Clicking the mic continues to toggle the state but doesn't actually do any recording. Ideally we would see access is restricted and direct the user to the macOS mic permissions.

bpasero commented 7 months ago

Related: https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/2238

As it turns out we would have to implement this on our own, the library does not provide this information, nor plans to add this in the future.

bpasero commented 7 months ago

I was really hoping that we can detect this using web APIs and I have tried the following (needs [1] for permissions):

navigator.permissions.query(
    { name: 'microphone' } as any
).then(function(permissionStatus){
    console.log(permissionStatus.state); // granted, denied, prompt
})

But this always returns denied. I was then hoping this would do it:

navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => {
    /* permissions */
}).catch((error) => { /* no permissions */ });

But I always seem to be getting a stream even when permissions are not granted.

If someone has more ideas, opening for help wanted.

[1] https://github.com/microsoft/vscode/commit/707bffbdae207740940e86a11b8178978515f9d0#diff-ce90ef6ffd304cc541efa8135dc4878c7b61889d2b2d5ef69e196af6cea7647b

Tyriar commented 7 months ago

@bpasero I'm guessing you would need some mac native code to check the OS-level permissions for the app, the query API giving denied all the time seems correct here as the app is unable to use the mic completely.

bpasero commented 7 months ago

@Tyriar I think the navigator.permissions API should return granted when I did grant permissions, but I also see that not all permissions can be queried like that, so its possible that microphone is not one of them.

I would like to avoid having to write native code for this and ideally find a web solution that works on all platforms. I am sure other apps must have this issue too?

Tyriar commented 7 months ago

Deepak or Matt would know more about using permissions, my experience with it is fairly limited to mainly just clipboard access.

bpasero commented 7 months ago

At least https://developer.mozilla.org/en-US/docs/Web/API/Permissions/query indicates a lot more than just clipboard.