web - clipboard warning when failing access

This commit is contained in:
Benjamin Pasero 2020-12-10 14:16:08 +01:00
parent 86a2311605
commit e6d238e251
2 changed files with 45 additions and 1 deletions

View file

@ -250,6 +250,10 @@
"name": "vs/workbench/services/bulkEdit",
"project": "vscode-workbench"
},
{
"name": "vs/workbench/services/clipboard",
"project": "vscode-workbench"
},
{
"name": "vs/workbench/services/commands",
"project": "vscode-workbench"

View file

@ -3,8 +3,48 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { BrowserClipboardService } from 'vs/platform/clipboard/browser/clipboardService';
import { BrowserClipboardService as BaseBrowserClipboardService } from 'vs/platform/clipboard/browser/clipboardService';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { IOpenerService } from 'vs/platform/opener/common/opener';
export class BrowserClipboardService extends BaseBrowserClipboardService {
constructor(
@INotificationService private readonly notificationService: INotificationService,
@IOpenerService private readonly openerService: IOpenerService
) {
super();
}
async readText(type?: string): Promise<string> {
if (type) {
return super.readText(type);
}
try {
return await navigator.clipboard.readText();
} catch (error) {
// Inform user about permissions problem
// (https://github.com/microsoft/vscode/issues/112089)
this.notificationService.prompt(
Severity.Error,
localize('clipboardError', "Unable to read from the browser's clipboard. Please make sure you have granted access for this website to read from the clipboard."),
[{
label: localize('learnMode', "Learn More"),
run: () => this.openerService.open('https://go.microsoft.com/fwlink/?linkid=2151362')
}],
{
sticky: true
}
);
return '';
}
}
}
registerSingleton(IClipboardService, BrowserClipboardService, true);