From 91ac39ac0b34a5ab88978160ce12f8deedabfd40 Mon Sep 17 00:00:00 2001 From: Levi Yan Date: Sat, 31 May 2025 22:51:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=81=BF=E5=85=8D=E6=89=93=E5=BC=80?= =?UTF-8?q?=E5=90=8C=E4=B8=80=E4=B8=AA=E9=A1=B9=E7=9B=AE=EF=BC=88home?= =?UTF-8?q?=E3=80=81open=20with=20vscode=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- l10n/bundle.l10n.zh-CN.json | 3 ++- package.json | 2 +- src/home.ts | 22 ++++++++++++++++++++-- src/main.ts | 21 ++++++++++++++++++--- src/remote-container.ts | 7 +++++-- 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/l10n/bundle.l10n.zh-CN.json b/l10n/bundle.l10n.zh-CN.json index 4ba39d0..2cab5e9 100644 --- a/l10n/bundle.l10n.zh-CN.json +++ b/l10n/bundle.l10n.zh-CN.json @@ -8,5 +8,6 @@ "User has logged out!":"用户已登出!", "Installing vscode-server and devstar extension in container": "正在容器中安装vscode-server及devstar插件", "Connected! Start installation": "连接成功,开始安装", - "Installation completed!": "安装完成!" + "Installation completed!": "安装完成!", + "Project has been open!": "该项目已经打开!" } \ No newline at end of file diff --git a/package.json b/package.json index dee76dd..2e99f13 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "devstar", "displayName": "%displayName%", "description": "%description%", - "version": "0.3.2", + "version": "0.3.3", "keywords": [], "publisher": "mengning", "engines": { diff --git a/src/home.ts b/src/home.ts index caa9d40..1a98824 100644 --- a/src/home.ts +++ b/src/home.ts @@ -68,11 +68,29 @@ export default class DSHome { panel.webview.postMessage({ command: 'getUsername', data: { username: username } }) break; } + case 'getCurrentHost': + let currentHost = null + if (vscode.env.remoteName) { + // 远程环境,需要确认当前host名称(项目名称) + const currentHostRecorded = this.context.globalState.get('currentHost') + currentHost = currentHostRecorded != undefined ? currentHostRecorded : "" + } else { + // 如果当前是本地环境,则没有限制 + } + + if (null == currentHost || "" == currentHost) { + panel.webview.postMessage({ command: 'getCurrentHost', data: {currentHost: ''}}) + break; + } else { + panel.webview.postMessage({ command: 'getCurrentHost', data: {currentHost: currentHost}}) + break; + } case 'firstOpenRemoteFolder': + // data.host - project name await this.remoteContainer.firstOpenProject(data.host, data.hostname, data.port, data.username, data.path, this.context) break; case 'openRemoteFolder': - this.remoteContainer.openRemoteFolder(data.host, data.port, data.username, data.path); + this.remoteContainer.openRemoteFolder(data.host, data.port, data.username, data.path, this.context); break; case 'getDevstarDomain': panel.webview.postMessage({ command: 'getDevstarDomain', data: { devstarDomain: this.devstarDomain } }) @@ -241,4 +259,4 @@ export default class DSHome { ` } -} \ No newline at end of file +} diff --git a/src/main.ts b/src/main.ts index 71e0120..80befd1 100644 --- a/src/main.ts +++ b/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'); } diff --git a/src/remote-container.ts b/src/remote-container.ts index 964797e..a9bc13c 100644 --- a/src/remote-container.ts +++ b/src/remote-container.ts @@ -30,7 +30,7 @@ export default class RemoteContainer { .then((res) => { if (res === 'success') { // only success then open folder - this.openRemoteFolder(host, port, username, path); + this.openRemoteFolder(host, port, username, path, context); } }) } @@ -232,7 +232,7 @@ export default class RemoteContainer { * * @host 表示project name */ - openRemoteFolder(host: string, port: number, username: string, path: string): void { + openRemoteFolder(host: string, port: number, username: string, path: string, context:vscode.ExtensionContext): void { if (vscode.env.remoteName) { // 远程环境,打开local terminal vscode.commands.executeCommand('workbench.action.terminal.newLocal').then(() => { @@ -245,6 +245,9 @@ export default class RemoteContainer { }) } else { // 本地环境 + // 在打开之前,需要先将host的信息记录到global state中,让home能够确认打开的host是哪个project的 + context.globalState.update('currentHost', host) + let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`); terminal.show(true); // 在原窗口打开