From 49a3b14797d7d2dc4c96872c8e4facfefafbc15d Mon Sep 17 00:00:00 2001
From: Kirigaya <1193466151@qq.com>
Date: Mon, 14 Jul 2025 01:44:20 +0800
Subject: [PATCH] save
---
renderer/src/App.vue | 3 ++-
.../main-panel/tool/auto-detector/index.vue | 2 +-
renderer/src/hook/mcp.ts | 1 +
renderer/src/hook/setting.ts | 1 +
renderer/src/views/setting/general.vue | 19 ++++-----------
service/src/hook/setting.ts | 7 +++++-
service/src/index.ts | 2 +-
service/src/setting/setting.service.ts | 24 ++++++++-----------
src/extension.ts | 1 +
src/i18n/index.ts | 8 +++++++
10 files changed, 36 insertions(+), 32 deletions(-)
diff --git a/renderer/src/App.vue b/renderer/src/App.vue
index 1e3e59d..99c2cd6 100644
--- a/renderer/src/App.vue
+++ b/renderer/src/App.vue
@@ -24,6 +24,7 @@ import { userHasReadGuide } from './components/guide/tour';
import PasswordDialog from '@/components/password-dialog/index.vue';
import { privilegeStatus } from './components/password-dialog/status';
+import { useI18n } from 'vue-i18n';
const bridge = useMessageBridge();
@@ -66,7 +67,7 @@ onMounted(async () => {
Connection.showPanel = false;
});
- await initialise();
+ await initialise();
});
diff --git a/renderer/src/components/main-panel/tool/auto-detector/index.vue b/renderer/src/components/main-panel/tool/auto-detector/index.vue
index 5e38d4c..142e862 100644
--- a/renderer/src/components/main-panel/tool/auto-detector/index.vue
+++ b/renderer/src/components/main-panel/tool/auto-detector/index.vue
@@ -73,7 +73,7 @@
diff --git a/service/src/hook/setting.ts b/service/src/hook/setting.ts
index 32d190e..4c51e6a 100644
--- a/service/src/hook/setting.ts
+++ b/service/src/hook/setting.ts
@@ -1,5 +1,6 @@
export let VSCODE_WORKSPACE = '';
export let RUNNING_CWD = '';
+export let DEFAULT_LANG = 'zh';
export function setVscodeWorkspace(workspace: string) {
VSCODE_WORKSPACE = workspace;
@@ -7,4 +8,8 @@ export function setVscodeWorkspace(workspace: string) {
export function setRunningCWD(path: string) {
RUNNING_CWD = path;
-}
\ No newline at end of file
+}
+
+export function setDefaultLang(lang: string) {
+ DEFAULT_LANG = lang;
+}
diff --git a/service/src/index.ts b/service/src/index.ts
index ae85e0c..5001b94 100644
--- a/service/src/index.ts
+++ b/service/src/index.ts
@@ -1,4 +1,4 @@
export { routeMessage } from './common/router.js';
export { VSCodeWebViewLike } from './hook/adapter.js';
-export { setVscodeWorkspace, setRunningCWD } from './hook/setting.js';
+export { setVscodeWorkspace, setRunningCWD, setDefaultLang } from './hook/setting.js';
export { clientMap } from './mcp/connect.service.js';
\ No newline at end of file
diff --git a/service/src/setting/setting.service.ts b/service/src/setting/setting.service.ts
index 40233d3..3671e92 100644
--- a/service/src/setting/setting.service.ts
+++ b/service/src/setting/setting.service.ts
@@ -1,7 +1,7 @@
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
-import { VSCODE_WORKSPACE } from '../hook/setting.js';
+import { DEFAULT_LANG, VSCODE_WORKSPACE } from '../hook/setting.js';
import { IConfig } from './setting.dto.js';
import { llms } from '../hook/llm.js';
@@ -14,20 +14,15 @@ function getConfigurationPath() {
return path.join(configDir, 'setting.json');
}
-function getDefaultLanguage() {
- if (process.env.VSCODE_PID) {
- // TODO: 获取 vscode 内部的语言
-
+function getDefaultConfig() {
+ return {
+ MODEL_INDEX: 0,
+ LLM_INFO: llms,
+ LANG: DEFAULT_LANG,
+ MCP_TIMEOUT_SEC: 60
}
- return 'zh';
}
-const DEFAULT_CONFIG: IConfig = {
- MODEL_INDEX: 0,
- LLM_INFO: llms,
- LANG: getDefaultLanguage(), MCP_TIMEOUT_SEC: 60
-};
-
function createConfig(): IConfig {
const configPath = getConfigurationPath();
@@ -39,8 +34,9 @@ function createConfig(): IConfig {
}
// 写入默认配置
- fs.writeFileSync(configPath, JSON.stringify(DEFAULT_CONFIG, null, 2), 'utf-8');
- return DEFAULT_CONFIG;
+ const defaultConfig = getDefaultConfig();
+ fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2), 'utf-8');
+ return defaultConfig;
}
export function loadSetting(): IConfig {
diff --git a/src/extension.ts b/src/extension.ts
index 6f6a407..821bdd5 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -13,6 +13,7 @@ export function activate(context: vscode.ExtensionContext) {
const workspace = workspaceFolder?.uri.fsPath || '';
setVscodeWorkspace(workspace);
setRunningCWD(context.extensionPath);
+
initialiseI18n(context);
// 添加i18n调试信息
diff --git a/src/i18n/index.ts b/src/i18n/index.ts
index 2cb183a..e110cd1 100644
--- a/src/i18n/index.ts
+++ b/src/i18n/index.ts
@@ -4,6 +4,14 @@ import * as path from 'path';
const defaultBundle: Record = {}
+export function getDefaultLanguage() {
+ const lang = vscode.env.language || 'en';
+ if (lang === 'zh-cn') {
+ return 'zh';
+ }
+ return lang;
+}
+
export function initialiseI18n(context: vscode.ExtensionContext) {
if (vscode.l10n.bundle === undefined) {
// 获取用户的语言设置