dsh-watch-together 0.2.6 → 0.2.8

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,91 @@
3
3
  All notable changes to **dsh-watch-together** are documented here.
4
4
  This package starts its own version line at `0.0.7` — it is not a continuation of `dsh-video-storyboard`.
5
5
 
6
+ ## [0.2.8] - 2026-11-03
7
+
8
+ > 三个社区 PR(都是 @ggfgfgf-on)+ 一批失效入口的清理。
9
+
10
+ ### Fixed — 多 P / 选集页面读错 `<video>`(合 PR #45,对应 #44)
11
+
12
+ 旧实现按 `duration` 挑播放器,遇到 B 站多语言版本这种页面,会挑中一个隐藏的 13 分钟长视频,
13
+ 上报的 `pos` 直接跳到 13:42,插件判定「换片了」,陪看中断。
14
+
15
+ 新逻辑:先排除不可见 / 零尺寸 / `opacity: 0` 的候选,再按在视口里占据的面积排序;
16
+ 播放中只加一档权重(不能压过更大的主播放器);认画中画和全屏;整页都不可见才退回全部。
17
+
18
+ ### Fixed — 气泡形状变化后不重合成(合 PR #42)
19
+
20
+ 静态跳帧只看 `_sig_bbox`,只清 `_sig` 不够。气泡/内框形状变了之后,如果桌面本身静止,
21
+ worker 会一直 `return None`,新遮罩和新色散要等用户动一下鼠标才出现。
22
+ `FORCE` 模式下看不出来,只在真机静置时暴露。
23
+
24
+ ### Fixed — `_tick` 每 4ms 重读一次配置(合 PR #47,fixes #46)
25
+
26
+ `not capturable()` 每拍读一次 `watch-window.json` —— `__init__` 早就把结果缓存在
27
+ `self._cappable` 了,这里纯属白花。0.2.7 引入的疏漏,谢谢抓出来。
28
+
29
+ ### Fixed — 删掉失效的 `run-glass*.cmd`,并去掉里面的本机绝对路径(#43)
30
+
31
+ 玻璃渲染重写之后 `DSH_WATCH_GLASS_TTL/FPS/CHROMA/BLUR/SAT` 和 `DSH_GLASS_ACRYLIC`
32
+ 已经没有任何代码读取,但那几个脚本还在设置它们:双击 `run-glass-acrylic.cmd` 以为开了
33
+ 亚克力,实际还是普通软件模糊。静默失效比报错更糟。
34
+
35
+ 现在只留一个 `run-glass.cmd`,开头列清哪些变量废弃、哪些真正有效;解释器也不再写死
36
+ 本机路径(先找 PATH 上的 `pythonw`,再退 `py -3`)—— 这个仓库是公开的。
37
+
38
+ ## [0.2.7] - 2026-11-03
39
+
40
+ > 五个社区 PR 一起收(都是 @ggfgfgf-on 提的),外加录屏模式的两个真 bug。
41
+
42
+ ### Fixed — 录屏/截图根本拍不到窗口
43
+
44
+ 窗口一直开着 `WDA_EXCLUDEFROMCAPTURE`(防截图/直播泄露,这是对的),
45
+ 但社区贡献者要调玻璃管线就必须能录。原来只有环境变量 `DSH_GLASS_WDA=0` 一个入口,
46
+ **而插件拉起窗口时不会传环境变量** —— 于是用户在 `~/.dsh/watch-window.json` 里写了
47
+ `"capturable": true` 也没人读,录出来永远是空桌面。
48
+
49
+ 现在 `capturable()` 真的读配置:环境变量(临时)→ 配置项(持久)→ 默认排除。
50
+
51
+ ### Fixed — 录屏模式下"字一直在闪"、拖尾越滚越浓
52
+
53
+ `capturable: true` 关掉 WDA 之后,**mss 抓背景时把窗口自己也抓进去了**。玻璃拿它当背景
54
+ 等于"透过自己看自己",形成反馈回路:背景里带着上一帧的字 → 亮度判据一直抖 → 字色来回翻;
55
+ 背景一直在变 → `moved` 一直为真 → 一直混合上一帧 → 越滚越浓的假拖尾(静止画面也在"动")。
56
+
57
+ 现在录屏模式下把窗口矩形用**周边均值**刷平(试过按上下边缘插值,相邻列颜色不同会变成
58
+ 一根根竖条,更难看)。窗口外 PAD 一圈仍是真背景,边缘透镜照常。
59
+ 实测同一位置连续 6 帧:帧差从"每次都在变"降到 **0.00**。
60
+
61
+ ### Added — 窗口心跳
62
+
63
+ `<cache>/window-heartbeat`,`_tick` 里每秒最多写一次。宿主那侧靠它区分"进程还在"和
64
+ "窗口真的在画"——只看 pid 的话,pid 被复用或界面卡死时永远认为窗还开着,于是再也不重开。
65
+
66
+ ### Fixed — GPU 抓屏越界(合 PR #40,作者 @ggfgfgf-on,fixes #39)
67
+
68
+ GPU 路径的 `capture_gpu()` 有自己一份 `sct.grab()`,没做 `gr-gl/gb-gt` 守卫;
69
+ 窗口被拖出屏幕时每帧抛 `Region has zero or negative size`,被 `_work()` 吞掉后背景永久停在旧帧。
70
+ 补上和 CPU 路径一样的检查。
71
+
72
+ ### Fixed — 台词 `at: null` 被存成第 0 秒(合 PR #38,作者 @ggfgfgf-on)
73
+
74
+ `Number(null) === 0`,显式写 `at: null` 的台词全被当成"第 0 秒",回读时挤在片头。
75
+
76
+ ### Fixed — 本机 API 的 CORS 与聊天游标(合 PR #35,作者 @ggfgfgf-on,fixes #33 #34)
77
+
78
+ - 聊天/位置 API 原来对**任意网页**放开 CORS,可被跨站写入;改成只认白名单。
79
+ - `chat.jsonl` 被清短之后,聊天页的游标永久卡在越界位置;改成越界自动归零。
80
+ - 新增 `test/chat-server-guards.test.mjs`。
81
+
82
+ ### Fixed — 卸载时没 detach voice adapter(合 PR #31,作者 @ggfgfgf-on,fixes #30)
83
+
84
+ 适配器订阅了 speech bus,插件卸载却没退订 —— `speechSubscribers()` 一直 > 0,
85
+ 重载后循环误以为"有人会念",模型再也不会被叫醒。
86
+
87
+ ### Added — 设置页自动保存(合 PR #32,作者 @ggfgfgf-on)
88
+
89
+ 改一项存一项,不用再点保存;顺带补了声音环境变量提示与连接状态。
90
+
6
91
  ## [0.2.6] - 2026-11-02
7
92
 
8
93
  > 陪看的声音还差最后一步:到点才开始合成。这一轮把"合成"从关键路径上挪开。
package/dsh.plugin.json CHANGED
@@ -1,12 +1,12 @@
1
- {
2
- "name": "dsh-watch-together",
3
- "description": "Watch a video together with a text-only agent: follow the user's real playback position and hand over one segment at a time, just before the segment ends.",
4
- "version": "0.2.6",
5
- "entry": {
6
- "name": "dsh-watch-together",
7
- "inject": [
8
- "tools",
9
- "attachments"
10
- ]
11
- }
12
- }
1
+ {
2
+ "name": "dsh-watch-together",
3
+ "description": "Watch a video together with a text-only agent: follow the user's real playback position and hand over one segment at a time, just before the segment ends.",
4
+ "version": "0.2.8",
5
+ "entry": {
6
+ "name": "dsh-watch-together",
7
+ "inject": [
8
+ "tools",
9
+ "attachments"
10
+ ]
11
+ }
12
+ }
@@ -448,6 +448,12 @@ def capture_gpu(self, sct):
448
448
  gt = max(0, t - G.PAD)
449
449
  gr = min(self._sw, r + G.PAD)
450
450
  gb = min(self._sh, b + G.PAD)
451
+ # 和 window.py 的 CPU 路径保持一致:多显示器 / DPI 变化 / 被别的程序
452
+ # 挪出屏幕时,钳位后的宽高可能 <= 0;mss 会抛
453
+ # "Region has zero or negative size",而 _work() 会每帧吞掉它 ——
454
+ # 表现就是日志每帧刷一条、背景永久停在旧帧。没有可抓的区域就别抓。
455
+ if gr - gl <= 0 or gb - gt <= 0:
456
+ return None
451
457
  shot = sct.grab({"left": gl, "top": gt, "width": gr - gl, "height": gb - gt})
452
458
  factor = 1.0 if _gpu.native else 4.0
453
459
  px = int(round((l - gl) / factor))
@@ -1,12 +1,40 @@
1
1
  @echo off
2
- rem 悬浮窗(液态玻璃)
3
- rem DSH_WATCH_GLASS_TTL 0 = 关掉实时玻璃(回到"开窗截一次");非 0 = 启用
4
- rem DSH_WATCH_GLASS_FPS 目标帧率,默认 30(本机实测能跑到 26~30Hz)
5
- rem DSH_WATCH_GLASS_CHROMA 色散强度,默认 8(0 = 完全关掉)
6
- rem DSH_WATCH_GLASS_BLUR 模糊半径,默认 13
7
- rem DSH_WATCH_GLASS_SAT 饱和度,默认 1.75
8
- set DSH_WATCH_GLASS_TTL=60
9
- set DSH_WATCH_GLASS_FPS=30
2
+ rem ---------------------------------------------------------------------------
3
+ rem 手工启动悬浮窗(开发/调试用)。正常使用时插件自己会拉起窗口,不需要这个。
4
+ rem
5
+ rem 【重要】旧版的这组变量在玻璃渲染重写之后**已经全部不读了**,设了也不会有
6
+ rem 任何效果 —— 见 issue #43。以前双击 run-glass-acrylic.cmd 以为开了亚克力,
7
+ rem 实际还是普通软件模糊:
8
+ rem
9
+ rem DSH_WATCH_GLASS_TTL / FPS / CHROMA / BLUR / SAT (不读)
10
+ rem DSH_GLASS_ACRYLIC (不读,没有 acrylic 路径了)
11
+ rem
12
+ rem 现在真正有效的开关:
13
+ rem
14
+ rem DSH_GLASS_NATIVE=1 走 GPU 路径(D3D11)
15
+ rem GLASS_FORCE=1 每帧强制重合成(调试用,很费 CPU)
16
+ rem DSH_GLASS_PREVIEW=1 预览模式:不抓屏,只贴最后一帧
17
+ rem DSH_GLASS_SNAPSHOT=1 文档截图模式:跑 2.5 秒后冻结画面
18
+ rem DSH_GLASS_WDA=0 允许截图/录屏拍到窗口(等价于配置里的 capturable)
19
+ rem
20
+ rem 尺寸、名字、capturable 这类持久设置写 ~/.dsh/watch-window.json。
21
+ rem ---------------------------------------------------------------------------
22
+
10
23
  cd /d "%~dp0"
11
- "C:/Users/10437/AppData/Local/Microsoft/WindowsApps/python.exe" window.py
24
+
25
+ rem 不写死解释器路径:先在 PATH 上找,找不到再试 py 启动器。
26
+ where pythonw >nul 2>&1
27
+ if %errorlevel%==0 (
28
+ start "" pythonw window.py
29
+ goto :eof
30
+ )
31
+ where py >nul 2>&1
32
+ if %errorlevel%==0 (
33
+ start "" py -3 window.py
34
+ goto :eof
35
+ )
36
+
37
+ echo 找不到 pythonw / py。
38
+ echo 需要一个带 tkinter 的 Python(python.org 官方包勾 tcl/tk,或 Microsoft Store 版),
39
+ echo 或者直接用插件拉起窗口(它自己会挑解释器)。
12
40
  pause
@@ -95,6 +95,38 @@ HEARTBEAT = cache_dir() / "window-heartbeat"
95
95
  HEARTBEAT_EVERY = 1.0
96
96
 
97
97
 
98
+ def _fill_own_rect(im, box):
99
+ """把「窗口自己」在抓屏帧里占的那块填掉。
100
+
101
+ **为什么必须填**:`capturable: true` 关掉了 `WDA_EXCLUDEFROMCAPTURE`,于是 mss
102
+ 抓背景时**把窗口自己也抓进去了**。玻璃再拿这张图当背景,就等于"透过自己看自己":
103
+
104
+ - 背景里带着上一帧的字 → 亮度判据一直抖 → **字色来回翻**(看起来就是"字在闪");
105
+ - 背景一直在变 → `moved` 一直为真 → 一直混合上一帧 → **越滚越浓的拖尾**
106
+ (那种"黏黏的"感觉其实是自激,不是真的动态模糊);
107
+ - 静止画面上也会出现"画面在自己动"。
108
+
109
+ 填法是拿这块上、下各一行像素做纵向线性插值 —— 得到一片渐变,像磨砂玻璃透出的
110
+ 环境色,不会有细节更不会有自己的内容。窗口外的 `PAD` 一圈仍然是真背景,
111
+ 边缘透镜照常能取到框外的料。
112
+ """
113
+ x0, y0, x1, y1 = (int(v) for v in box)
114
+ arr = np.asarray(im)
115
+ h, w = arr.shape[:2]
116
+ x0, x1 = max(1, min(w - 1, x0)), max(1, min(w - 1, x1))
117
+ y0, y1 = max(1, min(h - 2, y0)), max(1, min(h - 2, y1))
118
+ n = y1 - y0
119
+ if x1 <= x0 or n <= 0:
120
+ return im
121
+ out = arr.copy()
122
+ top = arr[y0 - 1, x0:x1].astype(np.float32)
123
+ bot = arr[y1, x0:x1].astype(np.float32)
124
+ t = ((np.arange(n, dtype=np.float32) + 1.0) / (n + 1.0))[:, None, None]
125
+ grad = top[None, :, :] * (1.0 - t) + bot[None, :, :] * t
126
+ out[y0:y1, x0:x1] = np.clip(grad, 0, 255).astype(np.uint8)
127
+ return Image.fromarray(out)
128
+
129
+
98
130
  def read_config():
99
131
  try:
100
132
  return json.loads(CONFIG.read_text(encoding="utf-8")) or {}
@@ -102,6 +134,28 @@ def read_config():
102
134
  return {}
103
135
 
104
136
 
137
+ def capturable():
138
+ """录屏 / 截图能不能拍到窗口。
139
+
140
+ 默认**不能** —— 走 `WDA_EXCLUDEFROMCAPTURE`,窗口不会出现在截图、直播、共享屏幕里。
141
+ 要给别人看效果、或者自己录一段发出来,就打开:
142
+
143
+ ```json
144
+ // ~/.dsh/watch-window.json
145
+ { "capturable": true }
146
+ ```
147
+
148
+ 环境变量 `DSH_GLASS_WDA=0` 也能打开,但它只对**这一次启动**有效(插件拉起窗口时不会传它),
149
+ 所以配置项才是那个"开关"。改完要重启窗口才生效。
150
+ """
151
+ if os.environ.get("DSH_GLASS_WDA") == "0":
152
+ return True
153
+ try:
154
+ return read_config().get("capturable") is True
155
+ except Exception:
156
+ return False
157
+
158
+
105
159
  def write_config(patch):
106
160
  cfg = read_config()
107
161
  cfg.update(patch or {})
@@ -484,6 +538,9 @@ class LiveGlass:
484
538
  self._bg = None
485
539
  self._hwnd = None
486
540
  self._excluded = False
541
+ # 录屏模式(capturable)下 mss 会抓到窗口自己,必须每帧挖掉,见 _fill_own_rect。
542
+ # 缓存起来:读配置是磁盘 IO,不能每帧做。
543
+ self._cappable = capturable()
487
544
  self._drag = None
488
545
  self._resize = None
489
546
  self._preview_at = 0.0
@@ -515,7 +572,7 @@ class LiveGlass:
515
572
  self._text_items = [i for i in self.canvas.find_all()
516
573
  if self.canvas.type(i) == "text"
517
574
  and i not in shadow_ids]
518
- self._set_exclude(os.environ.get("DSH_GLASS_WDA") != "0")
575
+ self._set_exclude(not capturable())
519
576
  self._worker.start()
520
577
  self.root.lift()
521
578
  self.root.after(80, self.root.lift)
@@ -892,6 +949,13 @@ class LiveGlass:
892
949
  ctypes.windll.user32.GetWindowRect(hwnd, ctypes.byref(rc))
893
950
  return (rc.left, rc.top, rc.right, rc.bottom)
894
951
 
952
+ def _invalidate_glass(self):
953
+ """让下一帧必须重新合成(静态跳帧只看 _sig_bbox,单清 _sig 不够)。"""
954
+ with self._geo_lock:
955
+ self._sig = None
956
+ self._sig_bbox = None
957
+ self._prev_out = None
958
+
895
959
  def _capture(self, sct):
896
960
  l, t, r, b = self._bbox()
897
961
  if r <= l or b <= t:
@@ -909,6 +973,10 @@ class LiveGlass:
909
973
  shot = sct.grab({"left": gl, "top": gt,
910
974
  "width": gr - gl, "height": gb - gt})
911
975
  im = Image.frombytes("RGB", shot.size, shot.rgb)
976
+ # **录屏模式必须挖掉自己**:WDA 关了之后 mss 会把窗口也抓进来,
977
+ # 玻璃拿它当背景就变成自我反馈(字闪 / 假拖尾 / 静止画面在动)。
978
+ if self._cappable:
979
+ im = _fill_own_rect(im, (l - gl, t - gt, r - gl, b - gt))
912
980
  sw4, sh4 = max(2, (gr - gl) // 4), max(2, (gb - gt) // 4)
913
981
  # 60fps 路径:只在 1/4 分辨率做一次模糊和折射,再放大。
914
982
  # cv2 的 resize 比 PIL 快一个数量级;没有 OpenCV 时无感回退。
@@ -1392,6 +1460,10 @@ class LiveGlass:
1392
1460
  if shapes != SHAPES:
1393
1461
  with self._geo_lock:
1394
1462
  apply_shapes(shapes)
1463
+ # 气泡/内框形状变了,合成的遮罩也变了;必须让上一帧的静态跳帧
1464
+ # 失效,否则桌面静止时 worker 会一直 return None,新遮罩/色散
1465
+ # 要等用户动一下鼠标或背景动一下才出现(调试 FORCE 模式下看不出)。
1466
+ self._invalidate_glass()
1395
1467
  # 每条消息只按正文占一块;时间戳贴在气泡上方,不进框。
1396
1468
  for info in infos:
1397
1469
  bx0, by0, bx1, by1, _r = info["shape"]
@@ -1681,7 +1753,7 @@ class LiveGlass:
1681
1753
  # 底部圆角/暗边会闪一下,看起来像渲染错位。
1682
1754
  self.root.after(INTERVAL_MS, self._tick)
1683
1755
  return
1684
- if not self._excluded and os.environ.get("DSH_GLASS_WDA") != "0":
1756
+ if not self._excluded and not self._cappable:
1685
1757
  self._set_exclude(True)
1686
1758
  self._pause.clear()
1687
1759
 
@@ -13,18 +13,51 @@
13
13
  /* global chrome */
14
14
 
15
15
  (() => {
16
- // 有些站点在一个页面里放多个 video(广告、预览、小窗)。
17
- // 挑"最像正在看的那个":优先在播的,其次时长长的。
16
+ // 有些站点在一个页面里放多个 video(广告、预览、小窗、多 P、多语言选集)。
17
+ // 挑"用户正在看的那个":先排除不可见 / 零尺寸的,再按可见面积选最大的;
18
+ // 播放中只加一点权重,不能让它压过一个更大的主播放器。
19
+ // 旧实现按 duration 选,多 P 页面会挑到隐藏的 13 分钟长视频,位置直接跳到另一集。
20
+ function visibleBox(v) {
21
+ if (!v.isConnected) return null;
22
+ const r = v.getBoundingClientRect();
23
+ if (!(r.width > 2 && r.height > 2)) return null;
24
+ let style;
25
+ try { style = getComputedStyle(v); } catch { return null; }
26
+ if (style.display === 'none' || style.visibility === 'hidden'
27
+ || Number(style.opacity) === 0) return null;
28
+ const left = Math.max(0, r.left);
29
+ const top = Math.max(0, r.top);
30
+ const right = Math.min(window.innerWidth, r.right);
31
+ const bottom = Math.min(window.innerHeight, r.bottom);
32
+ if (right - left <= 2 || bottom - top <= 2) return null;
33
+ return { area: (right - left) * (bottom - top) };
34
+ }
35
+
18
36
  function pickVideo() {
19
37
  const all = [...document.querySelectorAll('video')];
20
38
  if (all.length === 0) return null;
21
39
  if (all.length === 1) return all[0];
22
- const playing = all.filter((v) => !v.paused && !v.ended);
23
- const pool = playing.length > 0 ? playing : all;
24
- return pool.reduce((best, v) => {
25
- const score = (v) => (Number.isFinite(v.duration) ? v.duration : 0);
26
- return score(v) > score(best) ? v : best;
27
- }, pool[0]);
40
+
41
+ const viewport = Math.max(1, window.innerWidth * window.innerHeight);
42
+ const info = all.map((v) => ({ v, box: visibleBox(v) }));
43
+ // 先只在可见的里挑;整页都不可见(比如刚切走)时才退回全部。
44
+ const visible = info.filter((x) => x.box);
45
+ const pool = visible.length > 0 ? visible : info;
46
+ // 用户主动暂停时视频是 paused 但没 ended;只有 ended 才该让位给别的。
47
+ const live = pool.filter((x) => !x.v.ended);
48
+ const candidates = live.length > 0 ? live : pool;
49
+
50
+ const score = ({ v, box }) => {
51
+ let s = box ? (box.area / viewport) * 1e7 : 0;
52
+ if (!v.paused && !v.ended) s += 1e5;
53
+ if (v.readyState >= 2) s += 1e3;
54
+ if (v.currentTime > 0) s += 1e3;
55
+ if (v === document.pictureInPictureElement) s += 1e9;
56
+ const fs = document.fullscreenElement;
57
+ if (fs && fs !== document.documentElement && fs.contains(v)) s += 5e8;
58
+ return s;
59
+ };
60
+ return candidates.reduce((best, cur) => (score(cur) > score(best) ? cur : best)).v;
28
61
  }
29
62
 
30
63
  /**
package/lib/client.js CHANGED
@@ -87,6 +87,7 @@ window.__ModuleLoader__.load({
87
87
  browserPort: video.browserPort ? String(video.browserPort) : '',
88
88
  chatPort: watch.chatPort ? String(watch.chatPort) : '9377',
89
89
  adapter: typeof voice.adapter === 'string' ? voice.adapter : '',
90
+ voiceEnvOverrides: Array.isArray(voice.envOverrides) ? voice.envOverrides : [],
90
91
  };
91
92
  }
92
93
 
@@ -126,10 +127,14 @@ window.__ModuleLoader__.load({
126
127
  useInjectedStyle();
127
128
  const [form, setForm] = useState(null);
128
129
  const [checks, setChecks] = useState([]);
129
- const [busy, setBusy] = useState(false);
130
130
  const [checking, setChecking] = useState(false);
131
131
  const [error, setError] = useState('');
132
132
  const [notice, setNotice] = useState('');
133
+ const formRef = React.useRef(null);
134
+ const firstRender = React.useRef(true);
135
+ const saving = React.useRef(false);
136
+ const pending = React.useRef(false);
137
+ formRef.current = form;
133
138
 
134
139
  async function runCheck(api) {
135
140
  const target = api || apiConfig();
@@ -157,50 +162,86 @@ window.__ModuleLoader__.load({
157
162
  setError('设置接口未注入,请重启 DSH。');
158
163
  return undefined;
159
164
  }
160
- setBusy(true);
161
165
  apiCall(api, '/state').then(state => {
162
166
  if (cancelled) return;
163
167
  setForm(formFromState(state));
164
- setBusy(false);
165
168
  void runCheck(api);
166
169
  }).catch(e => {
167
170
  if (cancelled) return;
168
171
  setError(String(e && e.message ? e.message : e));
169
- setBusy(false);
170
172
  });
171
173
  return () => { cancelled = true; };
172
174
  }, []);
173
175
 
176
+ function validationError(current) {
177
+ const browserPort = current.browserPort === '' ? false : Number(current.browserPort);
178
+ if (browserPort !== false
179
+ && (!Number.isInteger(browserPort) || browserPort < 1 || browserPort > 65535)) {
180
+ return '浏览器调试端口必须是 1-65535 的整数。';
181
+ }
182
+ const chatPort = Number(current.chatPort);
183
+ if (!Number.isInteger(chatPort) || chatPort < 1 || chatPort > 65535) {
184
+ return '聊天服务端口必须是 1-65535 的整数。';
185
+ }
186
+ return '';
187
+ }
188
+
174
189
  async function save() {
175
- if (!form) return;
190
+ const current = formRef.current;
191
+ if (!current) return;
192
+ if (saving.current) {
193
+ pending.current = true;
194
+ return;
195
+ }
176
196
  const api = apiConfig();
177
197
  if (!api) {
178
198
  setError('设置接口未注入,请重启 DSH。');
179
199
  return;
180
200
  }
181
- setBusy(true);
201
+ const invalid = validationError(current);
202
+ if (invalid) {
203
+ setError(invalid);
204
+ setNotice('');
205
+ return;
206
+ }
207
+ saving.current = true;
182
208
  setError('');
183
209
  setNotice('');
184
210
  try {
185
211
  const video = {
186
- browserPort: form.browserPort === '' ? false : Number(form.browserPort),
212
+ browserPort: current.browserPort === '' ? false : Number(current.browserPort),
187
213
  };
188
- const watch = { chatPort: Number(form.chatPort) };
189
- const voice = { adapter: form.adapter };
214
+ const watch = { chatPort: Number(current.chatPort) };
215
+ const voice = { adapter: current.adapter };
190
216
  await apiCall(api, '/save', { video: video, watch: watch, voice: voice });
191
- setNotice('已保存。聊天端口改动在下次启动 DSH 后生效。');
217
+ setNotice('已自动保存。聊天端口改动在下次启动 DSH 后生效。');
192
218
  } catch (e) {
193
219
  setError(String(e && e.message ? e.message : e));
194
220
  } finally {
195
- setBusy(false);
221
+ saving.current = false;
222
+ if (pending.current) {
223
+ pending.current = false;
224
+ setTimeout(() => { void save(); }, 0);
225
+ }
196
226
  }
197
227
  }
198
228
 
229
+ useEffect(() => {
230
+ if (!form) return undefined;
231
+ if (firstRender.current) {
232
+ firstRender.current = false;
233
+ return undefined;
234
+ }
235
+ const timer = setTimeout(() => { void save(); }, 550);
236
+ return () => clearTimeout(timer);
237
+ }, [form && form.browserPort, form && form.chatPort, form && form.adapter]);
238
+
199
239
  if (!form) {
200
240
  return h('div', { 'data-dsh-vs': 'watch', className: 'dsh-vs dsh-vs-loading' }, error || '正在加载设置…');
201
241
  }
202
242
 
203
243
  const visibleChecks = checks.filter(item => item.id !== 'browser' && item.id !== 'chat' && item.id !== 'voice');
244
+ const connectionChecks = checks.filter(item => item.id === 'browser' || item.id === 'chat' || item.id === 'voice');
204
245
  const optionalIds = { python: true, extension: true, floating: true };
205
246
 
206
247
  return h('div', { 'data-dsh-vs': 'watch', className: 'dsh-vs' },
@@ -241,6 +282,28 @@ window.__ModuleLoader__.load({
241
282
  onChange: value => setForm(prev => ({ ...prev, adapter: value })),
242
283
  }),
243
284
  ),
285
+ form.voiceEnvOverrides.length
286
+ ? h('p', { className: 'dsh-vs-effective' },
287
+ '环境变量优先:' + form.voiceEnvOverrides.join('、') + ';这里的改动不会覆盖它们。')
288
+ : null,
289
+ ),
290
+ h('section', { className: 'dsh-vs-section' },
291
+ h('div', { className: 'dsh-vs-section-head' },
292
+ h('h3', { className: 'dsh-vs-section-title' }, '连接状态'),
293
+ ),
294
+ connectionChecks.length
295
+ ? h('div', { className: 'dsh-vs-deps' }, connectionChecks.map(check =>
296
+ h('div', { className: 'dsh-vs-dep', key: check.id },
297
+ h('span', {
298
+ className: 'dsh-vs-dot'
299
+ + (check.ok ? '' : optionalIds[check.id] ? ' is-warn' : ' is-bad'),
300
+ }),
301
+ h('div', { className: 'dsh-vs-dep-main' },
302
+ h('div', { className: 'dsh-vs-dep-name' }, check.label || check.id),
303
+ h('div', { className: 'dsh-vs-dep-detail', title: check.detail || '' }, check.detail || ''),
304
+ ),
305
+ )))
306
+ : h('p', { className: 'dsh-vs-hint' }, checking ? '正在检查…' : '尚未检查。'),
244
307
  ),
245
308
  h('section', { className: 'dsh-vs-section' },
246
309
  h('div', { className: 'dsh-vs-section-head' },
@@ -270,12 +333,6 @@ window.__ModuleLoader__.load({
270
333
  : h('p', { className: 'dsh-vs-hint' }, checking ? '正在检查…' : '尚未检查。'),
271
334
  ),
272
335
  h('div', { className: 'dsh-vs-footer' },
273
- h('button', {
274
- type: 'button',
275
- className: 'dsh-vs-btn dsh-vs-btn-primary',
276
- disabled: busy,
277
- onClick: save,
278
- }, busy ? '保存中…' : '保存'),
279
336
  h('span', { className: 'dsh-vs-status' + (error ? ' is-error' : ''), role: 'status' },
280
337
  error || notice),
281
338
  ),
package/package.json CHANGED
@@ -1,115 +1,115 @@
1
- {
2
- "name": "dsh-watch-together",
3
- "version": "0.2.6",
4
- "description": "Watch a video together with a text-only agent: follow the user's real playback position, hand over one segment at a time just before it ends, and keep a single text stream of scripted lines, interjections and the user's replies.",
5
- "keywords": [
6
- "dsh",
7
- "dsh-plugin",
8
- "deepseek-harness",
9
- "video",
10
- "watch-together",
11
- "watch-party",
12
- "companion",
13
- "playback",
14
- "subtitle",
15
- "caption",
16
- "tts"
17
- ],
18
- "homepage": "https://github.com/SAOS-3624/dsh-watch-together#readme",
19
- "bugs": {
20
- "url": "https://github.com/SAOS-3624/dsh-watch-together/issues"
21
- },
22
- "repository": {
23
- "type": "git",
24
- "url": "git+https://github.com/SAOS-3624/dsh-watch-together.git"
25
- },
26
- "author": "SAOS-3624",
27
- "license": "Apache-2.0",
28
- "type": "module",
29
- "main": "./src/index.js",
30
- "exports": {
31
- ".": "./src/index.js",
32
- "./client": "./lib/client.js",
33
- "./register": "./src/register.js",
34
- "./tool-spec": "./src/tool-spec.js",
35
- "./watch": "./src/watch.js",
36
- "./batches": "./src/batches.js",
37
- "./chat": "./src/chat.js",
38
- "./voice": "./src/voice.js",
39
- "./speech-bus": "./src/speech-bus.js",
40
- "./voice-adapter": "./src/voice-adapter.js",
41
- "./interfaces": "./src/interfaces.js",
42
- "./public-api": "./src/public-api.js",
43
- "./recognition-interface": "./src/recognition-interface.js",
44
- "./tts-interface": "./src/tts-interface.js",
45
- "./window-interface": "./src/window-interface.js",
46
- "./window-protocol": "./src/window-protocol.js"
47
- },
48
- "bin": {
49
- "dsh-watch": "./bin/watch.mjs",
50
- "dsh-watch-lines": "./bin/lines.mjs"
51
- },
52
- "files": [
53
- "src",
54
- "lib",
55
- "bin",
56
- "extension",
57
- "scripts",
58
- "docs",
59
- "cordis.patch.yml",
60
- "dsh.plugin.json",
61
- "README.md",
62
- "CHANGELOG.md",
63
- "LICENSE",
64
- "NOTICE",
65
- "examples/floating-chat/*.py",
66
- "examples/floating-chat/*.cmd",
67
- "examples/floating-chat/*.png",
68
- "examples/floating-chat/*.txt",
69
- "examples/voice-edge-tts/index.mjs"
70
- ],
71
- "engines": {
72
- "node": ">=20"
73
- },
74
- "scripts": {
75
- "test": "node --test",
76
- "pretest": "node scripts/sync-dep.mjs",
77
- "sync:dep": "node scripts/sync-dep.mjs",
78
- "prepublishOnly": "node scripts/check-syntax.mjs && node --test",
79
- "check": "node scripts/check-syntax.mjs",
80
- "doctor": "node bin/watch.mjs doctor",
81
- "install:extension": "node bin/watch.mjs install-extension",
82
- "sim": "node scripts/watch-sim.mjs",
83
- "e2e": "node scripts/watch-e2e.mjs"
84
- },
85
- "dependencies": {
86
- "dsh-video-storyboard": "^0.6.0"
87
- },
88
- "peerDependencies": {
89
- "@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
90
- },
91
- "peerDependenciesMeta": {
92
- "@deepseek-ai/dsh-tools": {
93
- "optional": true
94
- }
95
- },
96
- "dsh": {
97
- "bundle": {
98
- "patch": "./cordis.patch.yml"
99
- },
100
- "client": {
101
- "platform": "web"
102
- },
103
- "catalog": {
104
- "category": "tool",
105
- "summary": {
106
- "en": "Watch a video together with a text-only agent: it follows your real playback position and hands over one segment at a time, just before that segment ends.",
107
- "zh": "和只有文字的智能体一起看视频:跟着你真实的播放位置,一段一段把画面和台词交到它手上,在每段结束前说完。"
108
- },
109
- "capabilities": [
110
- "fs",
111
- "shell"
112
- ]
113
- }
114
- }
115
- }
1
+ {
2
+ "name": "dsh-watch-together",
3
+ "version": "0.2.8",
4
+ "description": "Watch a video together with a text-only agent: follow the user's real playback position, hand over one segment at a time just before it ends, and keep a single text stream of scripted lines, interjections and the user's replies.",
5
+ "keywords": [
6
+ "dsh",
7
+ "dsh-plugin",
8
+ "deepseek-harness",
9
+ "video",
10
+ "watch-together",
11
+ "watch-party",
12
+ "companion",
13
+ "playback",
14
+ "subtitle",
15
+ "caption",
16
+ "tts"
17
+ ],
18
+ "homepage": "https://github.com/SAOS-3624/dsh-watch-together#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/SAOS-3624/dsh-watch-together/issues"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/SAOS-3624/dsh-watch-together.git"
25
+ },
26
+ "author": "SAOS-3624",
27
+ "license": "Apache-2.0",
28
+ "type": "module",
29
+ "main": "./src/index.js",
30
+ "exports": {
31
+ ".": "./src/index.js",
32
+ "./client": "./lib/client.js",
33
+ "./register": "./src/register.js",
34
+ "./tool-spec": "./src/tool-spec.js",
35
+ "./watch": "./src/watch.js",
36
+ "./batches": "./src/batches.js",
37
+ "./chat": "./src/chat.js",
38
+ "./voice": "./src/voice.js",
39
+ "./speech-bus": "./src/speech-bus.js",
40
+ "./voice-adapter": "./src/voice-adapter.js",
41
+ "./interfaces": "./src/interfaces.js",
42
+ "./public-api": "./src/public-api.js",
43
+ "./recognition-interface": "./src/recognition-interface.js",
44
+ "./tts-interface": "./src/tts-interface.js",
45
+ "./window-interface": "./src/window-interface.js",
46
+ "./window-protocol": "./src/window-protocol.js"
47
+ },
48
+ "bin": {
49
+ "dsh-watch": "./bin/watch.mjs",
50
+ "dsh-watch-lines": "./bin/lines.mjs"
51
+ },
52
+ "files": [
53
+ "src",
54
+ "lib",
55
+ "bin",
56
+ "extension",
57
+ "scripts",
58
+ "docs",
59
+ "cordis.patch.yml",
60
+ "dsh.plugin.json",
61
+ "README.md",
62
+ "CHANGELOG.md",
63
+ "LICENSE",
64
+ "NOTICE",
65
+ "examples/floating-chat/*.py",
66
+ "examples/floating-chat/*.cmd",
67
+ "examples/floating-chat/*.png",
68
+ "examples/floating-chat/*.txt",
69
+ "examples/voice-edge-tts/index.mjs"
70
+ ],
71
+ "engines": {
72
+ "node": ">=20"
73
+ },
74
+ "scripts": {
75
+ "test": "node --test",
76
+ "pretest": "node scripts/sync-dep.mjs",
77
+ "sync:dep": "node scripts/sync-dep.mjs",
78
+ "prepublishOnly": "node scripts/check-syntax.mjs && node --test",
79
+ "check": "node scripts/check-syntax.mjs",
80
+ "doctor": "node bin/watch.mjs doctor",
81
+ "install:extension": "node bin/watch.mjs install-extension",
82
+ "sim": "node scripts/watch-sim.mjs",
83
+ "e2e": "node scripts/watch-e2e.mjs"
84
+ },
85
+ "dependencies": {
86
+ "dsh-video-storyboard": "^0.6.0"
87
+ },
88
+ "peerDependencies": {
89
+ "@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
90
+ },
91
+ "peerDependenciesMeta": {
92
+ "@deepseek-ai/dsh-tools": {
93
+ "optional": true
94
+ }
95
+ },
96
+ "dsh": {
97
+ "bundle": {
98
+ "patch": "./cordis.patch.yml"
99
+ },
100
+ "client": {
101
+ "platform": "web"
102
+ },
103
+ "catalog": {
104
+ "category": "tool",
105
+ "summary": {
106
+ "en": "Watch a video together with a text-only agent: it follows your real playback position and hands over one segment at a time, just before that segment ends.",
107
+ "zh": "和只有文字的智能体一起看视频:跟着你真实的播放位置,一段一段把画面和台词交到它手上,在每段结束前说完。"
108
+ },
109
+ "capabilities": [
110
+ "fs",
111
+ "shell"
112
+ ]
113
+ }
114
+ }
115
+ }
@@ -38,19 +38,49 @@ export async function startChatServer({
38
38
 
39
39
  // 扩展从**网页的源**发请求,属于跨域;而且是从公网页面访问本地地址,
40
40
  // Chrome 的 Private Network Access 还要求预检里看到 allow-private-network。
41
- // 我们只暴露"上报位置"和"读位置",没有敏感信息,所以直接放开。
42
- const cors = {
43
- 'access-control-allow-origin': '*',
44
- 'access-control-allow-methods': 'GET, POST, OPTIONS',
45
- 'access-control-allow-headers': 'content-type',
46
- 'access-control-allow-private-network': 'true',
47
- 'cache-control': 'no-store',
48
- };
41
+ //
42
+ // **不能直接放开成 `*`**:否则用户随便打开一个网页,它就能向本机 9377 写假台词、
43
+ // 伪造播放位置。只放行扩展来源和同端口的本机页面;没有 Origin 的请求(CLI、Python
44
+ // 悬浮窗、curl)保持可用 —— 浏览器发起的跨域请求一定会带 Origin。
45
+ const EXTENSION_SCHEMES = new Set(['chrome-extension:', 'moz-extension:', 'safari-web-extension:']);
46
+ function isAllowedOrigin(origin, port) {
47
+ if (!origin) return true;
48
+ try {
49
+ const u = new URL(origin);
50
+ if (EXTENSION_SCHEMES.has(u.protocol)) return true;
51
+ if (u.protocol !== 'http:') return false;
52
+ const host = u.hostname;
53
+ if (host !== '127.0.0.1' && host !== 'localhost' && host !== '[::1]') return false;
54
+ const p = Number(u.port || 80);
55
+ return Number.isInteger(p) && p === Number(port);
56
+ } catch {
57
+ return false;
58
+ }
59
+ }
60
+ function corsFor(origin) {
61
+ return {
62
+ 'access-control-allow-origin': origin || '*',
63
+ 'access-control-allow-methods': 'GET, POST, OPTIONS',
64
+ 'access-control-allow-headers': 'content-type',
65
+ 'access-control-allow-private-network': 'true',
66
+ 'cache-control': 'no-store',
67
+ };
68
+ }
49
69
 
50
70
  const server = createServer(async (req, res) => {
51
71
  let u;
52
72
  try { u = new URL(req.url, 'http://127.0.0.1'); } catch { res.writeHead(400); res.end(); return; }
53
73
 
74
+ const port = server.address()?.port ?? listenPort;
75
+ const origin = typeof req.headers.origin === 'string' && req.headers.origin
76
+ ? req.headers.origin : null;
77
+ if (!isAllowedOrigin(origin, port)) {
78
+ res.writeHead(403, { 'content-type': 'text/plain; charset=utf-8' });
79
+ res.end('origin not allowed');
80
+ return;
81
+ }
82
+ const cors = corsFor(origin);
83
+
54
84
  // 扩展直接 fetch(不经过 service worker)时会有这一趟预检
55
85
  if (req.method === 'OPTIONS') {
56
86
  res.writeHead(204, cors);
@@ -107,8 +137,16 @@ export async function startChatServer({
107
137
  if (u.pathname === '/api/messages') {
108
138
  const since = Math.max(0, Number(u.searchParams.get('since')) || 0);
109
139
  const all = readChat(env);
110
- res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
111
- res.end(JSON.stringify({ total: all.length, msgs: all.slice(since) }));
140
+ // 页面按"已读条数"轮询。chat.jsonl 被清空/重写后文件会比 since 短,
141
+ // 这时 slice(since) 永远是空的 —— 页面从此再也看不到新消息。让页面知道
142
+ // 该重置游标,而不是让它永远卡在旧条数上。
143
+ const reset = since > all.length;
144
+ res.writeHead(200, { ...cors, 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
145
+ res.end(JSON.stringify({
146
+ total: all.length,
147
+ msgs: reset ? all : all.slice(since),
148
+ ...(reset ? { reset: true } : {}),
149
+ }));
112
150
  return;
113
151
  }
114
152
  if (u.pathname === '/api/say' && req.method === 'POST') {
@@ -128,7 +166,7 @@ export async function startChatServer({
128
166
  } catch { /* 坏请求就算了 */ }
129
167
  // ok:false 让页面能把话回填进输入框 —— 之前一律 ok:true,
130
168
  // 服务端没写进去用户也不知道,字就丢了
131
- res.writeHead(200, { 'content-type': 'application/json' });
169
+ res.writeHead(200, { ...cors, 'content-type': 'application/json' });
132
170
  res.end(JSON.stringify({ ok }));
133
171
  });
134
172
  return;
package/src/chat-view.js CHANGED
@@ -56,6 +56,9 @@ input:focus{border-color:#4a7ab5}
56
56
  var n=0;
57
57
  function poll(){
58
58
  fetch(BASE+"/api/messages?since="+n+"&t="+Date.now()).then(function(r){return r.json();}).then(function(j){
59
+ // chat.jsonl 被清空/重写过:游标比文件长,服务端会回 reset。清屏重放,
60
+ // 否则页面会一直用旧条数 slice,新消息永远不出现。
61
+ if(j.reset){log.innerHTML="";n=0;}
59
62
  for(var k=0;k<j.msgs.length;k++)add(j.msgs[k]);
60
63
  n=j.total;setTimeout(poll,600);
61
64
  }).catch(function(){setTimeout(poll,1500);});
package/src/index.js CHANGED
@@ -102,10 +102,18 @@ async function registerAll(ctx) {
102
102
  // 声音适配器(可选):只通过 tts 接口挂,不 import voice.js。
103
103
  // 这里也保留启动时挂载,这样第一次只调 `say`(还没开窗)也有声音。
104
104
  try {
105
- const v = await getTtsPort().attachConfigured?.({ log: (m) => ctx?.logger?.info?.(m) });
105
+ const tts = getTtsPort();
106
+ const v = await tts.attachConfigured?.({ log: (m) => ctx?.logger?.info?.(m) });
106
107
  if (v && !v.ok && v.reason !== 'not-configured') {
107
108
  ctx?.logger?.warn?.(`[dsh-watch-together] voice adapter not loaded: ${v.reason}`);
108
109
  }
110
+ // 适配器订阅了 speech bus;插件卸载必须退订,否则 speechSubscribers()
111
+ // 会一直 > 0,重载后循环误以为"有人会念",模型就再也不会被叫醒。
112
+ if (v?.ok && typeof tts.detachConfigured === 'function') {
113
+ disposers.push(() => {
114
+ try { void tts.detachConfigured(); } catch { /* 卸载失败不能影响其他 disposer */ }
115
+ });
116
+ }
109
117
  } catch (e) {
110
118
  ctx?.logger?.warn?.(`[dsh-watch-together] voice adapter crashed: ${e?.message ?? e}`);
111
119
  }
@@ -118,6 +118,8 @@ export function readVoiceSettings(env = process.env) {
118
118
  exists: raw.exists,
119
119
  error: raw.error,
120
120
  adapter: typeof raw.data.adapter === 'string' ? raw.data.adapter : '',
121
+ envOverrides: ['DSH_VOICE_ADAPTER']
122
+ .filter((k) => env[k] !== undefined && env[k] !== ''),
121
123
  };
122
124
  }
123
125
 
@@ -115,11 +115,12 @@ function floatingWindow() {
115
115
 
116
116
  function voice(env) {
117
117
  const cfg = readVoiceSettings(env);
118
- if (!cfg.adapter) return { ok: false, detail: '未配置(可选;只影响念台词)' };
119
- if (/^[a-zA-Z]:[\\/]|^\\\\|^\.{1,2}[\\/]|^\//.test(cfg.adapter)) {
120
- return { ok: existsSync(cfg.adapter), detail: existsSync(cfg.adapter) ? cfg.adapter : '文件不存在:' + cfg.adapter };
118
+ const adapter = String(env.DSH_VOICE_ADAPTER || '').trim() || cfg.adapter;
119
+ if (!adapter) return { ok: false, detail: '未配置(可选;只影响念台词)' };
120
+ if (/^[a-zA-Z]:[\\/]|^\\\\|^\.{1,2}[\\/]|^\//.test(adapter)) {
121
+ return { ok: existsSync(adapter), detail: existsSync(adapter) ? adapter : '文件不存在:' + adapter };
121
122
  }
122
- return { ok: true, detail: cfg.adapter + '(包名,挂载时才能校验)' };
123
+ return { ok: true, detail: adapter + '(包名,挂载时才能校验)' };
123
124
  }
124
125
 
125
126
  /** @returns {Promise<Array<{id:string,label:string,ok:boolean,detail:string}>>} */
@@ -16,6 +16,7 @@ export const TTS_INTERFACE_VERSION = 1;
16
16
  * speechSubscribers: Function,
17
17
  * lastSpeech: Function,
18
18
  * attachConfiguredVoice?: Function,
19
+ * detachAdapters?: Function,
19
20
  * attachedAdapters?: Function,
20
21
  * configuredVoiceAdapter?: Function,
21
22
  * }} bus
@@ -23,7 +24,7 @@ export const TTS_INTERFACE_VERSION = 1;
23
24
  export function createTtsInterface(bus = {}) {
24
25
  const {
25
26
  onSpeech, emitSpeech, emitSpoken, speechSubscribers, lastSpeech,
26
- attachConfiguredVoice, attachedAdapters, configuredVoiceAdapter,
27
+ attachConfiguredVoice, detachAdapters, attachedAdapters, configuredVoiceAdapter,
27
28
  } = bus;
28
29
  for (const [name, fn] of Object.entries({ onSpeech, emitSpeech, speechSubscribers, lastSpeech })) {
29
30
  if (typeof fn !== 'function') throw new TypeError(`tts: ${name}() is required`);
@@ -53,6 +54,7 @@ export function createTtsInterface(bus = {}) {
53
54
  return lastSpeech();
54
55
  },
55
56
  attachConfigured: typeof attachConfiguredVoice === 'function' ? attachConfiguredVoice : null,
57
+ detachConfigured: typeof detachAdapters === 'function' ? detachAdapters : null,
56
58
  attached: typeof attachedAdapters === 'function' ? attachedAdapters : () => [],
57
59
  configured: typeof configuredVoiceAdapter === 'function' ? configuredVoiceAdapter : () => null,
58
60
  });
@@ -166,9 +166,17 @@ export async function saveLines(input, lines, { env = process.env } = {}) {
166
166
  // `at` 除了秒数,还可以直接传**字幕原文片段**,这里去转写里查它的 from。
167
167
  // 为什么必须有这条路:模型凭印象写秒数会整段错 —— 实测把"1/4 螺口"挂在 189 秒,
168
168
  // 而字幕里它在 247 秒,提前了 58 秒,用户当场发现"台词对不上视频"。
169
- let at = Number(l?.at);
170
- if (typeof l?.at === 'string' && l.at.trim()) {
171
- const q = l.at.trim();
169
+ //
170
+ // **null 和"没写 at"同义**:显式传 `at: null` 是合法输入(校验允许),
171
+ // 但 `Number(null) === 0` 会把它存成"第 0 秒"——第 180 段的那句从此永远
172
+ // 是"迟到 180 秒"被 dueLine 丢掉,用户看到的是"写了台词却没念"。
173
+ // 这里只接受数字或非空字符串;其余(null / undefined / 空串)都当没写。
174
+ const rawAt = l?.at;
175
+ let at = NaN;
176
+ if (typeof rawAt === 'number') {
177
+ at = rawAt;
178
+ } else if (typeof rawAt === 'string' && rawAt.trim()) {
179
+ const q = rawAt.trim();
172
180
  // **先查落盘的 `subs-<key>.json`,再查 locate 的进程内记忆**。
173
181
  // 后者只有 4 条、重启就空,而台词恰恰经常在另一个进程/另一轮里写 ——
174
182
  // 查不到就会被当成"没写 at",落到段首:用户看到的就是"台词比画面早一大截"。
@@ -1,7 +0,0 @@
1
- @echo off
2
- rem 同上,但目标 60fps —— 本机一轮 32ms,实际约 30Hz,多出来的帧会被丢掉
3
- set DSH_WATCH_GLASS_TTL=60
4
- set DSH_WATCH_GLASS_FPS=60
5
- cd /d "%~dp0"
6
- "C:/Users/10437/AppData/Local/Microsoft/WindowsApps/python.exe" window.py
7
- pause
@@ -1,8 +0,0 @@
1
- @echo off
2
- rem 磨砂模式:背景由 Windows 的 GPU 合成(DWM Acrylic),一次屏都不截。
3
- rem 气泡和标题栏会变成实心卡片(Tk 不支持半透明叠加)。
4
- rem 想调色调:DSH_GLASS_ACRYLIC_TINT,ABGR 十六进制,默认 0xB4121014
5
- set DSH_GLASS_ACRYLIC=1
6
- cd /d "%~dp0"
7
- "C:/Users/10437/AppData/Local/Microsoft/WindowsApps/python.exe" window.py
8
- pause
@@ -1,7 +0,0 @@
1
- @echo off
2
- rem 同上,但**关掉色散** —— 用来对比"色散到底是不是卡的原因"
3
- set DSH_WATCH_GLASS_TTL=120
4
- set DSH_WATCH_GLASS_CHROMA=0
5
- cd /d "%~dp0"
6
- "C:/Users/10437/AppData/Local/Microsoft/WindowsApps/python.exe" window.py
7
- pause