From 29f6ece39cc54dbfbebde092266a92eb3cba3169 Mon Sep 17 00:00:00 2001 From: Levi Yan Date: Thu, 12 Jun 2025 00:12:27 +0800 Subject: [PATCH] =?UTF-8?q?revert:=20=E5=8F=96=E6=B6=88=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E3=80=90=E9=81=BF=E5=85=8D=E6=89=93=E5=BC=80=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E9=A1=B9=E7=9B=AE=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/home.ts | 21 ++------------------- src/main.ts | 23 ++++------------------- src/remote-container.ts | 19 +++++++------------ 3 files changed, 13 insertions(+), 50 deletions(-) diff --git a/src/home.ts b/src/home.ts index 1a98824..032e390 100644 --- a/src/home.ts +++ b/src/home.ts @@ -68,29 +68,12 @@ 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) + await this.remoteContainer.firstOpenProject(data.host, data.hostname, data.port, data.username, data.path) break; case 'openRemoteFolder': - this.remoteContainer.openRemoteFolder(data.host, data.port, data.username, data.path, this.context); + this.remoteContainer.openRemoteFolder(data.host, data.port, data.username, data.path); break; case 'getDevstarDomain': panel.webview.postMessage({ command: 'getDevstarDomain', data: { devstarDomain: this.devstarDomain } }) diff --git a/src/main.ts b/src/main.ts index 2d489e6..ae24a23 100644 --- a/src/main.ts +++ b/src/main.ts @@ -45,14 +45,11 @@ export class DevStarExtension { // 如果没有用户登录,则直接登录; const res = await this.user.login(access_token, devstar_username) if (res === 'ok') { - await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context) + await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path) } } else if (devstar_username === this.user.getUsernameFromLocal()) { // 如果同用户已经登录,则忽略,直接打开项目 - // 检查项目是否已经打开 - if (!this.isSameProject(container_host, this.context)) { - await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context) - } + await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path) } else { // 如果不是同用户,可以选择切换用户,或者不切换登录用户,直接打开容器 const selection = await vscode.window.showWarningMessage(`已登录用户:${this.user.getUsernameFromLocal()},是否切换用户?`, @@ -61,7 +58,7 @@ export class DevStarExtension { // 如果没有用户登录,则直接登录; const res = await this.user.login(access_token, devstar_username) if (res === 'ok') { - await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context) + await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path) } } else if (selection === 'No') { await openProjectWithoutLogging(container_host, container_port, container_username, project_path); @@ -89,7 +86,7 @@ export class DevStarExtension { const container_username = username; const project_path = decodeURIComponent(path); - await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context) + await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path) } } } @@ -109,18 +106,6 @@ 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 0ea574c..7e0e31f 100644 --- a/src/remote-container.ts +++ b/src/remote-container.ts @@ -27,7 +27,7 @@ export default class RemoteContainer { * @param path * @param context 用于支持远程项目环境 */ - async firstOpenProject(host: string, hostname: string, port: number, username: string, path: string, context: vscode.ExtensionContext) { + async firstOpenProject(host: string, hostname: string, port: number, username: string, path: string) { if (vscode.env.remoteName) { vscode.commands.executeCommand('workbench.action.terminal.newLocal').then(() => { const terminal = vscode.window.terminals[vscode.window.terminals.length - 1]; @@ -41,7 +41,7 @@ export default class RemoteContainer { .then((res) => { if (res === 'success') { // only success then open folder - this.openRemoteFolder(host, port, username, path, context); + this.openRemoteFolder(host, port, username, path); } }) @@ -167,16 +167,11 @@ export default class RemoteContainer { * * @host 表示project name */ - openRemoteFolder(host: string, port: number, username: string, path: string, context: vscode.ExtensionContext): void { - // local env - if (vscode.env.remoteName === undefined) { - // 在打开之前,需要先将host的信息记录到global state中,让home能够确认打开的host是哪个project的 - context.globalState.update('currentHost', host) - let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`); - terminal.show(true); - // 在原窗口打开 - terminal.sendText(`code --remote ssh-remote+${username}@${host}:${port} ${path} --reuse-window`); - } + openRemoteFolder(host: string, port: number, username: string, path: string): void { + let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`); + terminal.show(true); + // 在原窗口打开 + terminal.sendText(`code --remote ssh-remote+${username}@${host}:${port} ${path} --reuse-window`); } }