From 91f00c7c285ecd85a8d86298183180703d719486 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 10 Dec 2020 15:38:28 +0100 Subject: [PATCH] web - allow to retry clipboard access (#112089) --- .../browser/parts/editor/editorCommands.ts | 2 +- src/vs/workbench/electron-sandbox/window.ts | 2 +- .../clipboard/browser/clipboardService.ts | 43 ++++++++++++------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/editorCommands.ts b/src/vs/workbench/browser/parts/editor/editorCommands.ts index dcece5343cb..c5f41f76c02 100644 --- a/src/vs/workbench/browser/parts/editor/editorCommands.ts +++ b/src/vs/workbench/browser/parts/editor/editorCommands.ts @@ -917,7 +917,7 @@ function registerOtherEditorCommands(): void { nls.localize('enablePreview', "Preview editors have been enabled in settings.") : nls.localize('disablePreview', "Preview editors have been disabled in settings."), [{ - label: nls.localize('learnMode', "Learn More"), run: () => openerService.open('https://go.microsoft.com/fwlink/?linkid=2147473') + label: nls.localize('learnMore', "Learn More"), run: () => openerService.open('https://go.microsoft.com/fwlink/?linkid=2147473') }] ); } diff --git a/src/vs/workbench/electron-sandbox/window.ts b/src/vs/workbench/electron-sandbox/window.ts index 9242ca0b6d6..d7de3cb071d 100644 --- a/src/vs/workbench/electron-sandbox/window.ts +++ b/src/vs/workbench/electron-sandbox/window.ts @@ -188,7 +188,7 @@ export class NativeWindow extends Disposable { // Shell Environment Issue Notifications const choices: IPromptChoice[] = [{ - label: localize('learnMode', "Learn More"), + label: localize('learnMore', "Learn More"), run: () => this.openerService.open('https://go.microsoft.com/fwlink/?linkid=2149667') }]; diff --git a/src/vs/workbench/services/clipboard/browser/clipboardService.ts b/src/vs/workbench/services/clipboard/browser/clipboardService.ts index 41050ea665a..89c532dec2e 100644 --- a/src/vs/workbench/services/clipboard/browser/clipboardService.ts +++ b/src/vs/workbench/services/clipboard/browser/clipboardService.ts @@ -9,6 +9,8 @@ import { IClipboardService } from 'vs/platform/clipboard/common/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'; +import { once } from 'vs/base/common/functional'; +import { DisposableStore } from 'vs/base/common/lifecycle'; export class BrowserClipboardService extends BaseBrowserClipboardService { @@ -27,22 +29,31 @@ export class BrowserClipboardService extends BaseBrowserClipboardService { 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 ''; + return new Promise(resolve => { + + // Inform user about permissions problem (https://github.com/microsoft/vscode/issues/112089) + const listener = new DisposableStore(); + const handle = 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('retry', "Retry"), + run: async () => { + listener.dispose(); + resolve(await this.readText(type)); + } + }, { + label: localize('learnMore', "Learn More"), + run: () => this.openerService.open('https://go.microsoft.com/fwlink/?linkid=2151362') + }], + { + sticky: true + } + ); + + // Always resolve the promise once the notification closes + listener.add(once(handle.onDidClose)(() => resolve(''))); + }); } } } -- GitLab