dsh-watch-together 0.2.13 → 0.2.15
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 +1860 -1781
- package/CREDITS.md +37 -0
- package/README.md +24 -5
- package/docs/INTERFACES.zh.md +13 -0
- package/dsh.plugin.json +12 -12
- package/examples/floating-chat/glass_static.py +158 -0
- package/examples/floating-chat/mic.py +19 -8
- package/examples/floating-chat/window.py +430 -65
- package/lib/client.js +41 -9
- package/package.json +133 -118
- package/scripts/check-expand-message.py +279 -0
- package/scripts/check-input-caret.py +151 -0
- package/src/define-tool.js +144 -0
- package/src/index.js +177 -164
- package/src/settings/config.js +53 -0
- package/src/settings/page.html +38 -4
- package/src/settings/server.js +8 -2
package/src/settings/config.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* ~/.dsh/video.json { browserPort, launchBrowser } (与分镜插件共享)
|
|
6
6
|
* ~/.dsh/voice.json { adapter } (voice-adapter.js 已读)
|
|
7
7
|
* ~/.dsh/watch.json { chatPort } (本页新增,chat-server 读取)
|
|
8
|
+
* ~/.dsh/watch-window.json { glass, geometry, name, … } (悬浮窗自己读写;本页只碰 glass)
|
|
8
9
|
*
|
|
9
10
|
* 这里不 import chat-server,避免 chat-server -> settings -> chat-server 的环。
|
|
10
11
|
*/
|
|
@@ -14,6 +15,19 @@ import { homedir } from 'node:os';
|
|
|
14
15
|
import { dirname, join } from 'node:path';
|
|
15
16
|
|
|
16
17
|
export const DEFAULT_CHAT_PORT = 9377;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 悬浮窗样式预设。
|
|
21
|
+
*
|
|
22
|
+
* `auto` 不落盘(写进去等于删掉 `glass` 键):窗口自己会按环境判断 ——
|
|
23
|
+
* 远程桌面/录屏用 solid(WDA 会让整窗在对面消失),其余用 live。
|
|
24
|
+
*
|
|
25
|
+
* 三个具体的档位:
|
|
26
|
+
* live 实时玻璃,抓屏 + 模糊,最好看也最吃 CPU
|
|
27
|
+
* frost 静态磨砂,一张预生成的底板,不抓屏(低配机/高分屏选这个)
|
|
28
|
+
* solid 纯色底板,最省
|
|
29
|
+
*/
|
|
30
|
+
export const WINDOW_STYLES = Object.freeze(['auto', 'live', 'frost', 'solid']);
|
|
17
31
|
const MAX_TEXT = 300;
|
|
18
32
|
|
|
19
33
|
export function dshHome(env = process.env) {
|
|
@@ -23,6 +37,8 @@ export function dshHome(env = process.env) {
|
|
|
23
37
|
export function videoConfigPath(env = process.env) { return join(dshHome(env), 'video.json'); }
|
|
24
38
|
export function voiceConfigPath(env = process.env) { return join(dshHome(env), 'voice.json'); }
|
|
25
39
|
export function watchConfigPath(env = process.env) { return join(dshHome(env), 'watch.json'); }
|
|
40
|
+
/** 悬浮窗自己的配置(窗口进程也往这里写 geometry/name);本页只改 `glass`。 */
|
|
41
|
+
export function windowConfigPath(env = process.env) { return join(dshHome(env), 'watch-window.json'); }
|
|
26
42
|
|
|
27
43
|
function readObject(path) {
|
|
28
44
|
if (!existsSync(path)) return { data: {}, error: null, exists: false };
|
|
@@ -78,6 +94,42 @@ export function writeWatchSettings(patch = {}, env = process.env) {
|
|
|
78
94
|
return readWatchSettings(env);
|
|
79
95
|
}
|
|
80
96
|
|
|
97
|
+
/**
|
|
98
|
+
* 悬浮窗样式(`watch-window.json` 的 `glass`)。
|
|
99
|
+
*
|
|
100
|
+
* 为什么写这个文件而不是 `watch.json`:窗口进程每 250ms 只看 `watch-window.json`
|
|
101
|
+
* 的 mtime,改这里才能**当场换过来**;写成别的文件要等下次开窗。
|
|
102
|
+
* 这个文件窗口自己也写(geometry / name / hidden),所以只能读-改-写,不能覆盖。
|
|
103
|
+
*/
|
|
104
|
+
export function readWindowSettings(env = process.env) {
|
|
105
|
+
const path = windowConfigPath(env);
|
|
106
|
+
const raw = readObject(path);
|
|
107
|
+
const value = typeof raw.data.glass === 'string' ? raw.data.glass.trim().toLowerCase() : '';
|
|
108
|
+
return {
|
|
109
|
+
path,
|
|
110
|
+
exists: raw.exists,
|
|
111
|
+
error: raw.error,
|
|
112
|
+
style: WINDOW_STYLES.includes(value) ? value : 'auto',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function writeWindowSettings(patch = {}, env = process.env) {
|
|
117
|
+
const path = windowConfigPath(env);
|
|
118
|
+
const { data } = readObject(path);
|
|
119
|
+
const next = { ...data };
|
|
120
|
+
if (patch.style !== undefined) {
|
|
121
|
+
const style = String(patch.style ?? '').trim().toLowerCase();
|
|
122
|
+
if (!WINDOW_STYLES.includes(style)) {
|
|
123
|
+
throw new Error('style 必须是 auto / live / frost / solid');
|
|
124
|
+
}
|
|
125
|
+
// `auto` 不落盘:窗口把"没有 glass 键"理解成自动,写个 auto 进去反而看不懂
|
|
126
|
+
if (style === 'auto') delete next.glass;
|
|
127
|
+
else next.glass = style;
|
|
128
|
+
}
|
|
129
|
+
writeObject(path, next);
|
|
130
|
+
return readWindowSettings(env);
|
|
131
|
+
}
|
|
132
|
+
|
|
81
133
|
export function readVideoSettings(env = process.env) {
|
|
82
134
|
const path = videoConfigPath(env);
|
|
83
135
|
const raw = readObject(path);
|
|
@@ -144,5 +196,6 @@ export function configPaths(env = process.env) {
|
|
|
144
196
|
video: videoConfigPath(env),
|
|
145
197
|
voice: voiceConfigPath(env),
|
|
146
198
|
watch: watchConfigPath(env),
|
|
199
|
+
window: windowConfigPath(env),
|
|
147
200
|
};
|
|
148
201
|
}
|
package/src/settings/page.html
CHANGED
|
@@ -62,6 +62,22 @@ code{font:12px/1.5 ui-monospace,SFMono-Regular,Consolas,monospace;background:var
|
|
|
62
62
|
<div class="banner" id="voiceHint">留空 = 台词只写进聊天记录,不念出来。</div>
|
|
63
63
|
</div>
|
|
64
64
|
|
|
65
|
+
<div class="card">
|
|
66
|
+
<h2>悬浮窗样式</h2>
|
|
67
|
+
<div class="grid">
|
|
68
|
+
<label class="field">外观预设
|
|
69
|
+
<select id="windowStyle">
|
|
70
|
+
<option value="auto">自动 —— 远程/录屏用纯色,其余实时玻璃</option>
|
|
71
|
+
<option value="live">实时玻璃 —— 跟着桌面模糊(好看,吃 CPU)</option>
|
|
72
|
+
<option value="frost">静态磨砂 —— 不吃性能</option>
|
|
73
|
+
<option value="solid">纯色 —— 最省,背后不透</option>
|
|
74
|
+
</select>
|
|
75
|
+
<span class="hint">改完立刻生效,不用重开窗口;窗口开着时也能切。</span>
|
|
76
|
+
</label>
|
|
77
|
+
</div>
|
|
78
|
+
<div class="banner" id="windowHint">实时玻璃每帧都要抓一次屏再模糊 —— 低配机、高分屏上「卡」就是这么来的。选「静态磨砂」后窗口不再抓屏,只画一张预生成的底板。</div>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
65
81
|
<div class="card">
|
|
66
82
|
<h2>依赖与下载</h2>
|
|
67
83
|
<p>缺少的依赖会出现官方下载按钮;插件只打开官方来源,不静默安装、不执行下载的文件。装好后回到本页点“重新检查”。</p>
|
|
@@ -105,7 +121,7 @@ code{font:12px/1.5 ui-monospace,SFMono-Regular,Consolas,monospace;background:var
|
|
|
105
121
|
const token = new URLSearchParams(location.search).get('token') || '';
|
|
106
122
|
const apiBase = '/dsh-watch-together/settings/api';
|
|
107
123
|
const $ = (id) => document.getElementById(id);
|
|
108
|
-
const state = { video: null, watch: null, voice: null, checks: [], paths: {} };
|
|
124
|
+
const state = { video: null, watch: null, voice: null, window: null, checks: [], paths: {} };
|
|
109
125
|
|
|
110
126
|
async function api(path, body) {
|
|
111
127
|
const res = await fetch(apiBase + path, {
|
|
@@ -132,18 +148,28 @@ code{font:12px/1.5 ui-monospace,SFMono-Regular,Consolas,monospace;background:var
|
|
|
132
148
|
const v = state.video || {};
|
|
133
149
|
const w = state.watch || {};
|
|
134
150
|
const s = state.voice || {};
|
|
151
|
+
const win = state.window || {};
|
|
135
152
|
$('browserPort').value = v.browserPort || '';
|
|
136
153
|
$('chatPort').value = w.chatPort || '';
|
|
137
154
|
$('adapter').value = s.adapter || '';
|
|
155
|
+
$('windowStyle').value = win.style || 'auto';
|
|
138
156
|
$('positionHint').textContent = v.browserPort
|
|
139
157
|
? '浏览器调试端口:' + v.browserPort + ';扩展上报优先,端口用于直接读页面。'
|
|
140
158
|
: '未配置调试端口:仍可用扩展上报或 SMTC;都没有时才需要手动传 cursor。';
|
|
141
159
|
$('voiceHint').textContent = s.adapter
|
|
142
160
|
? '当前适配器:' + s.adapter + '(下一场开始时挂载)'
|
|
143
161
|
: '留空 = 台词只写进聊天记录,不念出来。';
|
|
162
|
+
$('windowHint').textContent = win.style === 'frost'
|
|
163
|
+
? '当前:静态磨砂 —— 不抓屏、不逐帧合成,CPU 占用接近 0。'
|
|
164
|
+
: win.style === 'solid'
|
|
165
|
+
? '当前:纯色 —— 不抓屏、不设 WDA,远程桌面和录屏里也能看见。'
|
|
166
|
+
: win.style === 'live'
|
|
167
|
+
? '当前:实时玻璃 —— 每帧抓屏 + 模糊。觉得卡就换成「静态磨砂」。'
|
|
168
|
+
: '当前:自动 —— 远程/录屏环境用纯色,其余用实时玻璃;觉得卡可以手动选「静态磨砂」。';
|
|
144
169
|
$('paths').innerHTML = '<div>video.json:<code>' + escapeHtml(state.paths.video || '') + '</code></div>'
|
|
145
170
|
+ '<div>watch.json:<code>' + escapeHtml(state.paths.watch || '') + '</code></div>'
|
|
146
|
-
+ '<div>voice.json:<code>' + escapeHtml(state.paths.voice || '') + '</code></div>'
|
|
171
|
+
+ '<div>voice.json:<code>' + escapeHtml(state.paths.voice || '') + '</code></div>'
|
|
172
|
+
+ '<div>watch-window.json:<code>' + escapeHtml(state.paths.window || '') + '</code></div>';
|
|
147
173
|
}
|
|
148
174
|
|
|
149
175
|
function renderChecks() {
|
|
@@ -185,6 +211,7 @@ code{font:12px/1.5 ui-monospace,SFMono-Regular,Consolas,monospace;background:var
|
|
|
185
211
|
try {
|
|
186
212
|
const data = await api('/state');
|
|
187
213
|
state.video = data.video; state.watch = data.watch; state.voice = data.voice;
|
|
214
|
+
state.window = data.window;
|
|
188
215
|
state.checks = data.checks || []; state.paths = data.paths || {};
|
|
189
216
|
render(); renderChecks();
|
|
190
217
|
setStatus('');
|
|
@@ -200,10 +227,12 @@ code{font:12px/1.5 ui-monospace,SFMono-Regular,Consolas,monospace;background:var
|
|
|
200
227
|
};
|
|
201
228
|
const watch = { chatPort: Number($('chatPort').value) };
|
|
202
229
|
const voice = { adapter: $('adapter').value };
|
|
203
|
-
const
|
|
230
|
+
const win = { style: $('windowStyle').value };
|
|
231
|
+
const data = await api('/save', { video, watch, voice, window: win });
|
|
204
232
|
state.video = data.video; state.watch = data.watch; state.voice = data.voice;
|
|
233
|
+
state.window = data.window;
|
|
205
234
|
render();
|
|
206
|
-
setStatus('
|
|
235
|
+
setStatus('已保存;悬浮窗样式立刻生效,语音下一场生效,聊天端口若服务已在跑需重启 DSH。', 'ok');
|
|
207
236
|
} catch (e) { setStatus(e.message, 'bad'); }
|
|
208
237
|
}
|
|
209
238
|
|
|
@@ -219,6 +248,11 @@ code{font:12px/1.5 ui-monospace,SFMono-Regular,Consolas,monospace;background:var
|
|
|
219
248
|
|
|
220
249
|
$('save').addEventListener('click', save);
|
|
221
250
|
$('check').addEventListener('click', check);
|
|
251
|
+
// 下拉一改就把说明也换掉(真正落盘还是点保存;这里只是别让提示和选中的对不上)
|
|
252
|
+
$('windowStyle').addEventListener('change', () => {
|
|
253
|
+
state.window = { ...(state.window || {}), style: $('windowStyle').value };
|
|
254
|
+
render();
|
|
255
|
+
});
|
|
222
256
|
document.addEventListener('click', async (event) => {
|
|
223
257
|
const btn = event.target.closest('button.copy');
|
|
224
258
|
if (!btn) return;
|
package/src/settings/server.js
CHANGED
|
@@ -10,7 +10,8 @@ import { randomBytes } from 'node:crypto';
|
|
|
10
10
|
import { checkEnvironment } from './deps.js';
|
|
11
11
|
import {
|
|
12
12
|
configPaths, readVideoSettings, readVoiceSettings, readWatchSettings,
|
|
13
|
-
writeVideoSettings, writeVoiceSettings, writeWatchSettings,
|
|
13
|
+
readWindowSettings, writeVideoSettings, writeVoiceSettings, writeWatchSettings,
|
|
14
|
+
writeWindowSettings,
|
|
14
15
|
} from './config.js';
|
|
15
16
|
import { settingsPage } from './page.js';
|
|
16
17
|
|
|
@@ -63,6 +64,7 @@ function statePayload(env) {
|
|
|
63
64
|
video: readVideoSettings(env),
|
|
64
65
|
watch: readWatchSettings(env),
|
|
65
66
|
voice: readVoiceSettings(env),
|
|
67
|
+
window: readWindowSettings(env),
|
|
66
68
|
paths: configPaths(env),
|
|
67
69
|
};
|
|
68
70
|
}
|
|
@@ -104,6 +106,8 @@ export function createSettingsPage({ ctx, env = process.env, log = () => {} } =
|
|
|
104
106
|
if (body.video !== undefined) writeVideoSettings(body.video, env);
|
|
105
107
|
if (body.watch !== undefined) writeWatchSettings(body.watch, env);
|
|
106
108
|
if (body.voice !== undefined) writeVoiceSettings(body.voice, env);
|
|
109
|
+
// 悬浮窗样式:写 watch-window.json,窗口下一拍(250ms)自己换过来
|
|
110
|
+
if (body.window !== undefined) writeWindowSettings(body.window, env);
|
|
107
111
|
return json(res, 200, statePayload(env));
|
|
108
112
|
}
|
|
109
113
|
if (req.method === 'POST' && action === '/check') {
|
|
@@ -145,7 +149,8 @@ export function createSettingsPage({ ctx, env = process.env, log = () => {} } =
|
|
|
145
149
|
name: 'watch_together_settings',
|
|
146
150
|
description: [
|
|
147
151
|
'Open the local watch_together settings page: browser debugging port,',
|
|
148
|
-
'chat service port, voice adapter path,
|
|
152
|
+
'chat service port, voice adapter path, floating-window appearance preset',
|
|
153
|
+
'(live glass / static frost / solid), and a read-only dependency check',
|
|
149
154
|
'with official download buttons for Python, the browser extension, and ffmpeg.',
|
|
150
155
|
'Returns a tokenized local URL; the Web GUI also renders the same settings natively in the bundle detail page and Settings > Built-in plugins.',
|
|
151
156
|
].join(' '),
|
|
@@ -175,6 +180,7 @@ export function createSettingsPage({ ctx, env = process.env, log = () => {} } =
|
|
|
175
180
|
'一起看设置页:',
|
|
176
181
|
url,
|
|
177
182
|
'在浏览器打开;页面里的 API 用这个 URL 的 token 校验,不要把它发给别人。',
|
|
183
|
+
'悬浮窗样式(实时玻璃 / 静态磨砂 / 纯色)改完立刻生效,不用重开窗口。',
|
|
178
184
|
'语音适配器下一场开始时挂载;聊天端口在聊天服务启动时读取(服务已在跑需重启 DSH)。',
|
|
179
185
|
'台词/ASR 的 key 在视频分镜设置页配置。',
|
|
180
186
|
].join('\n'),
|