From f2d7d8f3b14931c2c9b92737ed92e88fd207b449 Mon Sep 17 00:00:00 2001 From: JOJO <1498581755@qq.com> Date: Sun, 31 May 2026 23:28:10 +0800 Subject: [PATCH] fix(ui): refresh git summary while idle --- static/src/app/lifecycle.ts | 2 ++ static/src/app/methods/ui.ts | 25 +++++++++++++++++++++++++ static/src/app/state.ts | 2 ++ 3 files changed, 29 insertions(+) diff --git a/static/src/app/lifecycle.ts b/static/src/app/lifecycle.ts index 7337a05..d8fffc6 100644 --- a/static/src/app/lifecycle.ts +++ b/static/src/app/lifecycle.ts @@ -42,6 +42,7 @@ export async function mounted() { // 立即加载初始数据(并行获取状态,优先同步运行模式) const initialDataPromise = this.loadInitialData(); this.refreshProjectGitSummary?.(); + this.startProjectGitSummaryIdleRefresh?.(); this.startConnectionHeartbeat(); this.checkTutorialPrompt(); if (initialDataPromise && typeof initialDataPromise.then === 'function') { @@ -118,6 +119,7 @@ export function beforeUnmount() { this.teardownMobileViewportWatcher(); this.subAgentStopPolling(); this.backgroundCommandStopPolling(); + this.stopProjectGitSummaryIdleRefresh?.(); this.resourceStopContainerStatsPolling(); this.resourceStopProjectStoragePolling(); this.resourceStopUsageQuotaPolling(); diff --git a/static/src/app/methods/ui.ts b/static/src/app/methods/ui.ts index 7bf5673..7c27fb0 100644 --- a/static/src/app/methods/ui.ts +++ b/static/src/app/methods/ui.ts @@ -154,7 +154,30 @@ function parseSystemNoticeLabel(rawContent: any): string | null { } export const uiMethods = { + startProjectGitSummaryIdleRefresh() { + if (this.projectGitSummaryRefreshTimer) { + return; + } + this.projectGitSummaryRefreshTimer = window.setInterval(() => { + if (!this.isConnected) return; + if (typeof this.isOutputActive === 'function' && this.isOutputActive()) return; + this.refreshProjectGitSummary?.({ idleFallback: true }); + }, 5000); + }, + + stopProjectGitSummaryIdleRefresh() { + if (!this.projectGitSummaryRefreshTimer) { + return; + } + window.clearInterval(this.projectGitSummaryRefreshTimer); + this.projectGitSummaryRefreshTimer = null; + }, + async refreshProjectGitSummary() { + if (this.projectGitSummaryRefreshing) { + return; + } + this.projectGitSummaryRefreshing = true; try { const resp = await fetch('/api/project/git-summary'); const payload = await resp.json().catch(() => ({})); @@ -170,6 +193,8 @@ export const uiMethods = { } catch (_) { this.projectGitSummary = null; this.gitChangesDiff = null; + } finally { + this.projectGitSummaryRefreshing = false; } }, diff --git a/static/src/app/state.ts b/static/src/app/state.ts index 203d230..e7ddc91 100644 --- a/static/src/app/state.ts +++ b/static/src/app/state.ts @@ -37,6 +37,8 @@ export function dataState() { runtimeQueueSyncLockKey: '', runtimeQueueSyncLockUntil: 0, projectGitSummary: null, + projectGitSummaryRefreshTimer: null, + projectGitSummaryRefreshing: false, gitChangesPanelOpen: false, gitChangesLoading: false, gitChangesError: '',