test resolver: simplify pause/unpause

This commit is contained in:
Martin Aeschlimann 2021-06-15 16:30:50 +02:00
parent 4f4d12148f
commit 99f4201e20
No known key found for this signature in database
GPG key ID: 2609A01E695523E3
2 changed files with 39 additions and 10 deletions

View file

@ -23,7 +23,8 @@
"onCommand:vscode-testresolver.newWindowWithError",
"onCommand:vscode-testresolver.showLog",
"onCommand:vscode-testresolver.openTunnel",
"onCommand:vscode-testresolver.startRemoteServer"
"onCommand:vscode-testresolver.startRemoteServer",
"onCommand:vscode-testresolver.toggleConnectionPause"
],
"main": "./out/extension",
"devDependencies": {
@ -70,9 +71,14 @@
"command": "vscode-testresolver.openTunnel"
},
{
"title": "Open Remote Server...",
"title": "Open a Remote Port...",
"category": "Remote-TestResolver",
"command": "vscode-testresolver.startRemoteServer"
},
{
"title": "Pause Connection (Test Reconnect)",
"category": "Remote-TestResolver",
"command": "vscode-testresolver.toggleConnectionPause"
}
],
"menus": {
@ -84,6 +90,10 @@
{
"command": "vscode-testresolver.startRemoteServer",
"when": "remoteName == test"
},
{
"command": "vscode-testresolver.toggleConnectionPause",
"when": "remoteName == test"
}
],
"statusBar/remoteIndicator": [
@ -111,6 +121,11 @@
"command": "vscode-testresolver.startRemoteServer",
"when": "remoteName == test",
"group": "remote_90_test_2_more@5"
},
{
"command": "vscode-testresolver.toggleConnectionPause",
"when": "remoteName == test",
"group": "remote_90_test_2_more@6"
}
]
},
@ -126,11 +141,6 @@
"type": "boolean",
"default": false
},
"testresolver.pause": {
"description": "If set, connection is paused",
"type": "boolean",
"default": false
},
"testresolver.supportPublicPorts": {
"description": "If set, the test resolver tunnel factory will support mock public ports. Forwarded ports will not actually be public. Requires reload.",
"type": "boolean",

View file

@ -135,9 +135,9 @@ export function activate(context: vscode.ExtensionContext) {
let remoteReady = true, localReady = true;
const remoteSocket = net.createConnection({ port: serverAddr.port });
let isDisconnected = getConfiguration('pause') === true;
vscode.workspace.onDidChangeConfiguration(_ => {
let newIsDisconnected = getConfiguration('pause') === true;
let isDisconnected = connectionPaused;
connectionPausedEvent.event(_ => {
let newIsDisconnected = connectionPaused;
if (isDisconnected !== newIsDisconnected) {
outputChannel.appendLine(`Connection state: ${newIsDisconnected ? 'open' : 'paused'}`);
isDisconnected = newIsDisconnected;
@ -215,6 +215,9 @@ export function activate(context: vscode.ExtensionContext) {
});
}
let connectionPaused = false;
let connectionPausedEvent = new vscode.EventEmitter<boolean>();
const authorityResolverDisposable = vscode.workspace.registerRemoteAuthorityResolver('test', {
async getCanonicalURI(uri: vscode.Uri): Promise<vscode.Uri> {
return vscode.Uri.file(uri.path);
@ -258,6 +261,22 @@ export function activate(context: vscode.ExtensionContext) {
}
}));
const pauseStatusBarEntry = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
pauseStatusBarEntry.text = 'Remote connection paused. Click to undo';
pauseStatusBarEntry.command = 'vscode-testresolver.toggleConnectionPause';
pauseStatusBarEntry.backgroundColor = new vscode.ThemeColor('statusBarItem.errorBackground');
context.subscriptions.push(vscode.commands.registerCommand('vscode-testresolver.toggleConnectionPause', () => {
if (!connectionPaused) {
connectionPaused = true;
pauseStatusBarEntry.show();
} else {
connectionPaused = false;
pauseStatusBarEntry.hide();
}
connectionPausedEvent.fire(connectionPaused);
}));
context.subscriptions.push(vscode.commands.registerCommand('vscode-testresolver.openTunnel', async () => {
const result = await vscode.window.showInputBox({
prompt: 'Enter the remote port for the tunnel',