mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-02 10:50:49 +08:00
refactor(config): reload editor and auth files via events
This commit is contained in:
7
app.js
7
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 登录框
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user