diff --git a/content/content.js b/content/content.js index aef8c98..d932cf5 100644 --- a/content/content.js +++ b/content/content.js @@ -365,9 +365,16 @@ if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text canStart = true; }); setInterval(function () { - BRIDGE.health().then(function (r) { if (UI && UI.setConnected) UI.setConnected(!!(r && r.ok)); }); + BRIDGE.health().then(function (r) { + if (UI && UI.setConnected) UI.setConnected(!!(r && r.ok)); + if (r && r.ok) __refreshStats(); + }); }, 30000); __refreshStats(); + // Keep stats fresh: without this, if bridge was down at init, the panel + // stays stuck at "? 0 (always 0)" until F5. Refresh every 30s, and also + // immediately on every successful health probe. + setInterval(__refreshStats, 30000); }); }); function __refreshStats() { try { var DB = globalThis.DSH_BRIDGE; if (!UI || !UI.setStats) return; if (!DB || !DB.fetchBridge) { UI.setStats('?', 0, 0); return; } DB.fetchBridge('GET', '/memory/state').then(function (j) { var st = (j && j.ok && j.data) ? j.data : {}; var entries = st.entries || []; var total = entries.length; var alwaysN = entries.filter(function (e) { return e.importance === 'always' && e.state !== 'archive' && e.state !== 'done'; }).length; return DB.fetchBridge('GET', '/health').then(function (hj) { UI.setStats((hj && hj.ok && hj.workspace) || '?', total, alwaysN); }); }).catch(function (e) { console.warn('[dsh-memory] stats ' + String(e)); UI.setStats('?', 0, 0); }); } catch (e) { console.warn('[dsh-memory] stats ' + String(e)); } }