feat: centralize config refresh handling and prevent races
This commit is contained in:
28
app.js
28
app.js
@@ -68,6 +68,9 @@ class CLIProxyManager {
|
||||
// 状态更新定时器
|
||||
this.statusUpdateTimer = null;
|
||||
this.lastConnectionStatusEmitted = null;
|
||||
this.isGlobalRefreshInProgress = false;
|
||||
|
||||
this.registerCoreEventHandlers();
|
||||
|
||||
// 日志自动刷新定时器
|
||||
this.logsRefreshTimer = null;
|
||||
@@ -149,6 +152,7 @@ class CLIProxyManager {
|
||||
init() {
|
||||
this.initUiVersion();
|
||||
this.initializeTheme();
|
||||
this.registerCoreEventHandlers();
|
||||
this.registerSettingsListeners();
|
||||
this.registerUsageListeners();
|
||||
if (typeof this.registerLogsListeners === 'function') {
|
||||
@@ -173,6 +177,30 @@ class CLIProxyManager {
|
||||
}
|
||||
}
|
||||
|
||||
registerCoreEventHandlers() {
|
||||
if (!this.events || typeof this.events.on !== 'function') {
|
||||
return;
|
||||
}
|
||||
this.events.on('config:refresh-requested', async (event) => {
|
||||
const detail = event?.detail || {};
|
||||
const forceRefresh = detail.forceRefresh !== false;
|
||||
// 避免并发触发导致重复请求
|
||||
if (this.isGlobalRefreshInProgress) {
|
||||
return;
|
||||
}
|
||||
await this.runGlobalRefresh(forceRefresh);
|
||||
});
|
||||
}
|
||||
|
||||
async runGlobalRefresh(forceRefresh = false) {
|
||||
this.isGlobalRefreshInProgress = true;
|
||||
try {
|
||||
await this.loadAllData(forceRefresh);
|
||||
} finally {
|
||||
this.isGlobalRefreshInProgress = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查主机名并隐藏 OAuth 登录框
|
||||
checkHostAndHideOAuth() {
|
||||
const hostname = window.location.hostname;
|
||||
|
||||
Reference in New Issue
Block a user