dsh-task-cat 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/client.js +40 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -62,6 +62,8 @@ Harness 的桌面外壳并没有向插件开放窗口 API(preload 只暴露文
62
62
 
63
63
  实现上它是只读标注:侧栏工作区行由应用自己渲染、没有暴露插槽,所以插件读 `useSessions` / `useWorkspaces` 算出每个工作区的进行中数量,再往对应行(`data-row-key="workspace:<id>"`、`aria-expanded="false"`)里插入一个徽章,并用 MutationObserver 在重渲染后补回。插件不改写、不替换行内任何应用内容。
64
64
 
65
+ 标记的写入是幂等的、并按帧合并:观察器只在一帧里重画一次,值没变就不写 DOM。否则「写入 → 观察器 → 再写入」会自我触发成死循环,把主线程占满——表现就是点侧栏时整个应用卡住。
66
+
65
67
  ## 交互
66
68
 
67
69
  - **点宠物**:展开/收起任务清单,按紧急程度排序:进行中 → 待查看 → 有进度 → 失败 → 已完成 → 空闲。
package/client.js CHANGED
@@ -969,7 +969,8 @@ window.__ModuleLoader__.load({
969
969
  return;
970
970
  }
971
971
  if (existing !== null) {
972
- existing.textContent = String(count);
972
+ const text = String(count);
973
+ if (existing.textContent !== text) existing.textContent = text;
973
974
  return;
974
975
  }
975
976
  const badge = document.createElement('span');
@@ -985,14 +986,49 @@ window.__ModuleLoader__.load({
985
986
  else row.appendChild(badge);
986
987
  };
987
988
 
989
+ // Painting writes badges into rows the sidebar owns, and those writes are
990
+ // themselves mutations. Feeding them straight back into `paintAll` is an
991
+ // endless loop on the main thread — the collapse button appeared to hang
992
+ // the whole app. Three rules keep it terminating: paint while flagged,
993
+ // coalesce callbacks into one frame, and write only on a real change.
994
+ let painting = false;
995
+ let frame = 0;
996
+
988
997
  const paintAll = () => {
989
- for (const row of document.querySelectorAll('[data-row-key^="workspace:"]')) paint(row);
998
+ if (painting) return;
999
+ painting = true;
1000
+ try {
1001
+ for (const row of document.querySelectorAll('[data-row-key^="workspace:"]')) paint(row);
1002
+ } finally {
1003
+ painting = false;
1004
+ }
1005
+ };
1006
+
1007
+ const schedule = () => {
1008
+ if (painting || frame !== 0) return;
1009
+ const run = () => {
1010
+ frame = 0;
1011
+ paintAll();
1012
+ };
1013
+ frame = typeof requestAnimationFrame === 'function'
1014
+ ? requestAnimationFrame(run)
1015
+ : setTimeout(run, 32);
990
1016
  };
1017
+
991
1018
  paintAll();
992
- const observer = new MutationObserver(paintAll);
993
- observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['aria-expanded', 'data-row-key'] });
1019
+ // Watch the list area when the sidebar exposes it; body only as a
1020
+ // fallback, so unrelated app activity cannot wake this up.
1021
+ const scope = document.querySelector('[data-sidebar-list-area]') ?? document.body;
1022
+ const observer = new MutationObserver(schedule);
1023
+ observer.observe(scope, {
1024
+ childList: true,
1025
+ subtree: true,
1026
+ attributes: true,
1027
+ attributeFilter: ['aria-expanded', 'data-row-key']
1028
+ });
994
1029
  return () => {
995
1030
  observer.disconnect();
1031
+ if (frame !== 0 && typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame);
996
1032
  for (const badge of document.querySelectorAll('[data-dsh-task-cat="workspace"]')) badge.remove();
997
1033
  };
998
1034
  }, [running, groups]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-task-cat",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Task cat: a floating white cat that watches every session's progress and jumps into the conversation that needs you.",
5
5
  "type": "module",
6
6
  "exports": {