refactor: centralize the code that first opens the project into a single function
This commit is contained in:
32
src/main.ts
32
src/main.ts
@@ -35,24 +35,12 @@ export class DevStarExtension {
|
||||
// 如果没有用户登录,则直接登录;
|
||||
this.user.setUserTokenToLocal(access_token)
|
||||
this.user.setUsernameToLocal(devstar_username)
|
||||
// 使用登录已经登录过的容器连接方法
|
||||
await this.remoteContainer.firstConnect(container_host, container_username, container_port)
|
||||
.then((_res) => {
|
||||
if (_res == 'success') {
|
||||
// only success then open folder
|
||||
this.remoteContainer.openRemoteFolder(container_host, container_port, container_username, project_path);
|
||||
}
|
||||
})
|
||||
} else if (devstar_username === this.user.getUsernameFromLocal()){
|
||||
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_port, container_username, project_path)
|
||||
} else if (devstar_username === this.user.getUsernameFromLocal()) {
|
||||
// 如果同用户已经登录,则忽略;
|
||||
// 使用登录已经登录过的容器连接方法
|
||||
await this.remoteContainer.firstConnect(container_host, container_username, container_port)
|
||||
.then((_res) => {
|
||||
if (_res == 'success') {
|
||||
// only success then open folder
|
||||
this.remoteContainer.openRemoteFolder(container_host, container_port, container_username, project_path);
|
||||
}
|
||||
})
|
||||
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_port, container_username, project_path)
|
||||
} else {
|
||||
// 如果不是同用户,可以选择切换用户,或者不切换登录用户,直接打开容器
|
||||
const selection = await vscode.window.showWarningMessage(`已登录用户:${this.user.getUsernameFromLocal()},是否切换用户?`,
|
||||
@@ -60,14 +48,8 @@ export class DevStarExtension {
|
||||
if (selection === 'Yes') {
|
||||
this.user.setUserTokenToLocal(access_token);
|
||||
this.user.setUsernameToLocal(devstar_username);
|
||||
// 使用登录已经登录过的容器连接方法
|
||||
await this.remoteContainer.firstConnect(container_host, container_username, container_port)
|
||||
.then((_res) => {
|
||||
if (_res == 'success') {
|
||||
// only success then open folder
|
||||
this.remoteContainer.openRemoteFolder(container_host, container_port, container_username, project_path);
|
||||
}
|
||||
})
|
||||
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_port, container_username, project_path)
|
||||
} else if (selection === 'No') {
|
||||
await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
|
||||
}
|
||||
|
@@ -15,6 +15,16 @@ export default class RemoteContainer {
|
||||
this.user = user
|
||||
}
|
||||
|
||||
async firstOpenProject(host: string, port: number, username: string, path: string) {
|
||||
this.firstConnect(host, username, port)
|
||||
.then((res) => {
|
||||
if (res == 'success') {
|
||||
// only success then open folder
|
||||
this.openRemoteFolder(host, port, username, path);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async firstConnect(host: string, username: string, port: number): Promise<string>; // connect with key
|
||||
// deprecated
|
||||
async firstConnect(host: string, username: string, port: number, password: string): Promise<string>;
|
||||
|
Reference in New Issue
Block a user