dsh-desktop-statusbar 3.0.2 → 3.0.4
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/docs/official-models.json +468 -0
- package/docs/official-models.md +190 -0
- package/docs/vendor-intelligence-order.json +124 -0
- package/docs/vendor-intelligence-order.md +77 -0
- package/lib/balance-api.js +318 -35
- package/lib/client.js +2992 -298
- package/lib/index.js +7784 -5843
- package/lib/self-update.js +45 -2
- package/locale/de.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/package.json +1 -1
- package/tools/plugin-dir.cjs +0 -4
- package/tools/shot.cjs +19 -15
package/lib/self-update.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* @module dsh-desktop-statusbar/self-update
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
import { spawn } from 'node:child_process'
|
|
23
|
+
import { spawn, spawnSync } from 'node:child_process'
|
|
24
24
|
import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
25
25
|
import { basename, dirname, join } from 'node:path'
|
|
26
26
|
import { ensureReleaseAgeExclude, findProfileDir } from './release-age.js'
|
|
@@ -328,6 +328,49 @@ export function resolvePnpm(options) {
|
|
|
328
328
|
return detail.ok === true ? detail.runner : null
|
|
329
329
|
}
|
|
330
330
|
|
|
331
|
+
/**
|
|
332
|
+
* 杀掉一条命令的**整棵进程树**。
|
|
333
|
+
*
|
|
334
|
+
* 为什么不能只 `child.kill()`:pnpm 是 Node 脚本,真正干活的是它再 spawn 出来的子进程;
|
|
335
|
+
* 在 Windows 上 `child.kill()` 只结束直接子进程,pnpm 的子孙进程会继续跑、继续占着文件句柄,
|
|
336
|
+
* 于是超时后下一次安装会撞上 `EPERM`/锁文件占用。用 `taskkill /T /F` 杀整棵树;
|
|
337
|
+
* 其它平台先 SIGTERM,2 秒后补 SIGKILL。
|
|
338
|
+
*
|
|
339
|
+
* `taskkill` 的失败**不会抛异常**:`spawnSync` 把失败放在 `result.error` / `result.status`
|
|
340
|
+
* 里(taskkill 不存在时 error=ENOENT,拒绝访问时 status≠0)。旧实现只 catch 异常,
|
|
341
|
+
* 失败分支永远不可达,进程树没被杀死也无人知道 —— 这里显式检查返回值,失败就回退
|
|
342
|
+
* `child.kill()`,至少把直接子进程收掉。
|
|
343
|
+
*
|
|
344
|
+
* @param {object} child spawn 返回的 ChildProcess
|
|
345
|
+
* @param {{spawnSync?: Function, platform?: string}} [deps] 测试注入(默认真实实现)
|
|
346
|
+
*/
|
|
347
|
+
export function killProcessTree(child, deps) {
|
|
348
|
+
if (child === null || child === undefined || typeof child.pid !== 'number') return
|
|
349
|
+
const spawnSyncFn = deps !== undefined && deps !== null && typeof deps.spawnSync === 'function' ? deps.spawnSync : spawnSync
|
|
350
|
+
const platform = deps !== undefined && deps !== null && typeof deps.platform === 'string' ? deps.platform : process.platform
|
|
351
|
+
if (platform === 'win32') {
|
|
352
|
+
let failed = true
|
|
353
|
+
try {
|
|
354
|
+
const result = spawnSyncFn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { stdio: 'ignore', windowsHide: true })
|
|
355
|
+
failed = result === null || result === undefined
|
|
356
|
+
|| (result.error !== undefined && result.error !== null)
|
|
357
|
+
|| result.status !== 0
|
|
358
|
+
} catch (error) {
|
|
359
|
+
failed = true
|
|
360
|
+
}
|
|
361
|
+
if (failed === true) {
|
|
362
|
+
/* taskkill 不可用 / 失败时退回普通 kill(可能已退出) */
|
|
363
|
+
try { child.kill() } catch (nested) { /* 可能已退出 */ }
|
|
364
|
+
}
|
|
365
|
+
return
|
|
366
|
+
}
|
|
367
|
+
try { child.kill('SIGTERM') } catch (error) { /* 可能已退出 */ }
|
|
368
|
+
const timer = setTimeout(() => {
|
|
369
|
+
try { child.kill('SIGKILL') } catch (error) { /* 可能已退出 */ }
|
|
370
|
+
}, 2000)
|
|
371
|
+
if (typeof timer.unref === 'function') timer.unref()
|
|
372
|
+
}
|
|
373
|
+
|
|
331
374
|
/**
|
|
332
375
|
* 跑一条命令并收集输出。
|
|
333
376
|
* @param {string} command
|
|
@@ -362,7 +405,7 @@ export function runCommand(command, args, options) {
|
|
|
362
405
|
}
|
|
363
406
|
timer = setTimeout(() => {
|
|
364
407
|
timedOut = true
|
|
365
|
-
|
|
408
|
+
killProcessTree(child)
|
|
366
409
|
/* 被杀之后 close 未必触发,兜一个底 */
|
|
367
410
|
setTimeout(() => finish(null), 5000)
|
|
368
411
|
}, options.timeoutMs === undefined ? INSTALL_TIMEOUT_MS : options.timeoutMs)
|
package/locale/de.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Desktop-Statusleiste",
|
|
4
|
+
"description": "Ersetzt die Statistikzeile unter der DSH-Desktop-Konversation durch eine konfigurierbare Statusleiste: 9 optionale, sortierbare Felder plus der Kontextring am Anfang der Leiste, offizielle Spitzen-/Nebenzeiten-Kostenschätzungen, eigene Modellpreise und Kontoguthaben."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/es.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Barra de estado de escritorio",
|
|
4
|
+
"description": "Sustituye la línea de estadísticas bajo la conversación del escritorio de DSH por una barra de estado configurable: 9 campos opcionales reordenables más el anillo de contexto al inicio de la barra, estimaciones oficiales de coste en horas punta y valle, precios personalizados de modelos y saldo de la cuenta."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/fr.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Barre d'état de bureau",
|
|
4
|
+
"description": "Remplace la ligne de statistiques sous la conversation du bureau DSH par une barre d'état configurable : 9 champs facultatifs réorganisables, plus l'anneau de contexte en tête de barre, estimation officielle des coûts heures pleines / creuses, prix de modèles personnalisés et solde du compte."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/ja.json
ADDED
package/locale/pt.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Barra de Estado do Ambiente de Trabalho",
|
|
4
|
+
"description": "Substitui a linha de estatísticas por baixo da conversa do ambiente de trabalho do DSH por uma barra de estado configurável: 9 campos opcionais reordenáveis, mais o anel de contexto no início da barra, estimativas oficiais de custo de ponta/fora de ponta, preços de modelos personalizados e saldo da conta."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/ru.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Строка состояния рабочего стола",
|
|
4
|
+
"description": "Заменяет строку статистики под диалогом DSH на рабочем столе на настраиваемую строку состояния: 9 необязательных полей с изменяемым порядком плюс кольцо контекста в начале строки, оценка стоимости по официальным пиковым/непиковым тарифам, свои цены моделей и баланс аккаунта."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/package.json
CHANGED
package/tools/plugin-dir.cjs
CHANGED
package/tools/shot.cjs
CHANGED
|
@@ -93,6 +93,7 @@ function loadPlugin(locale, config, presets) {
|
|
|
93
93
|
removeItem: (k) => { store.delete(k); }
|
|
94
94
|
},
|
|
95
95
|
innerWidth: 1200, innerHeight: 900,
|
|
96
|
+
__DSH_STATUSBAR_TEST__: true,
|
|
96
97
|
setInterval: () => 0, clearInterval: () => {}, setTimeout: () => 0, clearTimeout: () => {},
|
|
97
98
|
addEventListener: () => {}, removeEventListener: () => {},
|
|
98
99
|
fetch: () => Promise.resolve({ json: () => Promise.resolve({}) })
|
|
@@ -227,15 +228,14 @@ function settingsShot(locale) {
|
|
|
227
228
|
function pricingShot(locale) {
|
|
228
229
|
/* SettingsSection 里 useState 的顺序(组件加了 hook 就要回来重数一遍):
|
|
229
230
|
0 drag / 1 newModel / 2 hostModel / 3 editing / 4 draft /
|
|
230
|
-
5
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
presets[4] 从 draft 变成 editing、presets[7] 从 currencyOpen 变成 holidayNote。
|
|
231
|
+
5 catalogNotice / 6 platformModelOpen / 7 currencyOpen /
|
|
232
|
+
8 platformEditing / 9 platformDraft / 10 platformNotice / 11 newPlatform /
|
|
233
|
+
12 platformPopUp / 13 platformMenuSpec。
|
|
234
|
+
开发模式状态来自模块级快照;重复添加 / 倍率校验失败的提示由 catalogNotice 管理;
|
|
235
|
+
8-13 是「第三方平台」区块(平台编辑 / 草稿 / 校验提示 / 新平台名输入 / 编辑气泡方向 / 模型下拉定位)。
|
|
236
|
+
pricingShot 的 presets 固定为 editing=3、draft=4、currencyOpen=7。
|
|
237
|
+
币种下拉必须收在 presets[7](currencyOpen),否则展开会压住右边那列输入框。
|
|
238
|
+
历史上的坑:hook 顺序变化时截图 presets 未同步,会造成编辑区不展开或草稿注入错误状态。
|
|
239
239
|
教训:**下标是脆的**,加 hook 必须回来重数,并用 `node tools/shot.cjs` 实际生成一次确认。 */
|
|
240
240
|
const presets = [];
|
|
241
241
|
presets[3] = 'deepseek-flash';
|
|
@@ -379,9 +379,13 @@ function shoot(locale, scene) {
|
|
|
379
379
|
console.log('→ ' + path.relative(ROOT, file) + ' ' + Math.round(size / 1024) + ' KB');
|
|
380
380
|
}
|
|
381
381
|
|
|
382
|
-
|
|
383
|
-
const
|
|
384
|
-
const
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
|
|
382
|
+
if (require.main === module) {
|
|
383
|
+
const onlyLocale = process.argv[2];
|
|
384
|
+
const onlyScene = process.argv[3];
|
|
385
|
+
const locales = onlyLocale === undefined ? ['zh', 'en'] : [onlyLocale];
|
|
386
|
+
const scenes = onlyScene === undefined ? ['status', 'settings', 'pricing'] : [onlyScene];
|
|
387
|
+
locales.forEach((locale) => scenes.forEach((scene) => shoot(locale, scene)));
|
|
388
|
+
console.log('截图完成');
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
module.exports = { loadPlugin: loadPlugin, translator: translator };
|