From 10ffe098c234624811bab51b6021977fe499e88e Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Sun, 22 Jun 2025 04:03:29 +0800 Subject: [PATCH] finish config export --- .../main-panel/chat/chat-box/options/export.vue | 2 +- src/global.ts | 15 +++++++++++++++ src/webview/webview.service.ts | 6 +++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/renderer/src/components/main-panel/chat/chat-box/options/export.vue b/renderer/src/components/main-panel/chat/chat-box/options/export.vue index ba2bec5..a797b98 100644 --- a/renderer/src/components/main-panel/chat/chat-box/options/export.vue +++ b/renderer/src/components/main-panel/chat/chat-box/options/export.vue @@ -155,7 +155,7 @@ const copyCode = async () => { const exportCode = async () => { const bridge = useMessageBridge(); bridge.postMessage({ - command: 'export-file', + command: 'vscode/export-file', data: { filename: exportFileName.value, content: generateExportData.value diff --git a/src/global.ts b/src/global.ts index c46e6b0..a7d0df8 100644 --- a/src/global.ts +++ b/src/global.ts @@ -377,3 +377,18 @@ export async function getFirstValidPathFromCommand(command: string, cwd: string) return undefined; } + + +export async function exportFile(filename: string, content: any) { + // 使用 vscode 的 api,创建文件导出窗口,询问用户 + const uri = await vscode.window.showSaveDialog({ + defaultUri: vscode.Uri.file(filename), + filters: { + 'JSON': ['json'] + } + }); + + if (uri) { + fs.writeFileSync(uri.fsPath, content, 'utf-8'); + } +} \ No newline at end of file diff --git a/src/webview/webview.service.ts b/src/webview/webview.service.ts index 8be19a3..c392bee 100644 --- a/src/webview/webview.service.ts +++ b/src/webview/webview.service.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode'; import * as fs from 'fs'; import * as fspath from 'path'; -import { ConnectionType, McpOptions, panels, updateInstalledConnectionConfig, updateWorkspaceConnectionConfig } from '../global.js'; +import { ConnectionType, exportFile, McpOptions, panels, updateInstalledConnectionConfig, updateWorkspaceConnectionConfig } from '../global.js'; import { routeMessage } from '../../openmcp-sdk/service/index.js'; export function getWebviewContent(context: vscode.ExtensionContext, panel: vscode.WebviewPanel): string | undefined { @@ -101,6 +101,10 @@ export function revealOpenMcpWebviewPanel( } break; + case 'vscode/export-file': + exportFile(data.filename, data.content); + break; + case 'vscode/clipboard/writeText': vscode.env.clipboard.writeText(data.text); break;