feat: 避免打开同一个项目(home、open with vscode)
This commit is contained in:
21
src/main.ts
21
src/main.ts
@@ -48,9 +48,11 @@ export class DevStarExtension {
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
|
||||
}
|
||||
} else if (devstar_username === this.user.getUsernameFromLocal()) {
|
||||
// 如果同用户已经登录,则忽略;
|
||||
// 直接打开项目
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname,container_port, container_username, project_path, this.context)
|
||||
// 如果同用户已经登录,则忽略,直接打开项目
|
||||
// 检查项目是否已经打开
|
||||
if (!this.isSameProject(container_host, this.context)) {
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
|
||||
}
|
||||
} else {
|
||||
// 如果不是同用户,可以选择切换用户,或者不切换登录用户,直接打开容器
|
||||
const selection = await vscode.window.showWarningMessage(`已登录用户:${this.user.getUsernameFromLocal()},是否切换用户?`,
|
||||
@@ -101,6 +103,19 @@ export class DevStarExtension {
|
||||
this.startDevStarHome();
|
||||
}
|
||||
|
||||
isSameProject(project_name: string, context: vscode.ExtensionContext) {
|
||||
// 远程环境且目标项目名称==currentHost,则提示项目已经打开
|
||||
if (vscode.env.remoteName) {
|
||||
const currentHostRecorded = context.globalState.get('currentHost')
|
||||
const currentHost = currentHostRecorded != undefined ? currentHostRecorded : ""
|
||||
if (currentHost == project_name) {
|
||||
vscode.window.showWarningMessage(vscode.l10n.t("Project has been open!"))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async startDevStarHome() {
|
||||
vscode.commands.executeCommand('devstar.showHome');
|
||||
}
|
||||
|
Reference in New Issue
Block a user