feat(ui): 文件树在回合结束/回前台/重连后自动刷新
- 新增 reloadFileTree():保留展开与勾选,只重拉已展开的目录;250ms debounce + 1s 去重,多路触发合并 - 一轮跑完(engine 循环退出才发的 done)就地刷新;回前台 visibilitychange 与窗口重新聚焦也刷;断线重连补拉后补一次 - 修掉「切回文件树面板仍用旧缓存」:showFileTree 先失效再渲染 - 上传后改用 reloadFileTree,不再把用户已展开的目录收起来
This commit is contained in:
@@ -452,6 +452,7 @@
|
||||
// 侧栏底部「文件树」图标 → 切到这个面板(由 files.js 的 setDrawerPane 调用)。
|
||||
window.showFileTree = function () {
|
||||
ensureShell();
|
||||
invalidate(true); // 切回面板一律重拉已展开的目录,不拿上次的缓存糊弄(后台只标脏的也在这里补上)
|
||||
renderBody();
|
||||
};
|
||||
|
||||
@@ -462,6 +463,23 @@
|
||||
if (drawer && drawer.classList.contains('drawer-mode-files')) renderBody();
|
||||
};
|
||||
|
||||
// 按需刷新(一轮跑完 / 回前台 / 断线重连):保留展开与勾选,只重拉已展开的目录。
|
||||
// 不在文件树面板时只标脏不渲染,等切回来由 showFileTree 重新拉。
|
||||
let reloadTimer = 0, reloadAt = 0, reloading = false;
|
||||
window.reloadFileTree = function () {
|
||||
clearTimeout(reloadTimer);
|
||||
reloadTimer = setTimeout(async function () {
|
||||
if (Date.now() - reloadAt < 1000) return; // 刚刷过:多路触发(done/visibility/focus/resync)合并掉
|
||||
if (reloading) return; // 上一轮还在渲,跳过(它读到的就是刚清过的缓存)
|
||||
reloadAt = Date.now();
|
||||
invalidate(true);
|
||||
const drawer = $('drawer');
|
||||
if (!drawer || !drawer.classList.contains('drawer-mode-files')) return;
|
||||
reloading = true;
|
||||
try { await renderBody(); } finally { reloading = false; }
|
||||
}, 250);
|
||||
};
|
||||
|
||||
(function init() {
|
||||
if (!$('drawer-actions') || !$('files-tree')) return;
|
||||
req('GET', '/api/local/info').then(function (info) {
|
||||
|
||||
@@ -910,8 +910,9 @@
|
||||
// 全部成功不再弹提示(卡片已完成态即反馈);有失败才提醒
|
||||
if (errCount) toast('已上传 ' + done + ' 个,失败 ' + errCount + ' 个');
|
||||
loadFiles();
|
||||
// 桌面端左栏文件树是新的浏览入口,上传后要同步(旧面板只在手机端用)
|
||||
if (typeof window.refreshFileTree === 'function') window.refreshFileTree();
|
||||
// 桌面端左栏文件树是新的浏览入口,上传后要同步(旧面板只在手机端用);
|
||||
// 用 reloadFileTree 保留展开与勾选,refreshFileTree 会把用户展开的目录全收起来
|
||||
if (typeof window.reloadFileTree === 'function') window.reloadFileTree();
|
||||
// 1.2s 后收起进度条(还有别的批次在传就不收)
|
||||
setTimeout(() => {
|
||||
if (uploadBatches.size) return;
|
||||
|
||||
@@ -124,6 +124,8 @@
|
||||
}).catch(() => {}).then(() => {
|
||||
sseResyncing = false;
|
||||
if (state.sessionId === id && state.view === 'chat' && !state.es) connectStream();
|
||||
// 断点期间的文件变动看不到任何 SSE,补拉完顺手重刷一次文件树
|
||||
if (typeof window.reloadFileTree === 'function') window.reloadFileTree();
|
||||
});
|
||||
}
|
||||
setInterval(() => {
|
||||
@@ -179,6 +181,9 @@
|
||||
clearTimeout(sseSuspendTimer);
|
||||
clearTimeout(sseResumeProbeTimer);
|
||||
sseResumeProbeTimer = 0;
|
||||
// 回前台先刷一次文件树:后台期间的变动(工具产物/外部改动)直接补上;
|
||||
// 必须放在下方 sseSuspended 分支之前,否则「挂起后唤醒」这条路径会漏掉
|
||||
if (typeof window.reloadFileTree === 'function') window.reloadFileTree();
|
||||
// 后台已挂起:客户端不在线期间的 SSE 事件确定丢弃,必须补拉(增量渲染,不闪)
|
||||
if (sseSuspended) { resumeStream(); return; }
|
||||
if (!state.sessionId || state.view !== 'chat' || !state.es) return;
|
||||
@@ -187,6 +192,11 @@
|
||||
// 仍 OPEN 但心跳变旧:先给连接一个宽限自证,真静默才补拉
|
||||
if (Date.now() - state.lastSseAt > 45000) probeSseAlive();
|
||||
});
|
||||
// 窗口失去又获得焦点(如从 Finder 改完文件点回来):页面一直可见时 visibilitychange 不触发,
|
||||
// 只有 focus 能抓到;reloadFileTree 自带 debounce + 1s 去重,和上面的 visibilitychange 不会双刷
|
||||
window.addEventListener('focus', () => {
|
||||
if (state.sessionId && state.view === 'chat' && typeof window.reloadFileTree === 'function') window.reloadFileTree();
|
||||
});
|
||||
|
||||
// 地址栏跟随当前会话与侧栏模式:?s=<id>[&files=1],刷新/收藏/分享都能回到同一屏
|
||||
function syncUrl() {
|
||||
|
||||
@@ -473,6 +473,9 @@
|
||||
state.toolCallStreaming = {}; // 流式参数早卡映射随会话/回合重置
|
||||
updateScrollBottomBtn();
|
||||
loadSessionList();
|
||||
// 一轮完整跑完(agent 循环退出才发 done):工具/技能产物可能新增或改名,文件树就地刷新;
|
||||
// 不在文件树面板时 reloadFileTree 只标脏,等切回去再重拉
|
||||
if (typeof window.reloadFileTree === 'function') window.reloadFileTree();
|
||||
});
|
||||
// 服务端首次交互后自动生成的标题(finalize 后约 1s 到达):即时刷新顶栏 + 重拉会话列表(PC 常驻侧边栏/移动抽屉)
|
||||
es.addEventListener('title', ev => {
|
||||
|
||||
Reference in New Issue
Block a user