dsh-watch-together 0.2.14 → 0.3.0

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.
@@ -9,6 +9,9 @@
9
9
  拆出来的原因只有一个:`window.py` 原来 1900 行里,这三块和「拖动/缩放/渲染
10
10
  状态机」混在一起,改一个阈值要在同一文件里翻三遍。
11
11
  """
12
+ # 3.9 兼容:`dict | None` 这类注解要 future import 才不求值(见 #45)。
13
+ from __future__ import annotations
14
+
12
15
  import json
13
16
  import time
14
17
  from pathlib import Path
@@ -62,6 +65,10 @@ class ChatFeed:
62
65
  def __init__(self, path: Path):
63
66
  self.path = path
64
67
  self.messages: list[dict] = []
68
+ # **本轮 poll 新增的消息**。弹幕只该飘"新来的",不能把可见区那 4 条
69
+ # 反复推一遍;用 messages 长度差算,而不是让 add() 自己记 ——
70
+ # add() 也被 reload() 调,那样重载历史会一次性刷 80 条弹幕。
71
+ self.recent: list[dict] = []
65
72
  self.status = ""
66
73
  self.offset = 0 # 相对最新一条的滚动量
67
74
  self._seen: set = set()
@@ -112,6 +119,7 @@ class ChatFeed:
112
119
  def reload(self) -> None:
113
120
  """重读最后 80 行(文件被清短 / 首次加载)。"""
114
121
  self.messages = []
122
+ self.recent = []
115
123
  self._seen.clear()
116
124
  self._pos = 0
117
125
  self.offset = 0
@@ -124,7 +132,8 @@ class ChatFeed:
124
132
  self._pos = 0
125
133
 
126
134
  def poll(self) -> bool:
127
- """增量读;返回是否有变化。"""
135
+ """增量读;返回是否有变化。本轮新增的消息放在 `self.recent`。"""
136
+ self.recent = []
128
137
  try:
129
138
  size = self.path.stat().st_size
130
139
  except OSError:
@@ -139,10 +148,13 @@ class ChatFeed:
139
148
  data = f.read()
140
149
  self._pos = f.tell()
141
150
  changed = False
151
+ before = len(self.messages)
142
152
  for line in data.splitlines():
143
153
  if self.add(self.parse(line)):
144
154
  changed = True
145
155
  if changed:
156
+ # 只取非 meta 的那部分:meta 走 `status`,不进 messages
157
+ self.recent = self.messages[before:]
146
158
  if self.offset > 0:
147
159
  self.offset += len(data.splitlines())
148
160
  self.offset = max(0, min(self.offset, max(0, len(self.messages) - MESSAGE_SLOTS)))
@@ -241,6 +253,22 @@ class TextLayer:
241
253
  lx = x - width if right else (x - width / 2 if center else x)
242
254
  ly = (y + row * linespace + height / 2 if top
243
255
  else y + (row - (len(lines) - 1) / 2) * linespace)
256
+ if not adapt:
257
+ # 颜色固定(这块字有自己的底板)→ **整行一个 item**。
258
+ #
259
+ # 逐字的唯一理由是"同一行左右两半背后明暗不同、要各自翻色",
260
+ # `adapt=False` 时那个理由不存在,留着就是白建 5×字符数 个 item
261
+ # (1 个字 + 4 层描边)。滚一格重排要几百毫秒,大半花在这儿(#44)。
262
+ #
263
+ # 位置和逐字版本一致:Tk 8.6 不做字距调整,整串宽度 = 逐字宽度之和。
264
+ for dx, dy in stroke:
265
+ self.canvas.create_text(lx + dx, ly + dy, text=line, anchor="w",
266
+ fill=self.COLOR_DARK, font=spec,
267
+ tags=shadow_tags)
268
+ item = self.canvas.create_text(lx, ly, text=line, anchor="w",
269
+ fill=fill, font=spec, tags=tags)
270
+ self._fixed.add(item)
271
+ continue
244
272
  # 累积宽度,别对每个字重新 measure 前缀(那是 O(n²) 次 Tcl 调用)
245
273
  cx = lx
246
274
  for ch in line:
@@ -248,10 +276,8 @@ class TextLayer:
248
276
  self.canvas.create_text(cx + dx, ly + dy, text=ch, anchor="w",
249
277
  fill=self.COLOR_DARK, font=spec,
250
278
  tags=shadow_tags)
251
- item = self.canvas.create_text(cx, ly, text=ch, anchor="w",
252
- fill=fill, font=spec, tags=tags)
253
- if not adapt:
254
- self._fixed.add(item)
279
+ self.canvas.create_text(cx, ly, text=ch, anchor="w",
280
+ fill=fill, font=spec, tags=tags)
255
281
  cx += measure(ch)
256
282
 
257
283
  # ---- 翻色 ----
package/package.json CHANGED
@@ -1,133 +1,133 @@
1
- {
2
- "name": "dsh-watch-together",
3
- "version": "0.2.14",
4
- "description": "Watch a video together, in sync with the user's real playback: every segment arrives as one storyboard image plus its subtitle lines just before it ends, while the floating window carries spoken replies and live room audio — picture and voice, not a transcript.",
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
- "contributors": [
28
- {
29
- "name": "ggfgfgf-on",
30
- "url": "https://github.com/ggfgfgf-on"
31
- },
32
- {
33
- "name": "gao804",
34
- "url": "https://github.com/gao804"
35
- },
36
- {
37
- "name": "DreamDLYY",
38
- "url": "https://github.com/DreamDLYY"
39
- }
40
- ],
41
- "license": "Apache-2.0",
42
- "type": "module",
43
- "main": "./src/index.js",
44
- "exports": {
45
- ".": "./src/index.js",
46
- "./client": "./lib/client.js",
47
- "./register": "./src/register.js",
48
- "./tool-spec": "./src/tool-spec.js",
49
- "./watch": "./src/watch.js",
50
- "./batches": "./src/batches.js",
51
- "./chat": "./src/chat.js",
52
- "./voice": "./src/voice.js",
53
- "./speech-bus": "./src/speech-bus.js",
54
- "./voice-adapter": "./src/voice-adapter.js",
55
- "./interfaces": "./src/interfaces.js",
56
- "./public-api": "./src/public-api.js",
57
- "./recognition-interface": "./src/recognition-interface.js",
58
- "./tts-interface": "./src/tts-interface.js",
59
- "./window-interface": "./src/window-interface.js",
60
- "./window-protocol": "./src/window-protocol.js"
61
- },
62
- "bin": {
63
- "dsh-watch": "./bin/watch.mjs",
64
- "dsh-watch-lines": "./bin/lines.mjs"
65
- },
66
- "files": [
67
- "src",
68
- "lib",
69
- "bin",
70
- "extension",
71
- "scripts",
72
- "docs",
73
- "cordis.patch.yml",
74
- "dsh.plugin.json",
75
- "README.md",
76
- "CHANGELOG.md",
77
- "CREDITS.md",
78
- "LICENSE",
79
- "NOTICE",
80
- "examples/floating-chat/*.py",
81
- "examples/floating-chat/*.cmd",
82
- "examples/floating-chat/*.png",
83
- "examples/floating-chat/*.txt",
84
- "examples/voice-edge-tts/index.mjs",
85
- "examples/voice-edge-tts/stream/*.mjs",
86
- "examples/voice-edge-tts/stream/*.py",
87
- "examples/voice-edge-tts/stream/*.mp3"
88
- ],
89
- "engines": {
90
- "node": ">=20"
91
- },
92
- "scripts": {
93
- "test": "node --test",
94
- "pretest": "node scripts/sync-dep.mjs",
95
- "sync:dep": "node scripts/sync-dep.mjs",
96
- "prepublishOnly": "node scripts/check-syntax.mjs && node --test",
97
- "check": "node scripts/check-syntax.mjs",
98
- "doctor": "node bin/watch.mjs doctor",
99
- "install:extension": "node bin/watch.mjs install-extension",
100
- "sim": "node scripts/watch-sim.mjs",
101
- "e2e": "node scripts/watch-e2e.mjs"
102
- },
103
- "dependencies": {
104
- "dsh-video-storyboard": "^0.6.0"
105
- },
106
- "peerDependencies": {
107
- "@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
108
- },
109
- "peerDependenciesMeta": {
110
- "@deepseek-ai/dsh-tools": {
111
- "optional": true
112
- }
113
- },
114
- "dsh": {
115
- "bundle": {
116
- "patch": "./cordis.patch.yml"
117
- },
118
- "client": {
119
- "platform": "web"
120
- },
121
- "catalog": {
122
- "category": "tool",
123
- "summary": {
124
- "en": "Watch a video together, in sync with the user's playback: each segment arrives as one storyboard image plus its subtitle lines just before it ends, and the floating window carries spoken replies and live room audio.",
125
- "zh": "和智能体一起看视频:跟着真实播放位置,每段结束前把分镜画面 + 带秒台词交过去;悬浮窗里能出声,也听得见房间里的声音 —— 给的是画面和声音,不是一段转写文本。"
126
- },
127
- "capabilities": [
128
- "fs",
129
- "shell"
130
- ]
131
- }
132
- }
133
- }
1
+ {
2
+ "name": "dsh-watch-together",
3
+ "version": "0.3.0",
4
+ "description": "Watch a video together, in sync with the user's real playback: every segment arrives as one storyboard image plus its subtitle lines just before it ends, while the floating window carries spoken replies and live room audio — picture and voice, not a transcript.",
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
+ "contributors": [
28
+ {
29
+ "name": "ggfgfgf-on",
30
+ "url": "https://github.com/ggfgfgf-on"
31
+ },
32
+ {
33
+ "name": "gao804",
34
+ "url": "https://github.com/gao804"
35
+ },
36
+ {
37
+ "name": "DreamDLYY",
38
+ "url": "https://github.com/DreamDLYY"
39
+ }
40
+ ],
41
+ "license": "Apache-2.0",
42
+ "type": "module",
43
+ "main": "./src/index.js",
44
+ "exports": {
45
+ ".": "./src/index.js",
46
+ "./client": "./lib/client.js",
47
+ "./register": "./src/register.js",
48
+ "./tool-spec": "./src/tool-spec.js",
49
+ "./watch": "./src/watch.js",
50
+ "./batches": "./src/batches.js",
51
+ "./chat": "./src/chat.js",
52
+ "./voice": "./src/voice.js",
53
+ "./speech-bus": "./src/speech-bus.js",
54
+ "./voice-adapter": "./src/voice-adapter.js",
55
+ "./interfaces": "./src/interfaces.js",
56
+ "./public-api": "./src/public-api.js",
57
+ "./recognition-interface": "./src/recognition-interface.js",
58
+ "./tts-interface": "./src/tts-interface.js",
59
+ "./window-interface": "./src/window-interface.js",
60
+ "./window-protocol": "./src/window-protocol.js"
61
+ },
62
+ "bin": {
63
+ "dsh-watch": "./bin/watch.mjs",
64
+ "dsh-watch-lines": "./bin/lines.mjs"
65
+ },
66
+ "files": [
67
+ "src",
68
+ "lib",
69
+ "bin",
70
+ "extension",
71
+ "scripts",
72
+ "docs",
73
+ "cordis.patch.yml",
74
+ "dsh.plugin.json",
75
+ "README.md",
76
+ "CHANGELOG.md",
77
+ "CREDITS.md",
78
+ "LICENSE",
79
+ "NOTICE",
80
+ "examples/floating-chat/*.py",
81
+ "examples/floating-chat/*.cmd",
82
+ "examples/floating-chat/*.png",
83
+ "examples/floating-chat/*.txt",
84
+ "examples/voice-edge-tts/index.mjs",
85
+ "examples/voice-edge-tts/stream/*.mjs",
86
+ "examples/voice-edge-tts/stream/*.py",
87
+ "examples/voice-edge-tts/stream/*.mp3"
88
+ ],
89
+ "engines": {
90
+ "node": ">=20"
91
+ },
92
+ "scripts": {
93
+ "test": "node --test",
94
+ "pretest": "node scripts/sync-dep.mjs",
95
+ "sync:dep": "node scripts/sync-dep.mjs",
96
+ "prepublishOnly": "node scripts/check-syntax.mjs && node --test",
97
+ "check": "node scripts/check-syntax.mjs",
98
+ "doctor": "node bin/watch.mjs doctor",
99
+ "install:extension": "node bin/watch.mjs install-extension",
100
+ "sim": "node scripts/watch-sim.mjs",
101
+ "e2e": "node scripts/watch-e2e.mjs"
102
+ },
103
+ "dependencies": {
104
+ "dsh-video-storyboard": "^0.6.0"
105
+ },
106
+ "peerDependencies": {
107
+ "@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
108
+ },
109
+ "peerDependenciesMeta": {
110
+ "@deepseek-ai/dsh-tools": {
111
+ "optional": true
112
+ }
113
+ },
114
+ "dsh": {
115
+ "bundle": {
116
+ "patch": "./cordis.patch.yml"
117
+ },
118
+ "client": {
119
+ "platform": "web"
120
+ },
121
+ "catalog": {
122
+ "category": "tool",
123
+ "summary": {
124
+ "en": "Watch a video together, in sync with the user's playback: each segment arrives as one storyboard image plus its subtitle lines just before it ends, and the floating window carries spoken replies and live room audio.",
125
+ "zh": "和智能体一起看视频:跟着真实播放位置,每段结束前把分镜画面 + 带秒台词交过去;悬浮窗里能出声,也听得见房间里的声音 —— 给的是画面和声音,不是一段转写文本。"
126
+ },
127
+ "capabilities": [
128
+ "fs",
129
+ "shell"
130
+ ]
131
+ }
132
+ }
133
+ }
@@ -0,0 +1,144 @@
1
+ /**
2
+ * define-tool.js — `@deepseek-ai/dsh-tools` 的**离线兜底**。
3
+ *
4
+ * ## 为什么需要它(2026-11-06 社区实报)
5
+ *
6
+ * 插件的工具定义要用宿主的 `defineTool()`:它把 author spec 编译成 JSON Schema、
7
+ * 给 execute 包一层参数校验。但 `@deepseek-ai/dsh-tools` **被打包进宿主的 `app.asar`**,
8
+ * 插件从自己的 `node_modules` 往上解析时**找不到这个包** →
9
+ * `import()` 抛 → `apply()` 被 catch 吞掉 → **整个插件静默不注册任何工具**。
10
+ *
11
+ * 社区原话:「根源没变:它 `import('@deepseek-ai/dsh-tools')`,宿主的这份被打进 `app.asar`,
12
+ * plugins 侧解析不到,加载时就在注册工具之前抛了」。
13
+ *
14
+ * ## 兜底做什么、不做什么
15
+ *
16
+ * **做**:把 author spec 编译成宿主 `register()` 认的 JSON Schema。规则逐条照抄
17
+ * `dsh-tools/lib/index.js` 的 `runSchemaCompiler`:
18
+ * - `property-map`:每个属性的 `required: true` 提升到父级 `required` 数组,并从属性里删掉;
19
+ * 没写 `required: true` 的属性 = 可选(宿主的参数**默认全是可选**)。
20
+ * - `type: 'json'` 是 author-only 节点 → 退化成 `{}`(任意 JSON,只保留 description 等注解)。
21
+ * - `properties` / `items` 递归;其余键(`description` / `enum` / `additionalProperties`)原样透传。
22
+ *
23
+ * **不做**:运行时参数校验(宿主那层 `validateJsonSchemaValue` 拿不到)。
24
+ * 代价是模型传错参数时不再抛 `ToolArgsError`,而是走各 handler 自己的默认值分支 ——
25
+ * 真出问题时表现为"参数没生效",所以 `schema-audit.test.mjs` 那套静态审计更要守住。
26
+ *
27
+ * **首选仍然是宿主的版本**:`loadDefineTool()` 先 import、再 `DSH_TOOLS_PATH`,
28
+ * 两个都不行才落到这里,并打一条 warn 让用户知道降级了。
29
+ */
30
+
31
+ const AUTHOR_ONLY_JSON = 'json';
32
+
33
+ /**
34
+ * 编译一个属性表(`parameters` 或某个 object 节点的 `properties`)。
35
+ * @param {object} map - 属性名 → author value spec
36
+ * @param {string} path - 报错用的路径前缀
37
+ * @returns {{properties: object, required?: string[]}}
38
+ */
39
+ function compilePropertyMap(map, path) {
40
+ if (!map || typeof map !== 'object' || Array.isArray(map)) {
41
+ throw new Error(`${path} 必须是对象(属性名 → 值 schema)`);
42
+ }
43
+ const properties = {};
44
+ const required = [];
45
+ for (const [key, spec] of Object.entries(map)) {
46
+ if (!spec || typeof spec !== 'object' || Array.isArray(spec)) {
47
+ throw new Error(`${path}.${key} 必须是值 schema 对象`);
48
+ }
49
+ const { required: mark, ...rest } = spec;
50
+ if (mark !== undefined && mark !== true) throw new Error(`${path}.${key}.required 写了就只能是 true`);
51
+ if (mark === true) required.push(key);
52
+ properties[key] = compileValue(rest, `${path}.${key}`);
53
+ }
54
+ return required.length > 0 ? { properties, required } : { properties };
55
+ }
56
+
57
+ /**
58
+ * 编译一个值 schema。`type: 'json'` 退化成注解(不写 `type`)。
59
+ * @param {object} spec
60
+ * @param {string} path
61
+ * @returns {object}
62
+ */
63
+ function compileValue(spec, path) {
64
+ if (!spec || typeof spec !== 'object' || Array.isArray(spec)) {
65
+ throw new Error(`${path} 必须是值 schema 对象`);
66
+ }
67
+ const out = {};
68
+ for (const [key, value] of Object.entries(spec)) {
69
+ if (key === 'required') continue; // 由 compilePropertyMap 提走
70
+ if (key === 'properties') {
71
+ const compiled = compilePropertyMap(value, `${path}.properties`);
72
+ out.properties = compiled.properties;
73
+ if (compiled.required) out.required = compiled.required;
74
+ continue;
75
+ }
76
+ if (key === 'items') {
77
+ out.items = compileValue(value, `${path}.items`);
78
+ continue;
79
+ }
80
+ // author-only:任意 JSON。宿主把它变成"只有注解、没有 type"的 schema
81
+ if (key === 'type' && value === AUTHOR_ONLY_JSON) continue;
82
+ out[key] = value;
83
+ }
84
+ return out;
85
+ }
86
+
87
+ /**
88
+ * 编译 `parameters`:隐式开放对象,根上不写 `required`(除非属性显式标了)。
89
+ * @param {object} spec
90
+ * @returns {object}
91
+ */
92
+ export function parametersToJsonSchema(spec) {
93
+ const { properties, required } = compilePropertyMap(spec, 'parameters');
94
+ return { type: 'object', properties, ...(required ? { required } : {}) };
95
+ }
96
+
97
+ /**
98
+ * 编译 `output.schema`。
99
+ * @param {object} spec
100
+ * @returns {object}
101
+ */
102
+ export function outputSchemaToJsonSchema(spec) {
103
+ return compileValue(spec, 'schema');
104
+ }
105
+
106
+ /**
107
+ * `defineTool` 的兜底实现:**签名和返回值与宿主一致,只是不做运行时参数校验**。
108
+ * @param {object} options - 与宿主 `defineTool` 相同的入参
109
+ * @returns {object} registry-ready definition
110
+ */
111
+ export function defineToolCompat(options) {
112
+ if (!options || typeof options !== 'object') throw new Error('defineTool: options 必须是对象');
113
+ const { name, description, parameters, output, execute } = options;
114
+ if (typeof name !== 'string' || !name) throw new Error('defineTool: name 必须是非空字符串');
115
+ if (!output || typeof output !== 'object') throw new Error(`defineTool(${name}): 缺 output`);
116
+ if (typeof output.render !== 'function') throw new Error(`defineTool(${name}): output.render 必须是函数`);
117
+ if (typeof execute !== 'function') throw new Error(`defineTool(${name}): execute 必须是函数`);
118
+ if (options.timeoutMs !== undefined
119
+ && (!Number.isFinite(options.timeoutMs) || options.timeoutMs <= 0)) {
120
+ throw new Error(`defineTool(${name}): timeoutMs 必须是正数`);
121
+ }
122
+
123
+ const tool = {
124
+ name,
125
+ description,
126
+ parameters: parametersToJsonSchema(parameters ?? {}),
127
+ output: {
128
+ schema: outputSchemaToJsonSchema(output.schema ?? {}),
129
+ render: output.render,
130
+ ...(typeof output.presentationMeta === 'function' ? { presentationMeta: output.presentationMeta } : {}),
131
+ },
132
+ ...(options.deferLoading === true ? { deferLoading: true } : {}),
133
+ ...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
134
+ async execute(args, exec) {
135
+ return execute(args, exec);
136
+ },
137
+ };
138
+ if (typeof options.projectContent === 'function') tool.projectContent = options.projectContent;
139
+ if (typeof options.finalizeContent === 'function') tool.finalizeContent = options.finalizeContent;
140
+ if (typeof options.presentCall === 'function') tool.presentCall = options.presentCall;
141
+ if (typeof options.presentResult === 'function') tool.presentResult = options.presentResult;
142
+ if (typeof options.isConcurrencySafe === 'function') tool.isConcurrencySafe = options.isConcurrencySafe;
143
+ return tool;
144
+ }
@@ -64,9 +64,10 @@ function readConfig() {
64
64
  }
65
65
 
66
66
  /** 写一个键进配置(只合并不覆盖:`window.py` 也往这个文件写 geometry) */
67
- function patchConfig(patch) {
67
+ function patchConfig(patch, drop = []) {
68
68
  try {
69
69
  const cfg = { ...readConfig(), ...patch };
70
+ for (const key of drop) delete cfg[key];
70
71
  writeFileSync(windowConfigPath(), `${JSON.stringify(cfg, null, 2)}\n`, 'utf8');
71
72
  return true;
72
73
  } catch {
@@ -79,16 +80,46 @@ function patchConfig(patch) {
79
80
  *
80
81
  * 为什么这是**独立于关窗**的一档:关窗在陪看里是"不看了"(停表 + 落挂断记录),
81
82
  * 而用户经常只是嫌它挡画面 —— 那两件事必须分开(2026-11-01 用户提出)。
82
- * 窗口自己每 200ms 读一次这个配置(`_sync_visible`),所以这里只写文件就够。
83
+ * 窗口自己每 250ms 读一次这个配置(`_sync_config`),所以这里只写文件就够。
83
84
  *
84
85
  * @param {boolean} hidden
85
86
  * @returns {{ok: boolean, hidden: boolean, reason?: string}}
86
87
  */
87
88
  export function setWindowHidden(hidden) {
88
- if (process.env.DSH_WATCH_NO_WIDGET === '1') return { ok: false, hidden: false, reason: 'disabled' };
89
- if (!stillRunning()) return { ok: false, hidden: false, reason: 'window-not-open' };
90
- if (!patchConfig({ hidden: Boolean(hidden) })) return { ok: false, hidden: false, reason: 'config-write-failed' };
91
- return { ok: true, hidden: Boolean(hidden) };
89
+ const r = setWindowMode(hidden ? 'hidden' : 'full');
90
+ return { ok: r.ok, hidden: Boolean(hidden) && r.ok, reason: r.reason };
91
+ }
92
+
93
+ /**
94
+ * 两档:`full` / `hidden`。
95
+ *
96
+ * `hidden` 是**真正从屏幕上消失**(不是缩成一条)—— `overrideredirect` 窗口不进
97
+ * 任务栏,所以窗口进程会挂一个托盘图标,另外留了 `Ctrl+Alt+W` 热键兜底。
98
+ * 想在这时候还看得见消息,就配 `danmaku: true`。
99
+ *
100
+ * @param {'full'|'hidden'} mode
101
+ */
102
+ export function setWindowMode(mode) {
103
+ const want = String(mode ?? '').trim().toLowerCase();
104
+ if (want !== 'full' && want !== 'hidden') {
105
+ return { ok: false, mode: null, reason: 'bad-mode' };
106
+ }
107
+ if (process.env.DSH_WATCH_NO_WIDGET === '1') return { ok: false, mode: null, reason: 'disabled' };
108
+ if (!stillRunning()) return { ok: false, mode: null, reason: 'window-not-open' };
109
+ const patch = { hidden: want === 'hidden' };
110
+ // 只写 `hidden`:它是窗口真正读的那个键,`mode` 是窗口自己在最小化时补的
111
+ // 语义标记。JS 侧多写一个键,只会让"hide 到底改了什么"变得难查。
112
+ const ok = want === 'hidden' ? patchConfig(patch) : patchConfig(patch, ['mode']);
113
+ if (!ok) return { ok: false, mode: null, reason: 'config-write-failed' };
114
+ return { ok: true, mode: want };
115
+ }
116
+
117
+ /** 台词是否以弹幕飘过(和 mode 正交:隐藏 + 弹幕是最干净的一档)。 */
118
+ export function setWindowDanmaku(on) {
119
+ if (process.env.DSH_WATCH_NO_WIDGET === '1') return { ok: false, reason: 'disabled' };
120
+ if (!stillRunning()) return { ok: false, reason: 'window-not-open' };
121
+ if (!patchConfig({ danmaku: Boolean(on) })) return { ok: false, reason: 'config-write-failed' };
122
+ return { ok: true, danmaku: Boolean(on) };
92
123
  }
93
124
 
94
125
  /** 窗口现在是藏着的吗(读配置,不看进程) */
@@ -96,6 +127,12 @@ export function floatingWindowHidden() {
96
127
  return readConfig().hidden === true;
97
128
  }
98
129
 
130
+ /** 当前是哪一档(读配置) */
131
+ export function floatingWindowMode() {
132
+ const cfg = readConfig();
133
+ return cfg.hidden === true || cfg.mode === 'hidden' ? 'hidden' : 'full';
134
+ }
135
+
99
136
  /** 这个脚本最终用哪个文件(不检查存在性,交给调用方报清楚) */
100
137
  function resolveWindowScript(cfg = readConfig()) {
101
138
  const explicit = process.env.DSH_FLOAT_WINDOW || cfg.script;
@@ -150,8 +187,9 @@ export function floatingWindowAlive() {
150
187
  */
151
188
  export function openFloatingWindow({ log = null, force = false } = {}) {
152
189
  // **先清"上次藏着退出"的标记**(在任何早退之前):否则下次真开窗时它直接隐身,
153
- // 用户以为插件坏了(`window.py` 的 `_sync_visible` 只跟这个键,没有"第一次"的概念)。
154
- if (readConfig().hidden === true) patchConfig({ hidden: false });
190
+ // 用户以为插件坏了(`window.py` 的 `_sync_config` 只跟这个键,没有"第一次"的概念)。
191
+ const boot = readConfig();
192
+ if (boot.hidden === true || boot.mode === 'hidden') patchConfig({ hidden: false }, ['mode']);
155
193
  if (process.env.DSH_WATCH_NO_WIDGET === '1') return { ok: false, reason: 'disabled' };
156
194
  const cfg = readConfig();
157
195
  let script = resolveWindowScript(cfg);