Files
devstar-vscode/src/remote-container.ts

658 lines
23 KiB
TypeScript
Raw Normal View History

// remote-container.ts
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import * as vscode from 'vscode';
2025-11-18 14:04:48 +08:00
import * as rd from 'readline';
const { NodeSSH } = require('node-ssh');
2025-11-14 15:25:14 +08:00
const { spawn } = require('child_process');
const net = require('net');
import * as utils from './utils';
import User from './user';
import DevstarAPIHandler from './devstar-api';
export default class RemoteContainer {
private user: User;
2025-11-14 15:25:14 +08:00
private sshProcesses?: Map<string, any>;
private portMappings: Map<string, Array<{ containerPort: number, localPort: number, label: string, source: string }>> = new Map();
2025-11-18 14:04:48 +08:00
private statusBarItems?: Map<string, vscode.StatusBarItem>;
constructor(user: User) {
2025-11-18 14:04:48 +08:00
this.user = user;
}
2025-06-22 11:11:09 +08:00
public setUser(user: User) {
2025-11-18 14:04:48 +08:00
this.user = user;
2025-06-22 11:11:09 +08:00
}
/**
*
*/
async firstOpenProject(host: string, hostname: string, port: number, username: string, path: string, context: vscode.ExtensionContext) {
if (vscode.env.remoteName) {
try {
await vscode.commands.executeCommand('workbench.action.terminal.newLocal');
const terminal = vscode.window.terminals[vscode.window.terminals.length - 1];
2025-11-18 14:04:48 +08:00
if (terminal) {
2025-11-18 14:04:48 +08:00
let devstarDomain: string | undefined = context.globalState.get("devstarDomain_" + vscode.env.sessionId);
if (devstarDomain == undefined || devstarDomain == "") {
devstarDomain = undefined;
}
2025-11-18 14:04:48 +08:00
const semver = require('semver');
const powershellVersion = context.globalState.get('powershellVersion');
const powershell_semver_compatible_version = semver.coerce(powershellVersion);
let command = '';
if (devstarDomain === undefined) {
if (powershellVersion === undefined) {
command = `code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}"`;
} else if (semver.satisfies(powershell_semver_compatible_version, ">=5.1.26100")) {
command = `code --new-window ; code --% --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}"`;
} else {
command = `code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}"`;
}
} else {
if (powershellVersion === undefined) {
command = `code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}&devstar_domain=${devstarDomain}"`;
} else if (semver.satisfies(powershell_semver_compatible_version, ">=5.1.26100")) {
command = `code --new-window ; code --% --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}&devstar_domain=${devstarDomain}"`;
} else {
command = `code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}&devstar_domain=${devstarDomain}"`;
}
}
terminal.sendText(command);
} else {
vscode.window.showErrorMessage('无法创建终端,请检查终端是否可用。');
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : '未知错误';
vscode.window.showErrorMessage(`远程环境操作失败: ${errorMessage}`);
}
} else {
try {
2025-11-14 15:25:14 +08:00
await this.firstConnect(host, hostname, username, port, path)
.then((res) => {
if (res === 'success') {
this.openRemoteFolder(host, port, username, path);
} else {
vscode.window.showErrorMessage('首次连接容器失败,请检查网络和容器状态。');
}
})
.catch(error => {
const errorMessage = error instanceof Error ? error.message : '未知错误';
vscode.window.showErrorMessage(`首次连接容器时发生错误: ${errorMessage}`);
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : '未知错误';
vscode.window.showErrorMessage(`打开项目失败: ${errorMessage}`);
}
}
}
/**
* local environment
*/
2025-11-14 15:25:14 +08:00
async firstConnect(host: string, hostname: string, username: string, port: number, projectPath?: string): Promise<string> {
return new Promise(async (resolve, reject) => {
const ssh = new NodeSSH();
2025-11-18 14:04:48 +08:00
vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
2025-04-22 22:32:06 +08:00
title: vscode.l10n.t("Installing vscode-server and devstar extension in container"),
cancellable: false
}, async (progress) => {
try {
if (!this.user.existUserPrivateKey() || !this.user.existUserPublicKey()) {
2025-11-18 14:04:48 +08:00
await this.user.createUserSSHKey();
const devstarAPIHandler = new DevstarAPIHandler();
const uploadResult = await devstarAPIHandler.uploadUserPublicKey(this.user);
if (uploadResult !== "ok") {
2025-11-18 14:04:48 +08:00
throw new Error('Upload public key failed.');
}
}
} catch (error) {
reject(error);
return;
}
try {
await ssh.connect({
host: hostname,
2025-11-03 14:04:59 +08:00
username: 'root',
port: port,
privateKeyPath: this.user.getUserPrivateKeyPath(),
2025-11-18 14:04:48 +08:00
readyTimeout: 30000,
onKeyboardInteractive: (
2025-11-18 14:04:48 +08:00
_name: string,
_instructions: string,
_instructionsLang: string,
_prompts: any[],
finish: (responses: string[]) => void
) => {
finish([]);
}
});
2025-11-18 14:04:48 +08:00
progress.report({ message: vscode.l10n.t("Connected! Start installation") });
2025-11-18 14:04:48 +08:00
const vscodeCommitId = await utils.getVsCodeCommitId();
if ("" !== vscodeCommitId) {
const vscodeServerUrl = `https://vscode.download.prss.microsoft.com/dbazure/download/stable/${vscodeCommitId}/vscode-server-linux-x64.tar.gz`;
const installVscodeServerScript = `
mkdir -p ~/.vscode-server/bin/${vscodeCommitId} && \\
if [ "$(ls -A ~/.vscode-server/bin/${vscodeCommitId})" ]; then
echo "VSCode server already exists, installing extension only"
~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar
else
echo "Downloading and installing VSCode server"
wget ${vscodeServerUrl} -O vscode-server-linux-x64.tar.gz && \\
mv vscode-server-linux-x64.tar.gz ~/.vscode-server/bin/${vscodeCommitId} && \\
cd ~/.vscode-server/bin/${vscodeCommitId} && \\
tar -xvzf vscode-server-linux-x64.tar.gz --strip-components 1 && \\
rm vscode-server-linux-x64.tar.gz && \\
~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar
fi
`;
2025-11-18 14:04:48 +08:00
const installResult = await ssh.execCommand(installVscodeServerScript);
2025-11-18 14:04:48 +08:00
if (installResult.code === 0) {
vscode.window.showInformationMessage(vscode.l10n.t('Installation completed!'));
} else {
throw new Error(`Installation failed with exit code ${installResult.code}: ${installResult.stderr}`);
}
} else {
throw new Error('Failed to get VSCode commit ID');
}
2025-11-14 15:25:14 +08:00
if (projectPath) {
}
await ssh.dispose();
2025-11-18 14:04:48 +08:00
await this.storeProjectSSHInfo(host, hostname, port, 'root');
2025-11-18 14:04:48 +08:00
resolve('success');
} catch (error) {
try {
await ssh.dispose();
} catch (disposeError) {
}
reject(error);
}
});
});
}
2025-11-14 15:25:14 +08:00
/**
* devcontainer.json
*/
2025-11-18 14:04:48 +08:00
private async getPortsConfigFromDevContainer(ssh: any, containerPath: string): Promise<{
portsAttributes: any;
forwardPorts?: number[];
otherPortsAttributes?: any;
}> {
2025-11-14 15:25:14 +08:00
try {
const findResult = await ssh.execCommand(`find ${containerPath} -name "devcontainer.json" -type f`);
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
if (findResult.code === 0 && findResult.stdout.trim()) {
2025-11-18 14:04:48 +08:00
const devcontainerPath = findResult.stdout.trim().split('\n')[0];
2025-11-14 15:25:14 +08:00
const readResult = await ssh.execCommand(`cat ${devcontainerPath}`);
if (readResult.code === 0) {
const devcontainerConfig = JSON.parse(readResult.stdout);
2025-11-18 14:04:48 +08:00
return {
portsAttributes: devcontainerConfig.portsAttributes || {},
forwardPorts: devcontainerConfig.forwardPorts,
otherPortsAttributes: devcontainerConfig.otherPortsAttributes
};
2025-11-14 15:25:14 +08:00
}
}
} catch (error) {
}
2025-11-18 14:04:48 +08:00
return { portsAttributes: {} };
}
/**
* - 使
*/
private async findAvailableLocalPort(containerPort: number): Promise<number> {
if (await this.isPortAvailable(containerPort)) {
return containerPort;
}
for (let offset = 1; offset <= 10; offset++) {
const port1 = containerPort + offset;
if (port1 < 65536 && await this.isPortAvailable(port1)) {
return port1;
}
const port2 = containerPort - offset;
if (port2 > 0 && await this.isPortAvailable(port2)) {
return port2;
}
}
return this.findRandomAvailablePort();
}
/**
*
*/
private async isPortAvailable(port: number): Promise<boolean> {
return new Promise((resolve) => {
const server = net.createServer();
server.unref();
server.on('error', () => {
resolve(false);
});
server.listen(port, () => {
server.close(() => {
resolve(true);
});
});
});
2025-11-14 15:25:14 +08:00
}
/**
2025-11-18 14:04:48 +08:00
*
*/
private async findRandomAvailablePort(): Promise<number> {
return new Promise((resolve, reject) => {
const server = net.createServer();
server.unref();
server.on('error', reject);
server.listen(0, () => {
const port = server.address().port;
server.close(() => {
resolve(port);
});
});
});
}
/**
* - devcontainer.json
2025-11-14 15:25:14 +08:00
*/
private async setupPortForwarding(hostname: string, port: number, containerPath: string): Promise<void> {
const ssh = new NodeSSH();
2025-11-18 14:04:48 +08:00
const portMappings: Array<{ containerPort: number, localPort: number, label: string, source: string }> = [];
2025-11-14 15:25:14 +08:00
try {
await ssh.connect({
host: hostname,
username: 'root',
port: port,
privateKeyPath: this.user.getUserPrivateKeyPath(),
readyTimeout: 30000,
});
2025-11-18 14:04:48 +08:00
const portsConfig = await this.getPortsConfigFromDevContainer(ssh, containerPath);
if (portsConfig.forwardPorts && portsConfig.forwardPorts.length > 0) {
for (const containerPort of portsConfig.forwardPorts) {
const localPort = await this.findAvailableLocalPort(containerPort);
await this.createSSHPortForward(hostname, port, containerPort, localPort);
portMappings.push({
containerPort,
localPort,
label: `Port ${containerPort}`,
source: 'forwardPorts'
});
}
}
for (const [containerPortStr, attributes] of Object.entries(portsConfig.portsAttributes)) {
2025-11-14 15:25:14 +08:00
const containerPort = parseInt(containerPortStr);
if (!isNaN(containerPort)) {
2025-11-18 14:04:48 +08:00
const alreadyMapped = portMappings.some(m => m.containerPort === containerPort);
if (!alreadyMapped) {
const localPort = await this.findAvailableLocalPort(containerPort);
await this.createSSHPortForward(hostname, port, containerPort, localPort);
const label = (attributes as any).label || `Port ${containerPort}`;
portMappings.push({
containerPort,
localPort,
label,
source: 'portsAttributes'
});
}
2025-11-14 15:25:14 +08:00
}
}
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
await ssh.dispose();
2025-11-18 14:04:48 +08:00
const mappingKey = `${hostname}:${port}`;
this.portMappings.set(mappingKey, portMappings);
if (portMappings.length > 0) {
this.showPortMappingsSummary(portMappings);
2025-11-18 14:04:48 +08:00
this.registerPortMappingsCommands(mappingKey, portMappings);
}
2025-11-14 15:25:14 +08:00
} catch (error) {
await ssh.dispose();
throw error;
}
}
/**
* SSH
*/
private async createSSHPortForward(hostname: string, sshPort: number, containerPort: number, localPort: number): Promise<void> {
return new Promise((resolve, reject) => {
const sshArgs = [
2025-11-18 14:04:48 +08:00
'-N',
'-L',
`${localPort}:localhost:${containerPort}`,
2025-11-14 15:25:14 +08:00
'-o', 'StrictHostKeyChecking=no',
'-o', 'UserKnownHostsFile=/dev/null',
'-p', sshPort.toString(),
'-i', this.user.getUserPrivateKeyPath(),
`root@${hostname}`
];
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
const sshProcess = spawn('ssh', sshArgs);
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
sshProcess.on('error', (error: Error) => {
reject(error);
});
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
sshProcess.stdout.on('data', (data: Buffer) => {
});
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
sshProcess.stderr.on('data', (data: Buffer) => {
});
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
if (!this.sshProcesses) {
this.sshProcesses = new Map();
}
const key = `${hostname}:${sshPort}:${containerPort}`;
this.sshProcesses.set(key, sshProcess);
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
setTimeout(() => {
resolve();
}, 2000);
});
}
2025-11-18 14:04:48 +08:00
/**
*
*/
private showPortMappingsSummary(portMappings: Array<{ containerPort: number, localPort: number, label: string, source: string }>): void {
let message = `🎯 已建立 ${portMappings.length} 个端口映射:\n\n`;
portMappings.forEach(mapping => {
const samePort = mapping.containerPort === mapping.localPort ? " ✅" : " 🔄";
message += `${mapping.label}\n`;
message += ` 容器端口: ${mapping.containerPort} → 本地端口: ${mapping.localPort}${samePort}\n`;
message += ` 访问地址: http://localhost:${mapping.localPort}\n`;
message += ` 配置来源: ${mapping.source}\n\n`;
});
vscode.window.showInformationMessage(message, '复制映射信息', '在浏览器中打开', '查看详细信息')
.then(selection => {
if (selection === '复制映射信息') {
const copyText = portMappings.map(m =>
`${m.label}: http://localhost:${m.localPort} (容器端口: ${m.containerPort})`
).join('\n');
vscode.env.clipboard.writeText(copyText);
vscode.window.showInformationMessage('端口映射信息已复制到剪贴板');
} else if (selection === '在浏览器中打开' && portMappings.length > 0) {
vscode.env.openExternal(vscode.Uri.parse(`http://localhost:${portMappings[0].localPort}`));
} else if (selection === '查看详细信息') {
this.showPortMappingsInOutputChannel('current', 0);
}
});
}
/**
*
*/
private registerPortMappingsCommands(mappingKey: string, portMappings: Array<{ containerPort: number, localPort: number, label: string, source: string }>): void {
2025-11-18 14:04:48 +08:00
const showPortMappingsCommand = `devstar.showPortMappings.${mappingKey.replace(/[^a-zA-Z0-9]/g, '_')}`;
2025-11-18 14:04:48 +08:00
vscode.commands.registerCommand(showPortMappingsCommand, () => {
this.showPortMappingsSummary(portMappings);
});
this.createStatusBarItem(mappingKey, portMappings);
}
/**
*
*/
private createStatusBarItem(mappingKey: string, portMappings: Array<{ containerPort: number, localPort: number, label: string, source: string }>): void {
2025-11-18 14:04:48 +08:00
if (portMappings.length === 0) return;
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
2025-11-18 14:04:48 +08:00
statusBarItem.text = `$(plug) ${portMappings.length} Ports`;
statusBarItem.tooltip = `点击查看 ${portMappings.length} 个端口映射详情`;
2025-11-18 14:04:48 +08:00
statusBarItem.command = `devstar.showPortMappings.${mappingKey.replace(/[^a-zA-Z0-9]/g, '_')}`;
2025-11-18 14:04:48 +08:00
statusBarItem.show();
2025-11-18 14:04:48 +08:00
if (!this.statusBarItems) {
this.statusBarItems = new Map();
}
this.statusBarItems.set(mappingKey, statusBarItem);
}
/**
*
*/
public getActivePortMappings(hostname: string, port: number): Array<{ containerPort: number, localPort: number, label: string, source: string }> {
2025-11-18 14:04:48 +08:00
const mappingKey = `${hostname}:${port}`;
return this.portMappings.get(mappingKey) || [];
}
/**
*
*/
public showPortMappingsPanel(hostname: string, port: number): void {
const mappings = this.getActivePortMappings(hostname, port);
if (mappings.length === 0) {
vscode.window.showInformationMessage('当前没有活动的端口映射');
return;
}
this.showPortMappingsSummary(mappings);
}
/**
*
*/
public showPortMappingsInOutputChannel(hostname: string, port: number): void {
const mappings = this.getActivePortMappings(hostname, port);
if (mappings.length === 0) {
vscode.window.showInformationMessage('当前没有活动的端口映射');
return;
}
const outputChannel = vscode.window.createOutputChannel('DevStar Port Mappings');
outputChannel.show();
2025-11-18 14:04:48 +08:00
outputChannel.appendLine(`🎯 端口映射信息 - ${hostname}:${port}`);
outputChannel.appendLine('='.repeat(50));
2025-11-18 14:04:48 +08:00
mappings.forEach((mapping, index) => {
outputChannel.appendLine(`${index + 1}. ${mapping.label}`);
outputChannel.appendLine(` 容器端口: ${mapping.containerPort}`);
outputChannel.appendLine(` 本地端口: ${mapping.localPort}`);
outputChannel.appendLine(` 访问地址: http://localhost:${mapping.localPort}`);
outputChannel.appendLine(` 配置来源: ${mapping.source}`);
outputChannel.appendLine('');
});
2025-11-18 14:04:48 +08:00
outputChannel.appendLine('💡 提示: 您可以在浏览器中访问上述本地端口来访问容器中的服务');
}
/**
* ssh连接信息
*/
async storeProjectSSHInfo(host: string, hostname: string, port: number, username: string): Promise<void> {
const sshConfigPath = path.join(os.homedir(), '.ssh', 'config');
2025-11-18 14:04:48 +08:00
let canAppendSSHConfig = true;
if (fs.existsSync(sshConfigPath)) {
const reader = rd.createInterface(fs.createReadStream(sshConfigPath));
for await (const line of reader) {
if (line.includes(`Host ${host}`)) {
canAppendSSHConfig = false;
break;
}
}
}
if (canAppendSSHConfig) {
const privateKeyPath = this.user.getUserPrivateKeyPath();
2025-11-18 14:04:48 +08:00
const newSShConfigContent =
2025-05-06 23:04:10 +08:00
`\nHost ${host}\n HostName ${hostname}\n Port ${port}\n User ${username}\n PreferredAuthentications publickey\n IdentityFile ${privateKeyPath}\n `;
2025-11-18 14:04:48 +08:00
try {
fs.writeFileSync(sshConfigPath, newSShConfigContent, { encoding: 'utf8', flag: 'a' });
} catch (error) {
throw error;
}
}
}
/**
* local env
*/
2025-11-14 15:25:14 +08:00
async openRemoteFolder(host: string, port: number, username: string, path: string): Promise<void> {
try {
2025-11-14 15:25:14 +08:00
const sshConfig = await this.getSSHConfig(host);
if (sshConfig) {
try {
await this.setupPortForwarding(sshConfig.hostname, port, path);
2025-11-18 14:04:48 +08:00
setTimeout(() => {
this.showPortMappingsPanel(sshConfig.hostname, port);
}, 3000);
2025-11-14 15:25:14 +08:00
} catch (portError) {
2025-11-18 14:04:48 +08:00
vscode.window.showWarningMessage('端口映射设置失败,但容器连接已建立');
2025-11-14 15:25:14 +08:00
}
}
2025-11-18 14:04:48 +08:00
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
terminal.show(true);
2025-11-18 14:04:48 +08:00
const command = `code --remote ssh-remote+root@${host}:${port} ${path} --reuse-window`;
2025-11-18 14:04:48 +08:00
terminal.sendText(command);
} catch (error) {
const errorMessage = error instanceof Error ? error.message : '未知错误';
vscode.window.showErrorMessage(`打开远程文件夹失败: ${errorMessage}`);
}
}
2025-11-14 15:25:14 +08:00
/**
* SSH config
*/
private async getSSHConfig(host: string): Promise<{ hostname: string; port: number } | null> {
const sshConfigPath = path.join(os.homedir(), '.ssh', 'config');
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
if (!fs.existsSync(sshConfigPath)) {
return null;
}
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
const configContent = fs.readFileSync(sshConfigPath, 'utf8');
const lines = configContent.split('\n');
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
let currentHost = '';
let hostname = '';
2025-11-18 14:04:48 +08:00
let port = 22;
2025-11-14 15:25:14 +08:00
for (const line of lines) {
const trimmed = line.trim();
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
if (trimmed.startsWith('Host ')) {
currentHost = trimmed.substring(5).trim();
} else if (currentHost === host) {
if (trimmed.startsWith('HostName ')) {
hostname = trimmed.substring(9).trim();
} else if (trimmed.startsWith('Port ')) {
port = parseInt(trimmed.substring(5).trim());
}
}
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
if (hostname && currentHost === host) {
return { hostname, port };
}
}
2025-11-18 14:04:48 +08:00
2025-11-14 15:25:14 +08:00
return null;
}
/**
2025-11-18 14:04:48 +08:00
* UI
2025-11-14 15:25:14 +08:00
*/
2025-11-18 14:04:48 +08:00
public cleanupPortForwarding(hostname?: string, port?: number): void {
if (this.sshProcesses) {
for (const [key, process] of this.sshProcesses.entries()) {
try {
process.kill();
} catch (error) {
}
}
this.sshProcesses.clear();
}
2025-11-18 14:04:48 +08:00
if (this.statusBarItems) {
if (hostname && port) {
const mappingKey = `${hostname}:${port}`;
const statusBarItem = this.statusBarItems.get(mappingKey);
if (statusBarItem) {
statusBarItem.dispose();
this.statusBarItems.delete(mappingKey);
}
} else {
for (const [_, statusBarItem] of this.statusBarItems) {
statusBarItem.dispose();
}
this.statusBarItems.clear();
2025-11-14 15:25:14 +08:00
}
}
2025-11-18 14:04:48 +08:00
if (hostname && port) {
const mappingKey = `${hostname}:${port}`;
this.portMappings.delete(mappingKey);
} else {
this.portMappings.clear();
}
2025-11-14 15:25:14 +08:00
}
}
2025-02-25 11:43:06 +08:00
/**
*
*/
export async function openProjectWithoutLogging(hostname: string, port: number, username: string, path: string): Promise<void> {
2025-11-18 14:04:48 +08:00
const command = `code --remote ssh-remote+${username}@${hostname}:${port} ${path} --reuse-window`;
try {
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
terminal.show(true);
terminal.sendText(command);
} catch (error) {
const errorMessage = error instanceof Error ? error.message : '未知错误';
vscode.window.showErrorMessage(`无登录打开项目失败: ${errorMessage}`);
}
2025-03-02 23:22:51 +08:00
}