dsh-notify-say 0.4.72 → 0.4.74
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 +4 -0
- package/lib/index.js +130 -15
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/index.js
CHANGED
|
@@ -1038,8 +1038,7 @@ export function apply(ctx, config) {
|
|
|
1038
1038
|
appendNotifyLog(`[play-fallback] beep once after ${which} failed`);
|
|
1039
1039
|
try {
|
|
1040
1040
|
const c = spawn(POWERSHELL_EXE, [
|
|
1041
|
-
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-
|
|
1042
|
-
'-Command', '[console]::beep(880,300)',
|
|
1041
|
+
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', '[console]::beep(880,300)',
|
|
1043
1042
|
], { stdio: 'ignore', windowsHide: true });
|
|
1044
1043
|
c.once('error', () => { /* 蜂鸣也失败就算了 */ });
|
|
1045
1044
|
} catch { /* 同上 */ }
|
|
@@ -1416,17 +1415,84 @@ function hasVoiceLine(psKind) {
|
|
|
1416
1415
|
*
|
|
1417
1416
|
* @returns {boolean} 注册成功且可用
|
|
1418
1417
|
*/
|
|
1418
|
+
/**
|
|
1419
|
+
* 探测协议当前是否已注册且指向我们的处理器(不依赖内存状态)。
|
|
1420
|
+
*
|
|
1421
|
+
* 为什么必须 probe:`jumpProtoState` 是模块级变量,热重载后会重置。
|
|
1422
|
+
* 2026-10-20 实测:重载后状态变回 unknown,又因为 cfg 也是初始值
|
|
1423
|
+
* (toastJumpSession: false)而误判成「关着」,甚至把已注册的协议注销掉。
|
|
1424
|
+
*
|
|
1425
|
+
* @returns {'ok'|'missing'|'foreign'} missing=没注册,foreign=指向别处
|
|
1426
|
+
*/
|
|
1427
|
+
/**
|
|
1428
|
+
* 探测协议当前是否已注册且指向我们的处理器(不依赖内存状态)。
|
|
1429
|
+
*
|
|
1430
|
+
* ## 为什么用 .NET Registry API 而不是 `HKCU:`
|
|
1431
|
+
*
|
|
1432
|
+
* 2026-10-20 排查结论:从 Node 的 execFileSync 调 PowerShell 读
|
|
1433
|
+
* `HKCU:\Software\Classes\...` 时,**返回空字符串但 status=0**
|
|
1434
|
+
* (PSDrive 在非交互环境下初始化时机的问题)。而:
|
|
1435
|
+
* · 同样的命令从 pwsh 直接跑 → 正常
|
|
1436
|
+
* · `reg query` 从 Node 跑 → 正常
|
|
1437
|
+
* · `[Microsoft.Win32.Registry]::CurrentUser` → **正常**
|
|
1438
|
+
*
|
|
1439
|
+
* 所以改走 .NET Registry API,不依赖 PSDrive。
|
|
1440
|
+
*
|
|
1441
|
+
* ## 为什么必须 probe
|
|
1442
|
+
*
|
|
1443
|
+
* `jumpProtoState` 是模块级变量,热重载后重置;而 `cfg` 也重置成默认值
|
|
1444
|
+
* (toastJumpSession: false)→ 旧实现会误判成「关着」并把协议注销掉。
|
|
1445
|
+
*
|
|
1446
|
+
* @returns {'ok'|'missing'|'foreign'}
|
|
1447
|
+
*/
|
|
1448
|
+
function probeJumpProtocol() {
|
|
1449
|
+
try {
|
|
1450
|
+
// 测试环境守卫:单元测试大量调用 apply(),不能每次都碰注册表。
|
|
1451
|
+
if (typeof globalThis !== "undefined" && globalThis.__STUB_CHILD_PROCESS__ === true) {
|
|
1452
|
+
return "missing";
|
|
1453
|
+
}
|
|
1454
|
+
if (process.env.DSH_NOTIFY_NO_REGISTRY === "1") return "missing";
|
|
1455
|
+
|
|
1456
|
+
// 用 .NET Registry API:不受 PSDrive 初始化影响(见上方注释)。
|
|
1457
|
+
const subKey = `Software\\Classes\\${JUMP_PROTOCOL}\\shell\\open\\command`;
|
|
1458
|
+
const ps = [
|
|
1459
|
+
`$k = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('${subKey}');`,
|
|
1460
|
+
`if ($k) { $k.GetValue('') } else { '' }`
|
|
1461
|
+
].join(' ');
|
|
1462
|
+
|
|
1463
|
+
const out = execFileSync(POWERSHELL_EXE, [
|
|
1464
|
+
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', ps,
|
|
1465
|
+
], { encoding: 'utf8', windowsHide: true, timeout: 8000 });
|
|
1466
|
+
|
|
1467
|
+
const val = String(out || '').trim();
|
|
1468
|
+
if (!val) return 'missing';
|
|
1469
|
+
// 指向我们的 jump-handler.ps1 才算 ok
|
|
1470
|
+
return val.includes('jump-handler.ps1') ? 'ok' : 'foreign';
|
|
1471
|
+
} catch {
|
|
1472
|
+
// 读不到注册表就当没注册(不抛错,让调用方走注册流程)
|
|
1473
|
+
return 'missing';
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* 注册自定义协议(HKCU,无需管理员)。
|
|
1478
|
+
*
|
|
1479
|
+
* ⚠️ 2026-10-20 实测踩坑:**不能用 `-WindowStyle Hidden`**。
|
|
1480
|
+
* `-WindowStyle` 只对 `-File` 有效,配 `-Command` 会让 powershell.exe
|
|
1481
|
+
* 直接以 exit=-1 退出且无任何输出 —— 表现为"注册总是失败"。
|
|
1482
|
+
* 隐藏窗口交给 Node 的 `windowsHide: true` 就够了。
|
|
1483
|
+
*
|
|
1484
|
+
* @returns {boolean} 注册成功且可用
|
|
1485
|
+
*/
|
|
1419
1486
|
function registerJumpProtocol() {
|
|
1420
1487
|
try {
|
|
1421
1488
|
const handler = join(PLUGIN_ROOT, 'jump-handler.ps1');
|
|
1422
1489
|
if (!existsSync(handler)) { jumpProtoState = 'failed'; return false; }
|
|
1423
1490
|
|
|
1424
|
-
//
|
|
1491
|
+
// Toast 点击时 Windows 会调起这个命令,%1 是完整 URL
|
|
1425
1492
|
const cmd = `"${POWERSHELL_EXE}" -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File "${handler}" "%1"`;
|
|
1426
1493
|
|
|
1427
|
-
// 用 PowerShell 写注册表:避免引入额外依赖,且引号处理更稳。
|
|
1428
1494
|
const ps = [
|
|
1429
|
-
`$k = 'HKCU:\\Software\\Classes
|
|
1495
|
+
`$k = 'HKCU:\\Software\\Classes\\${JUMP_PROTOCOL}';`,
|
|
1430
1496
|
'if (-not (Test-Path $k)) { New-Item -Path $k -Force | Out-Null }',
|
|
1431
1497
|
'Set-ItemProperty -Path $k -Name "(default)" -Value "URL:DSH Notify Jump" -Force;',
|
|
1432
1498
|
'Set-ItemProperty -Path $k -Name "URL Protocol" -Value "" -Force;',
|
|
@@ -1436,8 +1502,7 @@ function hasVoiceLine(psKind) {
|
|
|
1436
1502
|
].join(' ');
|
|
1437
1503
|
|
|
1438
1504
|
execFileSync(POWERSHELL_EXE, [
|
|
1439
|
-
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-
|
|
1440
|
-
'-Command', ps,
|
|
1505
|
+
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', ps,
|
|
1441
1506
|
], {
|
|
1442
1507
|
stdio: 'ignore',
|
|
1443
1508
|
windowsHide: true,
|
|
@@ -1445,6 +1510,14 @@ function hasVoiceLine(psKind) {
|
|
|
1445
1510
|
timeout: 15000,
|
|
1446
1511
|
});
|
|
1447
1512
|
|
|
1513
|
+
// 写完立刻 probe 确认(不信任"命令没报错"就等于成功)
|
|
1514
|
+
const after = probeJumpProtocol();
|
|
1515
|
+
if (after !== 'ok') {
|
|
1516
|
+
jumpProtoState = 'failed';
|
|
1517
|
+
appendNotifyLog(`[jump-proto] register写入了但 probe=${after}`);
|
|
1518
|
+
return false;
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1448
1521
|
jumpProtoState = 'ok';
|
|
1449
1522
|
appendNotifyLog(`[jump-proto] registered ${JUMP_PROTOCOL}:// -> jump-handler.ps1`);
|
|
1450
1523
|
return true;
|
|
@@ -1462,13 +1535,18 @@ function hasVoiceLine(psKind) {
|
|
|
1462
1535
|
*/
|
|
1463
1536
|
function unregisterJumpProtocol() {
|
|
1464
1537
|
try {
|
|
1538
|
+
// ⚠️ 同 register:-Command 不能配 -WindowStyle Hidden(会让 powershell 直接失败)。
|
|
1465
1539
|
const ps = `$k = 'HKCU:\\Software\\Classes\\${JUMP_PROTOCOL}'; if (Test-Path $k) { Remove-Item $k -Recurse -Force }`;
|
|
1466
1540
|
execFileSync(POWERSHELL_EXE, [
|
|
1467
|
-
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-
|
|
1468
|
-
'-Command', ps,
|
|
1541
|
+
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', ps,
|
|
1469
1542
|
], { stdio: 'ignore', windowsHide: true, timeout: 10000 });
|
|
1470
|
-
|
|
1471
|
-
|
|
1543
|
+
const after = probeJumpProtocol();
|
|
1544
|
+
if (after === 'missing') {
|
|
1545
|
+
jumpProtoState = 'off';
|
|
1546
|
+
appendNotifyLog(`[jump-proto] unregistered ${JUMP_PROTOCOL}://`);
|
|
1547
|
+
} else {
|
|
1548
|
+
appendNotifyLog(`[jump-proto] unregister 后 probe=${after}(可能被占用)`);
|
|
1549
|
+
}
|
|
1472
1550
|
} catch (e) {
|
|
1473
1551
|
appendNotifyLog(`[jump-proto] unregister failed: ` + String((e && e.message) || e).slice(0, 120));
|
|
1474
1552
|
}
|
|
@@ -1479,13 +1557,40 @@ function hasVoiceLine(psKind) {
|
|
|
1479
1557
|
*
|
|
1480
1558
|
* @returns {boolean} 是否可用(决定 Toast 用哪种 launch)
|
|
1481
1559
|
*/
|
|
1560
|
+
/**
|
|
1561
|
+
* 按当前开关同步协议状态。
|
|
1562
|
+
*
|
|
1563
|
+
* ⚠️ 2026-10-20 重写:**每次都从注册表 probe**,不信任 `jumpProtoState`。
|
|
1564
|
+
*
|
|
1565
|
+
* 起因:热重载会把模块级变量重置,而 cfg 也重置成默认值
|
|
1566
|
+
* (toastJumpSession: false)→ 旧实现在重载时走进"开关关着"分支,
|
|
1567
|
+
* 把用户已经注册好的协议**主动注销**了(00:21 日志为证)。
|
|
1568
|
+
*
|
|
1569
|
+
* 现在的规则:
|
|
1570
|
+
* 开关开 + 已注册 → 直接用(不重复写注册表)
|
|
1571
|
+
* 开关开 + 未注册 → 注册
|
|
1572
|
+
* 开关关 + 已注册 → 注销(这是用户的明确选择,合理)
|
|
1573
|
+
* 开关关 + 未注册 → 什么都不做
|
|
1574
|
+
*
|
|
1575
|
+
* @returns {boolean} 是否可用(决定 Toast 用哪种 launch)
|
|
1576
|
+
*/
|
|
1482
1577
|
function syncJumpProtocol() {
|
|
1578
|
+
const probed = probeJumpProtocol();
|
|
1579
|
+
|
|
1483
1580
|
if (!cfg.toastJumpSession) {
|
|
1484
|
-
|
|
1581
|
+
// 开关关着:只有真的注册过才注销,避免无谓的注册表操作
|
|
1582
|
+
if (probed === 'ok' || probed === 'foreign') unregisterJumpProtocol();
|
|
1485
1583
|
jumpProtoState = 'off';
|
|
1486
1584
|
return false;
|
|
1487
1585
|
}
|
|
1488
|
-
|
|
1586
|
+
|
|
1587
|
+
if (probed === 'ok') {
|
|
1588
|
+
// 已是我们的处理器 —— 热重载/重启后走这条,不必重复写注册表
|
|
1589
|
+
jumpProtoState = 'ok';
|
|
1590
|
+
return true;
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
// 没注册,或指向别处(那是我们的协议名,覆盖即可)
|
|
1489
1594
|
return registerJumpProtocol();
|
|
1490
1595
|
}
|
|
1491
1596
|
|
|
@@ -2363,8 +2468,18 @@ function hasVoiceLine(psKind) {
|
|
|
2363
2468
|
pendingDone.clear();
|
|
2364
2469
|
prevStatus.clear();
|
|
2365
2470
|
lastTurnEnd.clear();
|
|
2366
|
-
// v0.4.
|
|
2367
|
-
|
|
2471
|
+
// ⚠️ v0.4.73:**不在这里注销协议**。
|
|
2472
|
+
//
|
|
2473
|
+
// 这个清理函数在**热重载时也会执行**(旧实例 dispose),
|
|
2474
|
+
// 于是会把用户刚注册好的协议注销掉 —— 2026-10-20 00:21 实测:
|
|
2475
|
+
// [jump-proto] unregistered dshnotify://
|
|
2476
|
+
// 之后所有 Toast 的 launch 又变回 dsh://open,点了一点反应没有。
|
|
2477
|
+
//
|
|
2478
|
+
// 正确的注销时机只有两个:
|
|
2479
|
+
// ① 用户在设置里关掉 toastJumpSession(syncJumpProtocol 负责)
|
|
2480
|
+
// ② 插件真的被卸载(不在此 hook,靠用户重装/卸载动作)
|
|
2481
|
+
//
|
|
2482
|
+
// 留一条注释在这里,防止后人又把它加回来。
|
|
2368
2483
|
// v0.4.63:长轮询的挂起响应也要结束掉。不做的后果是热重载后
|
|
2369
2484
|
// 旧连接永远等不到响应,客户端不会再发新的 /wait(它以为还在等)。
|
|
2370
2485
|
try { bridge.disposeAllWaiters(); } catch { /* 卸载期失败不影响退出 */ }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-notify-say",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.74",
|
|
4
4
|
"description": "Desktop notifications for DSH Desktop that actually speak: Windows TTS out of the box (zero download), VOICEVOX voice packs optional, a selectable system-sound fallback, and an idle gate that waits for running subagents before saying the turn is done. Includes a settings-page GUI (sound source, per-event overrides, jump-back-to-session, cooldowns) and a self hot-reload for development.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|