diff --git a/.gitea/workflows/devstar-vscode-release.yaml b/.gitea/workflows/devstar-vscode-release.yaml index 37f1e5e..788bc56 100644 --- a/.gitea/workflows/devstar-vscode-release.yaml +++ b/.gitea/workflows/devstar-vscode-release.yaml @@ -22,6 +22,10 @@ jobs: run: | npm install + - name: 安装 Git + run: | + apk add --no-cache git + - name: 构建插件 run: | npm run package diff --git a/src/home.ts b/src/home.ts index 9b46333..4132ade 100644 --- a/src/home.ts +++ b/src/home.ts @@ -79,95 +79,9 @@ export default class DSHome { async (message) => { const data = message.data; const need_return = message.need_return; - if (need_return) { - // ================= need return ==================== + if (!need_return) { switch (message.command) { - // ----------------- frequent ----------------------- - case 'getHomeConfig': - const config = { - language: vscode.env.language - }; - panel.webview.postMessage({ command: 'getHomeConfig', data: { homeConfig: config } }); - break; - case 'getUserToken': - const userToken = this.user.getUserTokenFromLocal(); - if (userToken === undefined) { - panel.webview.postMessage({ command: 'getUserToken', data: { userToken: '' } }); - } else { - panel.webview.postMessage({ command: 'getUserToken', data: { userToken: userToken } }); - } - break; - case 'getUsername': - const username = this.user.getUsernameFromLocal(); - if (username === undefined) { - panel.webview.postMessage({ command: 'getUsername', data: { username: '' } }); - } else { - panel.webview.postMessage({ command: 'getUsername', data: { username: username } }); - } - 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.context); - break; - case 'getDevstarDomain': - panel.webview.postMessage({ command: 'getDevstarDomain', data: { devstarDomain: this.devstarDomain } }); - break; - // ----------------- not frequent ----------------------- - case 'setUserToken': - this.user.setUserTokenToLocal(data.userToken); - if (data.userToken === this.user.getUserTokenFromLocal()) { - panel.webview.postMessage({ command: 'setUserToken', data: { ok: true } }); - } else { - panel.webview.postMessage({ command: 'setUserToken', data: { ok: false } }); - } - break; - case 'setUsername': - this.user.setUsernameToLocal(data.username); - if (data.username === this.user.getUsernameFromLocal()) { - panel.webview.postMessage({ command: 'setUsername', data: { ok: true } }); - } else { - panel.webview.postMessage({ command: 'setUsername', data: { ok: false } }); - } - break; - case 'getUserPublicKey': - let userPublicKey = ''; - if (this.user.existUserPrivateKey()) { - userPublicKey = this.user.getUserPublicKey(); - } - panel.webview.postMessage({ command: 'getUserPublicKey', data: { userPublicKey: userPublicKey } }); - break; - case 'createUserPublicKey': - await this.user.createUserSSHKey(); - if (this.user.existUserPublicKey()) { - panel.webview.postMessage({ command: 'createUserPublicKey', data: { ok: true } }); - } else { - panel.webview.postMessage({ command: 'createUserPublicKey', data: { ok: false } }); - } - break; - case 'getMachineName': - const machineName = os.hostname(); - panel.webview.postMessage({ command: 'getMachineName', data: { machineName: machineName } }); - break; - } - } else { - // ================= don't need return ============== - // frequent - switch (message.command) { - // ----------------- frequent ----------------------- - case 'showInformationNotification': - vscode.window.showInformationMessage(data.message); - break; - case 'showWarningNotification': - vscode.window.showWarningMessage(data.message); - break; - case 'showErrorNotification': - await utils.showErrorNotification(data.message); - break; case 'openExternalUrl': - // 修复:直接从 message 中获取 url,而不是从 data const url = message.url || (data && data.url); if (url) { try { diff --git a/src/main.ts b/src/main.ts index 26d288c..00373ca 100644 --- a/src/main.ts +++ b/src/main.ts @@ -210,11 +210,6 @@ export class DevStarExtension { vscode.commands.registerCommand('devstar.showHome', () => this.dsHome.toggle() ), - vscode.commands.registerCommand('devstar.showPortMappings', () => { - // 这里需要根据当前活动连接获取hostname和port - // 简化实现:显示所有活动的端口映射 - this.remoteContainer.showPortMappingsInOutputChannel('current', 0); - }), vscode.commands.registerCommand('devstar.clean', () => { // 先清除ssh key if (fs.existsSync(this.user.getUserPrivateKeyPath())) { diff --git a/src/remote-container.ts b/src/remote-container.ts index 0750468..290f4b5 100644 --- a/src/remote-container.ts +++ b/src/remote-container.ts @@ -16,7 +16,6 @@ export default class RemoteContainer { private user: User; private sshProcesses?: Map; private portMappings: Map> = new Map(); - private statusBarItems?: Map; constructor(user: User) { this.user = user; @@ -313,93 +312,10 @@ export default class RemoteContainer { } 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 { - const showPortMappingsCommand = `devstar.showPortMappings.${mappingKey.replace(/[^a-zA-Z0-9]/g, '_')}`; - - 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 { - if (portMappings.length === 0) return; - - const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100); - - statusBarItem.text = `$(plug) ${portMappings.length} Ports`; - statusBarItem.tooltip = `点击查看 ${portMappings.length} 个端口映射详情`; - - statusBarItem.command = `devstar.showPortMappings.${mappingKey.replace(/[^a-zA-Z0-9]/g, '_')}`; - - statusBarItem.show(); - - 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 }> { - 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(); - - outputChannel.appendLine(`🎯 端口映射信息 - ${hostname}:${port}`); - outputChannel.appendLine('='.repeat(50)); - - 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(''); - }); - - outputChannel.appendLine('💡 提示: 您可以在浏览器中访问上述本地端口来访问容器中的服务'); - } /** * 本地环境,保存项目的ssh连接信息 @@ -444,10 +360,6 @@ export default class RemoteContainer { // 调用 setupPortForwardingFromGlobalState 方法 await this.setupPortForwardingFromGlobalState(sshConfig.hostname, port, context); - setTimeout(() => { - this.showPortMappingsPanel(sshConfig.hostname, port); - }, 3000); - } catch (portError) { vscode.window.showWarningMessage('端口映射设置失败,但容器连接已建立'); } @@ -504,43 +416,6 @@ export default class RemoteContainer { return null; } - /** - * 清理端口映射和相关UI - */ - 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(); - } - - 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(); - } - } - - if (hostname && port) { - const mappingKey = `${hostname}:${port}`; - this.portMappings.delete(mappingKey); - } else { - this.portMappings.clear(); - } - } /** * 从 globalState 获取 forwardPorts 并建立端口映射 @@ -572,7 +447,6 @@ export default class RemoteContainer { if (portMappings.length > 0) { this.showPortMappingsSummary(portMappings); - this.registerPortMappingsCommands(mappingKey, portMappings); } // 使用完毕后立即清除 globalState 中的 forwardPorts,避免影响下一个项目 diff --git a/src/user.ts b/src/user.ts index 828c1aa..58cbfeb 100644 --- a/src/user.ts +++ b/src/user.ts @@ -6,7 +6,6 @@ import DevstarAPIHandler from './devstar-api'; import * as utils from './utils'; const { generateKeyPairSync, - createHash } = require('node:crypto'); const sshpk = require('sshpk'); diff --git a/src/utils.ts b/src/utils.ts index d06a6a0..9315a37 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,7 +3,6 @@ import * as https from 'https'; import * as vscode from 'vscode'; import * as os from 'os'; import { exec } from 'child_process'; -import * as path from 'path'; const { generateKeyPairSync,