From f23e40facfa55dd61c418aa657ee98d3f1b41329 Mon Sep 17 00:00:00 2001 From: Hoemr <1441758285@qq.com> Date: Sun, 30 Aug 2026 17:55:37 +0800 Subject: [PATCH] fix(files): auto-refresh the tree on window focus and via a dispatchable event The tree caches loaded directories per refresh tick, so content edited outside DSH (another editor, a sync plugin pulling from a remote) stayed stale until the manual refresh click. - bump the tick when the window regains focus, so switching back to DSH shows the on-disk state - also bump on a bubbling 'dsh-sidebar:refresh-files' window event, so external plugins (e.g. dsh-better-overleaf after a pull/push) can refresh the tree programmatically without reaching into internals --- src/client/TreePanel.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/client/TreePanel.tsx b/src/client/TreePanel.tsx index 63d6162..e6638cf 100644 --- a/src/client/TreePanel.tsx +++ b/src/client/TreePanel.tsx @@ -72,6 +72,21 @@ export function TreePanel(props: { const [results, setResults] = useState<{ matches: string[]; truncated: boolean } | null>(null) const [error, setError] = useState(null) const [refreshTick, setRefreshTick] = useState(0) + + // The tree caches loaded directories per refresh tick, so content changed + // outside DSH (another editor, a sync tool) stays stale until the manual + // refresh click. Re-focusing the window bumps the tick automatically, and + // integrations can force a refresh by dispatching a bubbling + // `dsh-sidebar:refresh-files` event on `window`. + useEffect(() => { + const bump = (): void => { setRefreshTick(tick => tick + 1) } + window.addEventListener('focus', bump) + window.addEventListener('dsh-sidebar:refresh-files', bump) + return () => { + window.removeEventListener('focus', bump) + window.removeEventListener('dsh-sidebar:refresh-files', bump) + } + }, []) /** One-line upload status under the search row ('' hides the hint). */ const [uploadStatus, setUploadStatus] = useState('') /** Whether the status line is a failure/cancel (error color, stays visible). */