Improve pause connection (#147318)
parent
2e2654c97f
commit
01ab50b929
|
@ -24,7 +24,13 @@ let outputChannel: vscode.OutputChannel;
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
|
|
||||||
|
let connectionPaused = false;
|
||||||
|
let connectionPausedEvent = new vscode.EventEmitter<boolean>();
|
||||||
|
|
||||||
function doResolve(_authority: string, progress: vscode.Progress<{ message?: string; increment?: number }>): Promise<vscode.ResolvedAuthority> {
|
function doResolve(_authority: string, progress: vscode.Progress<{ message?: string; increment?: number }>): Promise<vscode.ResolvedAuthority> {
|
||||||
|
if (connectionPaused) {
|
||||||
|
throw vscode.RemoteAuthorityResolverError.TemporarilyNotAvailable('Not available right now');
|
||||||
|
}
|
||||||
const connectionToken = String(crypto.randomInt(0xffffffffff));
|
const connectionToken = String(crypto.randomInt(0xffffffffff));
|
||||||
|
|
||||||
// eslint-disable-next-line no-async-promise-executor
|
// eslint-disable-next-line no-async-promise-executor
|
||||||
|
@ -151,8 +157,8 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
let remoteReady = true, localReady = true;
|
let remoteReady = true, localReady = true;
|
||||||
const remoteSocket = net.createConnection({ port: serverAddr.port });
|
const remoteSocket = net.createConnection({ port: serverAddr.port });
|
||||||
|
|
||||||
let isDisconnected = connectionPaused;
|
let isDisconnected = false;
|
||||||
connectionPausedEvent.event(_ => {
|
const handleConnectionPause = () => {
|
||||||
let newIsDisconnected = connectionPaused;
|
let newIsDisconnected = connectionPaused;
|
||||||
if (isDisconnected !== newIsDisconnected) {
|
if (isDisconnected !== newIsDisconnected) {
|
||||||
outputChannel.appendLine(`Connection state: ${newIsDisconnected ? 'open' : 'paused'}`);
|
outputChannel.appendLine(`Connection state: ${newIsDisconnected ? 'open' : 'paused'}`);
|
||||||
|
@ -175,7 +181,10 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
connectionPausedEvent.event(_ => handleConnectionPause());
|
||||||
|
handleConnectionPause();
|
||||||
|
|
||||||
proxySocket.on('data', (data) => {
|
proxySocket.on('data', (data) => {
|
||||||
remoteReady = remoteSocket.write(data);
|
remoteReady = remoteSocket.write(data);
|
||||||
|
@ -251,9 +260,6 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let connectionPaused = false;
|
|
||||||
let connectionPausedEvent = new vscode.EventEmitter<boolean>();
|
|
||||||
|
|
||||||
const authorityResolverDisposable = vscode.workspace.registerRemoteAuthorityResolver('test', {
|
const authorityResolverDisposable = vscode.workspace.registerRemoteAuthorityResolver('test', {
|
||||||
async getCanonicalURI(uri: vscode.Uri): Promise<vscode.Uri> {
|
async getCanonicalURI(uri: vscode.Uri): Promise<vscode.Uri> {
|
||||||
return vscode.Uri.file(uri.path);
|
return vscode.Uri.file(uri.path);
|
||||||
|
|
Loading…
Reference in New Issue