Skip to content

Commit

Permalink
add reload window button to reconnection dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
sbatten committed Nov 2, 2019
1 parent 4565afe commit d3405c4
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/vs/workbench/contrib/remote/browser/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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);
}
Expand All @@ -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();
}
Expand All @@ -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();
Expand All @@ -586,20 +602,20 @@ 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"));
break;
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
Expand All @@ -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();
}
}
Expand Down

0 comments on commit d3405c4

Please sign in to comment.