mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
Add web command to request usb access (#151795)
This experimental command triggers a request for usb devices. After the user selects these, extensions under the extension host can access them using `navigator.usb.getDevices(...)`
This commit is contained in:
@@ -24,6 +24,7 @@ import { IOpenEmptyWindowOptions, IOpenWindowOptions, IWindowOpenable } from 'vs
|
||||
import { IRecent, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { IPathService } from 'vs/workbench/services/path/common/pathService';
|
||||
import { ILocalizedString } from 'vs/platform/action/common/action';
|
||||
import { isWeb } from 'vs/base/common/platform';
|
||||
|
||||
export const ADD_ROOT_FOLDER_COMMAND_ID = 'addRootFolder';
|
||||
export const ADD_ROOT_FOLDER_LABEL: ILocalizedString = { value: localize('addFolderToWorkspace', "Add Folder to Workspace..."), original: 'Add Folder to Workspace...' };
|
||||
@@ -306,3 +307,9 @@ CommandsRegistry.registerCommand('_workbench.getRecentlyOpened', async function
|
||||
|
||||
return workspacesService.getRecentlyOpened();
|
||||
});
|
||||
|
||||
if (isWeb) {
|
||||
CommandsRegistry.registerCommand('workbench.experimental.requestUsbDevice', async (_accessor: ServicesAccessor): Promise<void> => {
|
||||
await (navigator as any).usb.requestDevice({ filters: [] });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -130,6 +130,7 @@ export class WebWorkerExtensionHost extends Disposable implements IExtensionHost
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.setAttribute('class', 'web-worker-ext-host-iframe');
|
||||
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
|
||||
iframe.setAttribute('allow', 'usb');
|
||||
iframe.setAttribute('aria-hidden', 'true');
|
||||
iframe.style.display = 'none';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user