Watch selected folders and reconcile bounded changes with media freshness guards

This commit is contained in:
karl committed 2026-10-13 02:30:38 +02:00
1 parent 99748bd99f
commit 657de3de86
22 files changed
+2022 -149

No files matched your search

+55
View File
@@ -77,6 +77,13 @@ interface DesktopStatus {
settings: Settings;
indexing: boolean;
shortcut_status: string;
watching?: {
root: string;
attached: boolean;
pending: boolean;
error: string | null;
watch_error: string | null;
}[];
}
interface SemanticStatus {
model: string;
@@ -452,6 +459,16 @@ async function refreshDesktopStatus() {
const path = document.createElement("span");
path.textContent = displayPath(root);
path.className = "path";
const watched = status.watching?.find((entry) => entry.root === root);
if (watched) {
path.title = watched.error
? `Automatic updates need attention: ${watched.error}`
: watched.pending
? "Checking for file changes…"
: watched.attached
? "Watching for file changes"
: "Checking for changes automatically";
}
const reindex = document.createElement("button");
reindex.type = "button";
reindex.textContent = "Reindex";
@@ -1039,6 +1056,31 @@ function submitSearch(request: SearchRequest, lane: SearchLane) {
(lane === "lexical" ? lexicalLane : hybridLane).submit(request);
}
function refreshIndexedSearch() {
const previous = latestSearch;
if (
!previous ||
previous.id !== requestId ||
query.value.trim() !== previous.query
)
return;
clearTimeout(hybridTimer);
lexicalLane.clear();
hybridLane.clear();
querySemanticFailed = false;
shownLane = "lexical";
// Keep the original input/first-response timing while rejecting responses
// captured before the index changed, even when the query text stays identical.
const refreshed: SearchRequest = { ...previous, id: ++requestId };
latestSearch = refreshed;
submitSearch(refreshed, "lexical");
if (canSearchSemantically()) {
hybridTimer = setTimeout(() => {
if (isCurrent(refreshed)) submitSearch(refreshed, "hybrid");
}, SEMANTIC_SETTLE_MS);
}
}
const isCurrent = (request: SearchRequest) => request.id === requestId;
const lexicalLane = new LatestLane<SearchRequest>(
async (request) => {
@@ -1366,6 +1408,19 @@ async function initializeSurface() {
void refreshDesktopStatus().catch(showError);
queueSemanticRefresh(0);
}).catch(showError);
if (isNativeDesktop()) {
void listen("folder-indexing-changed", () => {
void refreshDesktopStatus().catch(showError);
queueSemanticRefresh(0);
}).catch(showError);
void listen("search-index-changed", () => {
folderRevision++;
void refreshStats().catch(showError);
void refreshDesktopStatus().catch(showError);
queueSemanticRefresh(0);
refreshIndexedSearch();
}).catch(showError);
}
// Poll only during a user-triggered job; idle indexing status does no work.
setInterval(() => {
if (indexingActive) void refreshDesktopStatus().catch(showError);