From 35bd842979c7f2ad79b5ee9a2fb1856d14aa5f14 Mon Sep 17 00:00:00 2001 From: Levi Yan Date: Wed, 11 Jun 2025 11:44:34 +0800 Subject: [PATCH] feat: firstOpenProject, in remote environment, create new local window, then call extension and open project by command --- src/main.ts | 18 ++++++++++++++++++ src/remote-container.ts | 23 ++++++++++++++++++----- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 80befd1..ed991e2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -73,6 +73,24 @@ export class DevStarExtension { } else { vscode.window.showErrorMessage('Missing required parameters.'); } + } else if (uri.path === "/openProjectSkippingLoginCheck") { + // 仅有已登录、不用改变登录状态时,用此流程 + const params = new URLSearchParams(uri.query); + const host = params.get('host'); + const hostname = params.get('hostname'); + const port = params.get('port'); + const username = params.get('username'); + const path = params.get('path'); + + if (host && hostname && port && username && path) { + const container_host = host; + const container_hostname = hostname + const container_port = parseInt(port, 10); + 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) + } } } }); diff --git a/src/remote-container.ts b/src/remote-container.ts index a9bc13c..94d3b39 100644 --- a/src/remote-container.ts +++ b/src/remote-container.ts @@ -18,6 +18,8 @@ export default class RemoteContainer { /** * 第一次打开远程项目 + * + * 远程环境,先创建local窗口,在通过命令行调用url打开(目前,仅支持vscode协议) * @param host 项目名称 * @param hostname ip * @param port @@ -26,13 +28,24 @@ export default class RemoteContainer { * @param context 用于支持远程项目环境 */ async firstOpenProject(host: string, hostname: string, port: number, username: string, path: string, context: vscode.ExtensionContext) { - await this.firstConnect(host, hostname, username, port, context) - .then((res) => { - if (res === 'success') { - // only success then open folder - this.openRemoteFolder(host, port, username, path, context); + if (vscode.env.remoteName) { + vscode.commands.executeCommand('workbench.action.terminal.newLocal').then(() => { + const terminal = vscode.window.terminals[vscode.window.terminals.length - 1]; + if (terminal) { + // vscode协议 + terminal.sendText(`code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}"`) } }) + } else { + await this.firstConnect(host, hostname, username, port, context) + .then((res) => { + if (res === 'success') { + // only success then open folder + this.openRemoteFolder(host, port, username, path, context); + } + }) + + } } /**