dsh-notify-say 0.4.87 → 0.5.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +38 -10
  3. package/THIRD-PARTY-NOTICES.md +99 -99
  4. package/dsh-notify.ps1 +3 -3
  5. package/jump-handler.ps1 +3 -3
  6. package/jump-handler.vbs +182 -177
  7. package/lib/client.js +2 -2
  8. package/lib/config-route.js +251 -251
  9. package/lib/config-schema.js +386 -371
  10. package/lib/config-store.js +464 -429
  11. package/lib/dev-reload.js +752 -752
  12. package/lib/diagnostics.js +9 -3
  13. package/lib/dsh-home.js +219 -0
  14. package/lib/index.js +3542 -3375
  15. package/lib/log-privacy.js +200 -171
  16. package/lib/protocol-ownership.js +188 -31
  17. package/lib/session-bridge.js +295 -295
  18. package/lib/voice-pack-download.js +530 -530
  19. package/lib/voice-pack-route.js +260 -260
  20. package/package.json +1 -1
  21. package/test/audio-wiring.test.mjs +1 -1
  22. package/test/client-bundle.test.mjs +1 -1
  23. package/test/config-schema.test.mjs +28 -12
  24. package/test/config-store.test.mjs +61 -14
  25. package/test/diagnostics.test.mjs +84 -2
  26. package/test/docs-consistency.test.mjs +7 -5
  27. package/test/fail-route.test.mjs +2 -2
  28. package/test/fail-voice.test.mjs +193 -193
  29. package/test/idle-gate.test.mjs +2 -2
  30. package/test/protocol-ownership.test.mjs +446 -30
  31. package/test/real-cordis.test.mjs +209 -204
  32. package/test/reload-live.test.mjs +261 -261
  33. package/test/reload-verification.test.mjs +244 -244
  34. package/test/session-jump.test.mjs +1 -1
  35. package/test/stub-child-process.mjs +51 -51
  36. package/test/version-consistency.test.mjs +18 -6
  37. package/test/wiring.test.mjs +15 -3
  38. package/tools/notify-config.ps1 +24 -2
package/jump-handler.vbs CHANGED
@@ -1,177 +1,182 @@
1
- ' DSH 通知插件 —— 协议处理器包装(v0.4.78)
2
- '
3
- ' ## 为什么用 VBS 而不是直接调 powershell.exe
4
- '
5
- ' 1. **不弹命令行窗口**
6
- ' wscript.exe 是 GUI 子系统程序,本身不创建控制台。
7
- ' 而 `powershell.exe -WindowStyle Hidden` 在协议调起场景下**仍会闪窗/
8
- ' 留下可见控制台**(Windows 已知行为:-WindowStyle 只影响 PS 自己的
9
- ' 宿主窗口,不改父进程传给子进程的 console)。
10
- ' 2026-10-20 用户实测多次报告"点 Toast 打开一个命令行窗口"。
11
- '
12
- ' 2. **启动更快**
13
- ' 不走 PowerShell 冷启动(约 300–800ms),VBS 几毫秒。
14
- '
15
- ' 3. **参数传递可靠**
16
- ' 协议调起时 Windows 传给 "%1" 的是完整 URL;VBS 的 WScript.Arguments
17
- ' 能原样拿到,不需要经过 powershell 的参数解析(那层会吃掉引号/& 之类)。
18
- '
19
- ' ## 它做什么
20
- '
21
- ' ① 解析 dshnotify://jump?session=<id>
22
- ' ② 找插件端口(port.txt,或扫描能响应 /version 的端口)
23
- ' ③ POST /api/dsh-notify-say/pending-jump(带 Origin 头,过 http-guard)
24
- ' ④ 调 dsh://open 把 DSH 唤到前台(用 Run 的第二参数 0 = 隐藏窗口)
25
- '
26
- ' ## 安全
27
- '
28
- ' 只接受 dshnotify://jump?session=<白名单字符>,其它一律静默退出。
29
-
30
- Option Explicit
31
-
32
- Dim url, sid, port, candidates, i, ok, logPath, fso
33
-
34
- Set fso = CreateObject("Scripting.FileSystemObject")
35
-
36
- ' ── 诊断日志(放在 %TEMP%,与插件主日志同目录)──────────────────────────
37
- Sub LogLine(msg)
38
- On Error Resume Next
39
- Dim ts, dir, f
40
- dir = fso.GetSpecialFolder(2).Path & "\dsh-notify-say"
41
- If Not fso.FolderExists(dir) Then fso.CreateFolder(dir)
42
- logPath = dir & "\jump-handler.log"
43
- Set ts = fso.OpenTextFile(logPath, 8, True)
44
- ts.WriteLine Now & " " & msg
45
- ts.Close
46
- On Error GoTo 0
47
- End Sub
48
-
49
- ' ── 1. 取参数 ─────────────────────────────────────────────────────────────
50
- If WScript.Arguments.Count = 0 Then
51
- LogLine "[skip] no args"
52
- WScript.Quit 0
53
- End If
54
-
55
- url = WScript.Arguments(0)
56
- LogLine "[recv] """ & url & """"
57
-
58
- ' ── 2. 解析 session ──────────────────────────────────────────────────────
59
- sid = ""
60
- Dim m
61
- Set m = New RegExp
62
- m.IgnoreCase = True
63
- m.Pattern = "^dshnotify://jump/?(\?(.*))?$"
64
- If Not m.Test(url) Then
65
- LogLine "[skip] url not matched"
66
- WScript.Quit 0
67
- End If
68
-
69
- Dim query
70
- query = ""
71
- Set m = New RegExp
72
- m.IgnoreCase = True
73
- m.Pattern = "\?(.*)$"
74
- If m.Test(url) Then query = m.Execute(url)(0).SubMatches(0)
75
-
76
- Set m = New RegExp
77
- m.IgnoreCase = True
78
- m.Pattern = "(^|&)session=([^&]+)"
79
- If m.Test(query) Then
80
- sid = m.Execute(query)(0).SubMatches(1)
81
- End If
82
-
83
- ' 白名单:只接受字母数字/下划线/连字符(4-128 位)
84
- If sid <> "" Then
85
- Set m = New RegExp
86
- m.Pattern = "^[A-Za-z0-9_-]{4,128}$"
87
- If Not m.Test(sid) Then
88
- LogLine "[skip] bad session id: """ & sid & """"
89
- sid = ""
90
- End If
91
- End If
92
-
93
- LogLine "[parse] sid=" & sid
94
- If sid = "" Then WScript.Quit 0
95
-
96
- ' ── 3. 找端口 ────────────────────────────────────────────────────────────
97
- ' 优先 port.txt(插件在注册路由时写入)
98
- port = 0
99
- On Error Resume Next
100
- Dim ts2, txt
101
- Dim shEnv, localAppData, p1
102
- Set shEnv = CreateObject("WScript.Shell")
103
- localAppData = shEnv.ExpandEnvironmentStrings("%LOCALAPPDATA%")
104
- If localAppData = "" Or InStr(localAppData, "%") > 0 Then
105
- ' 兜底:TEMP 的上一级就是 LOCALAPPDATA
106
- localAppData = fso.GetSpecialFolder(2).ParentFolder.Path
107
- End If
108
- p1 = localAppData & "\dsh-notify-say\port.txt"
109
- LogLine "[port] looking at " & p1
110
- If fso.FileExists(p1) Then
111
- Set ts2 = fso.OpenTextFile(p1, 1)
112
- txt = Trim(ts2.ReadAll)
113
- ts2.Close
114
- If IsNumeric(txt) Then port = CLng(txt)
115
- LogLine "[port] from port.txt=" & port
116
- Else
117
- LogLine "[port] port.txt not found"
118
- End If
119
- On Error GoTo 0
120
-
121
- ' 候选端口:port.txt 优先,再补常见/历史端口
122
- candidates = ""
123
- If port > 0 Then candidates = CStr(port)
124
- Dim extra
125
- extra = Array("55510", "58163", "59525", "53523", "50061", "19387")
126
- For i = 0 To UBound(extra)
127
- If InStr("," & candidates & ",", "," & extra(i) & ",") = 0 Then
128
- If candidates = "" Then
129
- candidates = extra(i)
130
- Else
131
- candidates = candidates & "," & extra(i)
132
- End If
133
- End If
134
- Next
135
-
136
- ' ── 4. POST pending-jump ────────────────────────────────────────────────
137
- Dim ports
138
- ports = Split(candidates, ",")
139
- ok = False
140
-
141
- For i = 0 To UBound(ports)
142
- If Not ok Then
143
- Dim px, body, httpResp
144
- px = ports(i)
145
- If IsNumeric(px) And CLng(px) > 0 Then
146
- On Error Resume Next
147
- body = "{""sessionId"":""" & sid & """,""at"":" & CStr(Now * 86400000) & "}"
148
- ' 正确的毫秒时间戳(VBS 没有 Date.now,用 Timer 不够,用 DateDiff)
149
- Dim epochMs
150
- epochMs = DateDiff("s", #1/1/1970#, Now()) * 1000
151
- body = "{""sessionId"":""" & sid & """,""at"":" & CStr(epochMs) & "}"
152
-
153
- Set httpResp = CreateObject("MSXML2.XMLHTTP.6.0")
154
- httpResp.Open "POST", "http://127.0.0.1:" & px & "/api/dsh-notify-say/pending-jump", False
155
- httpResp.setRequestHeader "Origin", "http://127.0.0.1:" & px
156
- httpResp.setRequestHeader "Content-Type", "application/json"
157
- httpResp.Send body
158
- If httpResp.Status = 200 Then
159
- LogLine "[posted] port=" & px & " status=" & httpResp.Status
160
- ok = True
161
- Else
162
- LogLine "[post-fail] port=" & px & " status=" & httpResp.Status
163
- End If
164
- On Error GoTo 0
165
- End If
166
- End If
167
- Next
168
-
169
- If Not ok Then LogLine "[warn] no port accepted the POST"
170
-
171
- ' ── 5. 唤窗(第二参数 0 = 隐藏窗口)────────────────────────────────────
172
- On Error Resume Next
173
- Dim sh
174
- Set sh = CreateObject("WScript.Shell")
175
- sh.Run "cmd /c start """" dsh://open", 0, False
176
- LogLine "[open] dsh://open"
177
- On Error GoTo 0
1
+ ' DSH 通知插件 —— 协议处理器包装(v0.4.78)
2
+ '
3
+ ' ## 为什么用 VBS 而不是直接调 powershell.exe
4
+ '
5
+ ' 1. **不弹命令行窗口**
6
+ ' wscript.exe 是 GUI 子系统程序,本身不创建控制台。
7
+ ' 而 `powershell.exe -WindowStyle Hidden` 在协议调起场景下**仍会闪窗/
8
+ ' 留下可见控制台**(Windows 已知行为:-WindowStyle 只影响 PS 自己的
9
+ ' 宿主窗口,不改父进程传给子进程的 console)。
10
+ ' 2026-10-20 用户实测多次报告"点 Toast 打开一个命令行窗口"。
11
+ '
12
+ ' 2. **启动更快**
13
+ ' 不走 PowerShell 冷启动(约 300–800ms),VBS 几毫秒。
14
+ '
15
+ ' 3. **参数传递可靠**
16
+ ' 协议调起时 Windows 传给 "%1" 的是完整 URL;VBS 的 WScript.Arguments
17
+ ' 能原样拿到,不需要经过 powershell 的参数解析(那层会吃掉引号/& 之类)。
18
+ '
19
+ ' ## 它做什么
20
+ '
21
+ ' ① 解析 dshnotify-say://jump?session=<id>
22
+ ' ② 找插件端口(port.txt,或扫描能响应 /version 的端口)
23
+ ' ③ POST /api/dsh-notify-say/pending-jump(带 Origin 头,过 http-guard)
24
+ ' ④ 调 dsh://open 把 DSH 唤到前台(用 Run 的第二参数 0 = 隐藏窗口)
25
+ '
26
+ ' ## 安全
27
+ '
28
+ ' 只接受 dshnotify-say://jump?session=<白名单字符>,其它一律静默退出。
29
+ '
30
+ ' ## v0.5.0 协议改名
31
+ '
32
+ ' 协议名从 dshnotify 改为 dshnotify-say(见 lib/index.js 的 JUMP_PROTOCOL)。
33
+ ' 匹配**只认新名**:老键由插件启动时清掉,这里不必兼容旧 URL。
34
+
35
+ Option Explicit
36
+
37
+ Dim url, sid, port, candidates, i, ok, logPath, fso
38
+
39
+ Set fso = CreateObject("Scripting.FileSystemObject")
40
+
41
+ ' ── 诊断日志(放在 %TEMP%,与插件主日志同目录)──────────────────────────
42
+ Sub LogLine(msg)
43
+ On Error Resume Next
44
+ Dim ts, dir, f
45
+ dir = fso.GetSpecialFolder(2).Path & "\dsh-notify-say"
46
+ If Not fso.FolderExists(dir) Then fso.CreateFolder(dir)
47
+ logPath = dir & "\jump-handler.log"
48
+ Set ts = fso.OpenTextFile(logPath, 8, True)
49
+ ts.WriteLine Now & " " & msg
50
+ ts.Close
51
+ On Error GoTo 0
52
+ End Sub
53
+
54
+ ' ── 1. 取参数 ─────────────────────────────────────────────────────────────
55
+ If WScript.Arguments.Count = 0 Then
56
+ LogLine "[skip] no args"
57
+ WScript.Quit 0
58
+ End If
59
+
60
+ url = WScript.Arguments(0)
61
+ LogLine "[recv] """ & url & """"
62
+
63
+ ' ── 2. 解析 session ──────────────────────────────────────────────────────
64
+ sid = ""
65
+ Dim m
66
+ Set m = New RegExp
67
+ m.IgnoreCase = True
68
+ m.Pattern = "^dshnotify-say://jump/?(\?(.*))?$"
69
+ If Not m.Test(url) Then
70
+ LogLine "[skip] url not matched"
71
+ WScript.Quit 0
72
+ End If
73
+
74
+ Dim query
75
+ query = ""
76
+ Set m = New RegExp
77
+ m.IgnoreCase = True
78
+ m.Pattern = "\?(.*)$"
79
+ If m.Test(url) Then query = m.Execute(url)(0).SubMatches(0)
80
+
81
+ Set m = New RegExp
82
+ m.IgnoreCase = True
83
+ m.Pattern = "(^|&)session=([^&]+)"
84
+ If m.Test(query) Then
85
+ sid = m.Execute(query)(0).SubMatches(1)
86
+ End If
87
+
88
+ ' 白名单:只接受字母数字/下划线/连字符(4-128 位)
89
+ If sid <> "" Then
90
+ Set m = New RegExp
91
+ m.Pattern = "^[A-Za-z0-9_-]{4,128}$"
92
+ If Not m.Test(sid) Then
93
+ LogLine "[skip] bad session id: """ & sid & """"
94
+ sid = ""
95
+ End If
96
+ End If
97
+
98
+ LogLine "[parse] sid=" & sid
99
+ If sid = "" Then WScript.Quit 0
100
+
101
+ ' ── 3. 找端口 ────────────────────────────────────────────────────────────
102
+ ' 优先 port.txt(插件在注册路由时写入)
103
+ port = 0
104
+ On Error Resume Next
105
+ Dim ts2, txt
106
+ Dim shEnv, localAppData, p1
107
+ Set shEnv = CreateObject("WScript.Shell")
108
+ localAppData = shEnv.ExpandEnvironmentStrings("%LOCALAPPDATA%")
109
+ If localAppData = "" Or InStr(localAppData, "%") > 0 Then
110
+ ' 兜底:TEMP 的上一级就是 LOCALAPPDATA
111
+ localAppData = fso.GetSpecialFolder(2).ParentFolder.Path
112
+ End If
113
+ p1 = localAppData & "\dsh-notify-say\port.txt"
114
+ LogLine "[port] looking at " & p1
115
+ If fso.FileExists(p1) Then
116
+ Set ts2 = fso.OpenTextFile(p1, 1)
117
+ txt = Trim(ts2.ReadAll)
118
+ ts2.Close
119
+ If IsNumeric(txt) Then port = CLng(txt)
120
+ LogLine "[port] from port.txt=" & port
121
+ Else
122
+ LogLine "[port] port.txt not found"
123
+ End If
124
+ On Error GoTo 0
125
+
126
+ ' 候选端口:port.txt 优先,再补常见/历史端口
127
+ candidates = ""
128
+ If port > 0 Then candidates = CStr(port)
129
+ Dim extra
130
+ extra = Array("55510", "58163", "59525", "53523", "50061", "19387")
131
+ For i = 0 To UBound(extra)
132
+ If InStr("," & candidates & ",", "," & extra(i) & ",") = 0 Then
133
+ If candidates = "" Then
134
+ candidates = extra(i)
135
+ Else
136
+ candidates = candidates & "," & extra(i)
137
+ End If
138
+ End If
139
+ Next
140
+
141
+ ' ── 4. POST pending-jump ────────────────────────────────────────────────
142
+ Dim ports
143
+ ports = Split(candidates, ",")
144
+ ok = False
145
+
146
+ For i = 0 To UBound(ports)
147
+ If Not ok Then
148
+ Dim px, body, httpResp
149
+ px = ports(i)
150
+ If IsNumeric(px) And CLng(px) > 0 Then
151
+ On Error Resume Next
152
+ body = "{""sessionId"":""" & sid & """,""at"":" & CStr(Now * 86400000) & "}"
153
+ ' 正确的毫秒时间戳(VBS 没有 Date.now,用 Timer 不够,用 DateDiff)
154
+ Dim epochMs
155
+ epochMs = DateDiff("s", #1/1/1970#, Now()) * 1000
156
+ body = "{""sessionId"":""" & sid & """,""at"":" & CStr(epochMs) & "}"
157
+
158
+ Set httpResp = CreateObject("MSXML2.XMLHTTP.6.0")
159
+ httpResp.Open "POST", "http://127.0.0.1:" & px & "/api/dsh-notify-say/pending-jump", False
160
+ httpResp.setRequestHeader "Origin", "http://127.0.0.1:" & px
161
+ httpResp.setRequestHeader "Content-Type", "application/json"
162
+ httpResp.Send body
163
+ If httpResp.Status = 200 Then
164
+ LogLine "[posted] port=" & px & " status=" & httpResp.Status
165
+ ok = True
166
+ Else
167
+ LogLine "[post-fail] port=" & px & " status=" & httpResp.Status
168
+ End If
169
+ On Error GoTo 0
170
+ End If
171
+ End If
172
+ Next
173
+
174
+ If Not ok Then LogLine "[warn] no port accepted the POST"
175
+
176
+ ' ── 5. 唤窗(第二参数 0 = 隐藏窗口)────────────────────────────────────
177
+ On Error Resume Next
178
+ Dim sh
179
+ Set sh = CreateObject("WScript.Shell")
180
+ sh.Run "cmd /c start """" dsh://open", 0, False
181
+ LogLine "[open] dsh://open"
182
+ On Error GoTo 0
package/lib/client.js CHANGED
@@ -1780,7 +1780,7 @@ window.__ModuleLoader__.load({
1780
1780
  //
1781
1781
  // ⚠️ 2026-10-20 更正:这里原本写着「Toast 的点击只能唤起窗口、
1782
1782
  // 带不了会话 id,所以点通知才跳做不到」。**那个结论已经过时** ——
1783
- // v0.4.70 起通过注册自有协议 dshnotify:// 已能精确跳转,
1783
+ // v0.4.70 起通过注册自有协议 dshnotify-say:// 已能精确跳转,
1784
1784
  // 见下面新增的 toastJumpSession 开关。
1785
1785
  // 「只能靠窗口从后台回来作为信号」现在仅适用于**未开启**精准跳转时。
1786
1786
  rows.push(h('div', { key: 'sepHr2', style: { margin: '10px 0 4px', borderTop: '1px solid rgba(128,128,128,.25)' } }))
@@ -1810,7 +1810,7 @@ window.__ModuleLoader__.load({
1810
1810
  h('span', { style: S.toggleLabel }, '点击通知跳到对应会话'),
1811
1811
  h('span', { style: S.toggleDesc },
1812
1812
  ' — 点哪条通知就打开哪条会话,多会话时尤其有用。'
1813
- + '开启后会在 Windows 注册 dshnotify:// 协议,关掉时自动清理。'
1813
+ + '开启后会在 Windows 注册 dshnotify-say:// 协议,关掉时自动清理。'
1814
1814
  + '这是「你点了才跳」,与下面的自动跳不是一回事。'),
1815
1815
  ),
1816
1816
  ))