From 323485445da223e31fcf86d9037f2301cf4b834a Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Fri, 21 Nov 2025 10:36:04 +0800 Subject: [PATCH] refactor(config): reload editor and auth files via events --- app.js | 7 +++++++ src/core/connection.js | 7 ++----- src/modules/auth-files.js | 15 +++++++++++++++ src/modules/config-editor.js | 15 +++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index baac3ca..cbe5c86 100644 --- a/app.js +++ b/app.js @@ -150,6 +150,9 @@ class CLIProxyManager { this.initializeTheme(); this.registerSettingsListeners(); this.registerUsageListeners(); + if (typeof this.registerConfigEditorListeners === 'function') { + this.registerConfigEditorListeners(); + } this.checkLoginStatus(); this.bindEvents(); this.setupNavigation(); @@ -161,6 +164,10 @@ class CLIProxyManager { this.updateLoginConnectionInfo(); // 检查主机名,如果不是 localhost 或 127.0.0.1,则隐藏 OAuth 登录框 this.checkHostAndHideOAuth(); + + if (typeof this.registerAuthFilesListeners === 'function') { + this.registerAuthFilesListeners(); + } } // 检查主机名并隐藏 OAuth 登录框 diff --git a/src/core/connection.js b/src/core/connection.js index 44d6b98..f1d0ff7 100644 --- a/src/core/connection.js +++ b/src/core/connection.js @@ -328,15 +328,12 @@ export const connectionModule = { // 认证文件需要单独加载,因为不在配置中 await this.loadAuthFiles(keyStats); - // 加载配置文件编辑器内容 - await this.loadConfigFileEditor(forceRefresh); - this.refreshConfigEditor(); - if (this.events && typeof this.events.emit === 'function') { this.events.emit('data:config-loaded', { config, usageData, - keyStats + keyStats, + forceRefresh }); } diff --git a/src/modules/auth-files.js b/src/modules/auth-files.js index a1c9e11..88ed85d 100644 --- a/src/modules/auth-files.js +++ b/src/modules/auth-files.js @@ -1025,5 +1025,20 @@ export const authFilesModule = { // 清空文件输入框,允许重复上传同一文件 event.target.value = ''; } + }, + + registerAuthFilesListeners() { + if (!this.events || typeof this.events.on !== 'function') { + return; + } + this.events.on('data:config-loaded', async (event) => { + const detail = event?.detail || {}; + const keyStats = detail.keyStats || null; + try { + await this.loadAuthFiles(keyStats); + } catch (error) { + console.error('加载认证文件失败:', error); + } + }); } }; diff --git a/src/modules/config-editor.js b/src/modules/config-editor.js index d8e8195..7834bac 100644 --- a/src/modules/config-editor.js +++ b/src/modules/config-editor.js @@ -252,5 +252,20 @@ export const configEditorModule = { throw new Error(data.message || data.error || 'Server rejected the update'); } } + }, + + registerConfigEditorListeners() { + if (!this.events || typeof this.events.on !== 'function') { + return; + } + this.events.on('data:config-loaded', async (event) => { + const detail = event?.detail || {}; + try { + await this.loadConfigFileEditor(detail.forceRefresh || false); + this.refreshConfigEditor(); + } catch (error) { + console.error('加载配置文件失败:', error); + } + }); } };