fix: even if the connection is not successful, the host information is stored
This commit is contained in:
@@ -70,8 +70,6 @@ export default class DSHome {
|
|||||||
// only success then open folder
|
// only success then open folder
|
||||||
this.remoteContainer.openRemoteFolder(data.host, data.username, data.port, data.path);
|
this.remoteContainer.openRemoteFolder(data.host, data.username, data.port, data.path);
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
|
||||||
console.error(`Failed to connect ${data.host}: `, error)
|
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
case 'openRemoteFolder':
|
case 'openRemoteFolder':
|
||||||
|
@@ -20,7 +20,7 @@ export default class RemoteContainer {
|
|||||||
async firstConnect(host: string, username: string, port: number, password: string): Promise<string>;
|
async firstConnect(host: string, username: string, port: number, password: string): Promise<string>;
|
||||||
|
|
||||||
async firstConnect(host: string, username: string, port: number, password?: string): Promise<string> {
|
async firstConnect(host: string, username: string, port: number, password?: string): Promise<string> {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve) => {
|
||||||
const ssh = new NodeSSH();
|
const ssh = new NodeSSH();
|
||||||
vscode.window.withProgress({
|
vscode.window.withProgress({
|
||||||
location: vscode.ProgressLocation.Notification,
|
location: vscode.ProgressLocation.Notification,
|
||||||
@@ -96,13 +96,19 @@ export default class RemoteContainer {
|
|||||||
await ssh.dispose();
|
await ssh.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only connect successfully then save the host info
|
||||||
|
await this.storeHostInfo(host, port, username)
|
||||||
|
|
||||||
|
resolve('success')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to install vscode-server and extension: ', error);
|
console.error('Failed to install vscode-server and extension: ', error);
|
||||||
await ssh.dispose();
|
await ssh.dispose();
|
||||||
reject(error);
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// only connect successfully then save the host info
|
async storeHostInfo(host:string, port:number, username:string): Promise<void> {
|
||||||
const sshConfigPath = path.join(os.homedir(), '.ssh', 'config');
|
const sshConfigPath = path.join(os.homedir(), '.ssh', 'config');
|
||||||
// check if the host and related info exist in local ssh config file before saving
|
// check if the host and related info exist in local ssh config file before saving
|
||||||
var canAppendSSHConfig = true
|
var canAppendSSHConfig = true
|
||||||
@@ -128,10 +134,6 @@ export default class RemoteContainer {
|
|||||||
fs.writeFileSync(sshConfigPath, newSShConfigContent, { encoding: 'utf8', flag: 'a' });
|
fs.writeFileSync(sshConfigPath, newSShConfigContent, { encoding: 'utf8', flag: 'a' });
|
||||||
console.log('Host registered in local ssh config');
|
console.log('Host registered in local ssh config');
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve("success");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user