From d3405c46e74ffe27cbd19db9f36570d0b31b8746 Mon Sep 17 00:00:00 2001 From: SteVen Batten Date: Fri, 1 Nov 2019 19:48:14 -0700 Subject: [PATCH] add reload window button to reconnection dialog --- .../contrib/remote/browser/remote.ts | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/contrib/remote/browser/remote.ts b/src/vs/workbench/contrib/remote/browser/remote.ts index fa38183f29d15..4d17af30bd3e2 100644 --- a/src/vs/workbench/contrib/remote/browser/remote.ts +++ b/src/vs/workbench/contrib/remote/browser/remote.ts @@ -525,7 +525,7 @@ class RemoteAgentConnectionStatusListener implements IWorkbenchContribution { let reconnectWaitEvent: ReconnectionWaitEvent | null = null; let disposableListener: IDisposable | null = null; - function showProgress(location: ProgressLocation, buttons?: string[]) { + function showProgress(location: ProgressLocation, buttons: { label: string, callback: () => void }[]) { if (currentProgressPromiseResolve) { currentProgressPromiseResolve(); } @@ -536,12 +536,12 @@ class RemoteAgentConnectionStatusListener implements IWorkbenchContribution { if (location === ProgressLocation.Dialog) { // Show dialog progressService!.withProgress( - { location: ProgressLocation.Dialog, buttons }, + { location: ProgressLocation.Dialog, buttons: buttons.map(button => button.label) }, (progress) => { if (progressReporter) { progressReporter.currentProgress = progress; } return promise; }, (choice?) => { // Handle choice from dialog - if (choice === 0 && buttons && reconnectWaitEvent) { - reconnectWaitEvent.skipWait(); + if (buttons[choice]) { + buttons[choice].callback(); } else { showProgress(ProgressLocation.Notification, buttons); } @@ -551,12 +551,12 @@ class RemoteAgentConnectionStatusListener implements IWorkbenchContribution { } else { // Show notification progressService!.withProgress( - { location: ProgressLocation.Notification, buttons }, + { location: ProgressLocation.Notification, buttons: buttons.map(button => button.label) }, (progress) => { if (progressReporter) { progressReporter.currentProgress = progress; } return promise; }, (choice?) => { - // Handle choice from notification - if (choice === 0 && buttons && reconnectWaitEvent) { - reconnectWaitEvent.skipWait(); + // Handle choice from dialog + if (buttons[choice]) { + buttons[choice].callback(); } else { hideProgress(); } @@ -572,6 +572,22 @@ class RemoteAgentConnectionStatusListener implements IWorkbenchContribution { currentProgressPromiseResolve = null; } + const reconnectButton = { + label: nls.localize('reconnectNow', "Reconnect Now"), + callback: () => { + if (reconnectWaitEvent) { + reconnectWaitEvent.skipWait(); + } + } + }; + + const reloadButton = { + label: nls.localize('reloadWindow', "Reload Window"), + callback: () => { + commandService.executeCommand(ReloadWindowAction.ID); + } + }; + connection.onDidStateChange((e) => { if (currentTimer) { currentTimer.dispose(); @@ -586,7 +602,7 @@ class RemoteAgentConnectionStatusListener implements IWorkbenchContribution { case PersistentConnectionEventType.ConnectionLost: if (!currentProgressPromiseResolve) { progressReporter = new ProgressReporter(null); - showProgress(ProgressLocation.Dialog, [nls.localize('reconnectNow', "Reconnect Now")]); + showProgress(ProgressLocation.Dialog, [reconnectButton, reloadButton]); } progressReporter!.report(nls.localize('connectionLost', "Connection Lost")); @@ -594,12 +610,12 @@ class RemoteAgentConnectionStatusListener implements IWorkbenchContribution { case PersistentConnectionEventType.ReconnectionWait: hideProgress(); reconnectWaitEvent = e; - showProgress(lastLocation || ProgressLocation.Notification, [nls.localize('reconnectNow', "Reconnect Now")]); + showProgress(lastLocation || ProgressLocation.Notification, [reconnectButton, reloadButton]); currentTimer = new ReconnectionTimer(progressReporter!, Date.now() + 1000 * e.durationSeconds); break; case PersistentConnectionEventType.ReconnectionRunning: hideProgress(); - showProgress(lastLocation || ProgressLocation.Notification); + showProgress(lastLocation || ProgressLocation.Notification, [reloadButton]); progressReporter!.report(nls.localize('reconnectionRunning', "Attempting to reconnect...")); // Register to listen for quick input is opened @@ -609,7 +625,7 @@ class RemoteAgentConnectionStatusListener implements IWorkbenchContribution { // Need to move from dialog if being shown and user needs to type in a prompt if (lastLocation === ProgressLocation.Dialog && progressReporter !== null) { hideProgress(); - showProgress(ProgressLocation.Notification); + showProgress(ProgressLocation.Notification, [reloadButton]); progressReporter.report(); } }