finish config export

This commit is contained in:
锦恢 2025-06-22 04:03:29 +08:00
parent d10c88f35e
commit 10ffe098c2
3 changed files with 21 additions and 2 deletions

View File

@ -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

View File

@ -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');
}
}

View File

@ -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;