feat: 避免打开同一个项目(home、open with vscode)

This commit is contained in:
Levi Yan
2025-05-31 22:51:28 +08:00
parent a8d5f4acb8
commit 91ac39ac0b
5 changed files with 46 additions and 9 deletions

View File

@@ -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');
}