dsh-notify-me 1.20.0 → 1.21.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.
- package/CHANGELOG.md +32 -0
- package/LICENSE +21 -21
- package/README.en.md +12 -9
- package/README.md +12 -9
- package/lib/client.js +68 -9
- package/lib/focus-window.ps1 +17 -5
- package/lib/win-toast.js +32 -7
- package/lib/win-toast.ps1 +6 -3
- package/package.json +3 -2
- package/smoke/win-toast-test.mjs +31 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to **dsh-notify-me** are documented here.
|
|
4
4
|
|
|
5
|
+
## [1.21.0] — 2026-11-16
|
|
6
|
+
|
|
7
|
+
点桌面通知的正文现在真能把 DSH 从最小化和托盘里拉回来;macOS 在 DSH 已经处于前台时点原生通知也会立即切到对应会话。
|
|
8
|
+
|
|
9
|
+
### 修复
|
|
10
|
+
|
|
11
|
+
- **Windows 原生审批 Toast 点正文不提窗**([#40](https://github.com/chromoany/dsh-notify-me/issues/40)):正文点击原来回的是 `dsh://open` 深链——Windows 上这条深链既拉不起最小化窗口,更拉不起 `SW_HIDE` 到托盘的窗口(1.14.0 就因此把整条深链删掉,1.19.0 的原生 Toast 又把它请回来)。现在正文点击统一回 `dsh-notify-me://open`(有会话时带 `?session=`),协议处理器写动作文件后照旧尝试激活;页面侧 `applyWinAction()` 收到 `open` 先 POST 宿主 focus 路由抬窗、再切会话,无会话的正文点击也保留为一次纯抬窗(`lib/win-toast.js` 不再把无 session 的 open 丢掉)。`lib/focus-window.ps1` 同时不再过滤 `IsWindowVisible=false` 的 DSH 主窗:托盘隐藏的 `Chrome_WidgetWin_1` 先 `ShowWindow(SW_SHOW)` 再走原有的 Alt / foreground 步骤,优先隐藏主窗而不是同进程的可见辅助窗口,DETAIL 记 `step 0` 与 `tray-hidden`。
|
|
12
|
+
- **macOS 原生通知在 DSH 已在前台时点击不切会话**([#38](https://github.com/chromoany/dsh-notify-me/pull/38),TianqiCai):助手的点击文件只在页面重新获得焦点时被读取,而 DSH 本来就处于前台时 `dsh://open` 不会产生新的激活,页面收不到 `focus`,文件就留在临时目录里,直到你下次切走再回来才补跳一次。macOS 通道现在会在通知挂出后、页面处于前台时每秒探测一次宿主(最多 120 秒),点击后 1 秒内完成切换,读到点击即停;窗口不在前台时不轮询,仍由 `focus` 事件处理。Windows 端的 `startWinPoll` 一直有同样的处理,这次补齐 macOS 的缺口。
|
|
13
|
+
- **Windows 审批轮询不随插件销毁停止**:`startWinPoll` 的 1.5 秒 interval 原来只在待审批动作消失后自行结束,插件卸载时仍会跑满 180 秒。现在补了 `stopWinPoll()`,并和 macOS 轮询一起挂到插件卸载清理里。
|
|
14
|
+
|
|
15
|
+
### 测试
|
|
16
|
+
|
|
17
|
+
- `smoke/win-toast-test.mjs` 新增静态断言:`win-toast.ps1` 正文不得再出现 `launch="dsh://open"`,必须出现 `launch="dsh-notify-me://open"`;新增 `dsh-notify-me://open`(无 session)解析为 `{ action: 'open', sessionId: '' }` 的用例,钉住「无会话正文点击仍是一次抬窗请求」。
|
|
18
|
+
- `smoke/smoke-test.cjs` 新增两条用例:`winNativeToastClick()` 在 Windows 桌面壳里发一条原生审批 Toast,塞回 `open` 动作后断言页面只 POST 一次 focus 路由才切到被提醒的会话(`raiseLast === 'focused'`),无 session 的 `open` 只抬窗不切;`macNativeClickPoll()`(来自 [#38](https://github.com/chromoany/dsh-notify-me/pull/38))模拟 macOS 前台点击,只靠 1 秒轮询切到目标会话并断言点击后轮询停止。
|
|
19
|
+
|
|
20
|
+
### 文档
|
|
21
|
+
|
|
22
|
+
- README 中英同步:抬窗候选不再要求窗口可见,托盘隐藏窗口先 `SW_SHOW`;Windows 原生 Toast 的正文点击改为自家协议 + 页面轮询抬窗;「已知限制」里移除托盘隐藏(`SW_HIDE`)这一条,并按实测更新 Windows 仍可能抬不起的场合。
|
|
23
|
+
- `docs/listing.md` 版本号升到 1.21.0。
|
|
24
|
+
|
|
25
|
+
## [1.20.1] — 2026-11-13
|
|
26
|
+
|
|
27
|
+
Windows 中文用户名下点审批通知的「同意 / 拒绝」不再弹脚本错误:协议处理器改成纯 ASCII + UTF-16LE BOM 落盘。
|
|
28
|
+
|
|
29
|
+
### 修复
|
|
30
|
+
|
|
31
|
+
- **非 ASCII 用户名下点通知按钮必弹 800A004C**([#36](https://github.com/chromoany/dsh-notify-me/issues/36)):`notify-handler.vbs` 原来按 UTF-8 无 BOM 写入,且把 `C:\Users\<用户名>\AppData\Local\dsh-notify-me\actions` 整个绝对路径烘进脚本。WSH 用系统 ANSI 代码页(中文是 CP936)解码这种文件,中文用户名被按双字节拆开、路径里的反斜杠被吃掉,第 8 行 `FolderExists` 找不到目录,于是每次点按钮都弹 Windows Script Host 错误框,动作写不进 actions 目录,DSH 也不会被唤回。现在脚本里只写 `sh.ExpandEnvironmentStrings("%LOCALAPPDATA%") & "\dsh-notify-me\actions"`,点击时才解析路径,脚本正文保持纯 ASCII;文件本身同时改成 UTF-16LE + BOM 写入,将来真有非 ASCII 进脚本也不会被按 ANSI 解码。
|
|
32
|
+
|
|
33
|
+
### 测试
|
|
34
|
+
|
|
35
|
+
- `smoke/win-toast-test.mjs` 原来用 UTF-8 回读脚本并断言包含临时目录路径,恰好把编码问题盖住;现在断言脚本带 UTF-16LE BOM、正文纯 ASCII、含 `ExpandEnvironmentStrings` 表达式、不烘入任何 profile 路径。测试把 `LOCALAPPDATA` 指向临时目录,走的是生产分支。
|
|
36
|
+
|
|
5
37
|
## [1.20.0] — 2026-11-12
|
|
6
38
|
|
|
7
39
|
同源中继可以按网关自己的字段形状发请求体了:`relay.bodyTemplate` 写一段 JSON 模板,宿主渲染后转发;模板配错在宿主启动时就拦下,不会让每条提醒都回 500。
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 chromoany
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 chromoany
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.en.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
[](https://github.com/chromoany/dsh-notify-me/actions/workflows/test.yml)
|
|
14
14
|
[](#installation)
|
|
15
15
|
[](https://www.npmjs.com/package/dsh-notify-me)
|
|
16
|
-
[](#compatibility)
|
|
17
17
|
[](https://awesome-dsh-plugin.com)
|
|
18
18
|
|
|
19
19
|
</div>
|
|
@@ -210,7 +210,7 @@ The last block inside Advanced. The page protocol is detected automatically to t
|
|
|
210
210
|
<summary>Alert language, Desktop window raising, and reset</summary>
|
|
211
211
|
|
|
212
212
|
- **Alert language**: follow the UI / Simplified Chinese / English — governs the alert copy and the `🔔 …` title marker;
|
|
213
|
-
- **Desktop window raising**: on Windows the host route does the native activation, on macOS / Linux the `dsh://open` deep link does; raising back a minimized or covered window is measured to work on Windows and Linux (see [How the Desktop window gets raised](#how-the-desktop-window-gets-raised));
|
|
213
|
+
- **Desktop window raising**: on Windows the host route does the native activation, on macOS / Linux the `dsh://open` deep link does; raising back a minimized or covered window is measured to work on Windows and Linux, and a window hidden to the tray with `SW_HIDE` is first shown with `SW_SHOW` on Windows since 1.21.0 (see [How the Desktop window gets raised](#how-the-desktop-window-gets-raised));
|
|
214
214
|
- **Reset settings**: restores every switch and sound setting to the factory defaults (external push targets and chosen custom audio files are kept).
|
|
215
215
|
|
|
216
216
|
</details>
|
|
@@ -343,7 +343,7 @@ This is primarily a **browser-layer** plugin: local toasts, sound and the title
|
|
|
343
343
|
|
|
344
344
|
## Compatibility
|
|
345
345
|
|
|
346
|
-
Every release from `0.1.1-rc.2` through `0.2.2-rc.
|
|
346
|
+
Every release from `0.1.1-rc.2` through `0.2.2-rc.2` was tested to actually activate, including the npm `next` channel's `0.2.2-rc.2` and the `0.2.2-rc.1` build the desktop app currently bundles (the criteria: the plugin entry lands in the boot page's `__DSH_BOOT__`, its inject dependencies resolve, `/plugins/??dsh-notify-me/client.js` serves a build containing the new code, and the "Notify me" section appears in Settings). Per-release records, the host-generation shape differences and the two traps that fail silently are in **[docs/compatibility.en.md](docs/compatibility.en.md)**.
|
|
347
347
|
|
|
348
348
|
## Advanced console configuration
|
|
349
349
|
|
|
@@ -387,7 +387,7 @@ DSH Desktop is a thin Electron shell and its page lives under `dsh-app://app`: D
|
|
|
387
387
|
<details>
|
|
388
388
|
<summary>The route, the raise order, the measurements, and the security gate</summary>
|
|
389
389
|
|
|
390
|
-
On Windows the host route works like this: the shell forwards every path under `dsh-app://app` other than static assets straight to the host HTTP server (with an origin check and the host cookie injected), so that POST is a same-origin request with no CORS involved; the host half (`lib/index.js`) already runs as a child of the Electron main process, so `process.ppid` is the browser process that owns the main window. On a toast click: the page POSTs → the host spawns one `powershell.exe` running `lib/focus-window.ps1 -ProcessId <ppid>` → the script enumerates that pid's
|
|
390
|
+
On Windows the host route works like this: the shell forwards every path under `dsh-app://app` other than static assets straight to the host HTTP server (with an origin check and the host cookie injected), so that POST is a same-origin request with no CORS involved; the host half (`lib/index.js`) already runs as a child of the Electron main process, so `process.ppid` is the browser process that owns the main window. On a toast click: the page POSTs → the host spawns one `powershell.exe` running `lib/focus-window.ps1 -ProcessId <ppid>` → the script enumerates that pid's owner-less, non-toolwindow top-level windows (visible ones first; a DSH main window hidden to the tray with `SW_HIDE` is kept too, ahead of the same process's visible helper windows, and gets `ShowWindow(SW_SHOW)` first) → activates adaptively → compares `GetForegroundWindow()` and prints `FOCUSED=1|0` → the host answers `200` / `202`.
|
|
391
391
|
|
|
392
392
|
On Windows the raise order is adaptive: already in front means do nothing (the common case, zero flicker); minimized means `SW_RESTORE` first; then a synthetic Alt tap (`keybd_event` down/up) grants the calling thread foreground permission before `SetForegroundWindow`; only if all of that fails does it fall back to `SW_MINIMIZE` + `SW_RESTORE`. `SetForegroundWindow` on its own gets refused by the foreground lock — per call, unrelated to `ForegroundLockTimeout`. That also re-reads why the 1.5.2 deep-link approach was "sometimes it works": the times the window did come forward were most likely the OS activating the app on the click itself.
|
|
393
393
|
|
|
@@ -397,7 +397,7 @@ Security-wise the plugin opens exactly one exact route. Requests outside the voc
|
|
|
397
397
|
|
|
398
398
|
That header is only a "this came from the page" marker, not the defence — a DNS-rebinding page is same-origin with the address it resolved, so it can send any custom header and triggers no preflight. The real gate is three checks: the peer address must be loopback, or exactly the address the listener itself is bound to; `Host` must be a loopback name (`127.0.0.1` / `localhost` / `[::1]`, port optional) or that same bind address, because the shell deletes `host` when forwarding and fetch refills it from the URL it dialled, while a rebound page still has the attacker's domain in `Host`; and an `Origin`, when present, must be same-origin with that `Host`. Any failure answers `403`, with `reason` set to `bad-remote` / `bad-host` / `cross-origin`. A `GET` returns only `{ok, route, enabled, desktop, platform}`, so after installing you can open it in a browser to confirm the route is there. Calls within 400 ms coalesce into one, and a script that has not answered after 8 s is killed and counted as a failure.
|
|
399
399
|
|
|
400
|
-
The cases where it will not raise are the same ones listed under [Known limitations](#known-limitations) (elevated window, another virtual desktop, a foreground repeatedly stolen
|
|
400
|
+
The cases where it will not raise are the same ones listed under [Known limitations](#known-limitations) (elevated window, another virtual desktop, a foreground repeatedly stolen); they all answer `202` truthfully and the conversation switch still happens. A main window hidden to the tray with `SW_HIDE` used to answer `202` outright; since 1.21.0 it is `ShowWindow(SW_SHOW)`-ed first and then goes through the same activation steps ([#40](https://github.com/chromoany/dsh-notify-me/issues/40)).
|
|
401
401
|
|
|
402
402
|
</details>
|
|
403
403
|
|
|
@@ -407,7 +407,7 @@ On macOS Desktop (`dsh-app://app`) the page's own `new Notification()` never rea
|
|
|
407
407
|
|
|
408
408
|
- **One-time setup**: `bash macos/build.sh` builds `macos/DSH Notify.app` (needs Xcode Command Line Tools, a few seconds). The bundle is `.gitignore`d, so it is in neither the repository nor the npm package. Allow it under System Settings → Notifications → DSH Notify the first time one arrives.
|
|
409
409
|
- **Which path is used is automatic**: the host registers the route only when all three hold — macOS, the desktop shell (the Electron binary), and a built helper. Otherwise the `GET` probe reports `enabled: false` and the page keeps its own notification, exactly as before this change. `dsh web` in a browser never reaches the route.
|
|
410
|
-
- **Clicking returns to that conversation**: the helper writes the session id to `dsh-notify-me-click.json` in the temp directory and opens `dsh://open` to raise the window; the next time the page regains focus it `GET`s that id once, switches to the conversation and clears it, so nothing jumps twice. With `autoFocus` off the window is raised but the conversation is left alone.
|
|
410
|
+
- **Clicking returns to that conversation**: the helper writes the session id to `dsh-notify-me-click.json` in the temp directory and opens `dsh://open` to raise the window; the next time the page regains focus it `GET`s that id once, switches to the conversation and clears it, so nothing jumps twice. When DSH is already in front, `dsh://open` produces no new activation and the page gets no `focus` event, so after a native toast is posted the page also probes the host once a second while it is in front (up to 120 s): a click switches within a second and the poll stops as soon as the click is read; nothing is polled while the window is not in front. With `autoFocus` off the window is raised but the conversation is left alone.
|
|
411
411
|
- **Sound**: the "system notification sound" mode hands the sound to macOS; the synthesized modes stay in the page, so the two never stack.
|
|
412
412
|
- **Still no Approve / Reject buttons**: notification actions require registered categories, and the helper never touches approval state — decisions stay in the conversation.
|
|
413
413
|
- **Turning it off**: add `macNotify: { enabled: false }` to the `notify-me` entry in the profile's patch layer, or delete `macos/DSH Notify.app` and the probe falls back to `enabled: false`.
|
|
@@ -420,6 +420,8 @@ The page's own `new Notification()` is not refused on Windows Desktop, but it ca
|
|
|
420
420
|
|
|
421
421
|
- **Who posts it**: the host half (`lib/index.js`) registers `POST /__dsh-notify-me/win-toast` and runs one `powershell.exe` with `lib/win-toast.ps1`, which sends the toast through the WinRT `ToastNotificationManager` under the "DeepSeek Harness" AUMID — the same notification stack DSH's own notifications use, so it follows the same system notification settings.
|
|
422
422
|
- **How the buttons decide**: the toast's two buttons use `activationType="protocol"` and point at `dsh-notify-me://approve?token=…` / reject. Clicking one invokes the handler registered for that protocol (a VBS that writes the action to a file and opens `dsh://open`); the host hands the action back on the page's next probe, and the page still goes through the same `decidePending()` the approval panel uses — "Approve" is "Allow once" and releases nothing extra.
|
|
423
|
+
- **The body click raises too**: a body click now always goes through `dsh-notify-me://open` (with `?session=` when there is a conversation, and still kept as a plain raise request when there is none) instead of treating `dsh://open` as the Windows raising mechanism — that deep link neither restores a minimized window nor a window hidden to the tray with `SW_HIDE`. While an approval is pending the page probes every 1.5 s; an `open` action first POSTs the host focus route to raise the window and only then switches the conversation, with tray-hidden windows shown first by `focus-window.ps1` ([#40](https://github.com/chromoany/dsh-notify-me/issues/40)).
|
|
424
|
+
- **Non-ASCII user names**: the handler script is written as UTF-16LE with a BOM and resolves its action directory from `sh.ExpandEnvironmentStrings("%LOCALAPPDATA%")` at click time, so its body stays pure ASCII — WSH can no longer decode it in the system ANSI code page and mangle the path (which made every button click fail with an `800A004C` script error, [#36](https://github.com/chromoany/dsh-notify-me/issues/36)); fixed in 1.20.1. An upgrade needs only a restart: the first buttoned toast after it rewrites the script, and no manual cleanup is required.
|
|
423
425
|
- **Registration**: the first buttoned toast registers that handler under `HKCU\Software\Classes\dsh-notify-me` (current-user, no admin rights needed) and books the toast into `ToastNotificationManager.History` by tag. Tokens are single-use and valid for 3 minutes; an action file is deleted once taken.
|
|
424
426
|
- **When it does not post**: outside the Windows desktop host, with `winToast.enabled: false`, or without `powershell.exe`, the route reports `enabled: false` (`501`) and the page keeps its own buttonless notification — the same behaviour as before this change.
|
|
425
427
|
- **Turning it off**: add `winToast: { enabled: false }` to the `notify-me` entry in the profile's patch layer; approval alerts go back to the page's own notification, without buttons.
|
|
@@ -440,7 +442,7 @@ Like the other routes, this one registers exactly one exact path and refuses eve
|
|
|
440
442
|
|
|
441
443
|
- Quick-decision buttons need a Service Worker: `http://127.0.0.1` and `https` work, `http://192.168.x.x`-style LAN addresses do not; **the Desktop (`dsh-app://`) is tested and cannot register a Service Worker** (the host does not grant the `allowServiceWorkers` privilege): on Windows Desktop approval alerts are posted by the host as native toasts with real buttons (see [How Windows Desktop raises buttoned notifications](#how-windows-desktop-raises-buttoned-notifications)), while macOS Desktop falls back to a buttonless notification. When the host renders no notification buttons, the `bridge` field of `debug()` explains why, and nothing else is affected.
|
|
442
444
|
- Windows caps a toast tag at 64 characters, and Chromium hands the platform the whole `n#<origin>#<tag>` string — the desktop page's `dsh-app://app` alone takes 16. The plugin sizes each tag against the current `location.origin` and, when it does not fit, keeps a readable prefix and swaps the tail for a short hash, so a tag seen through `debug()` may be shortened; if the platform still refuses one, its message lands in `debug().lastToastReject` and the settings test button reports it instead of claiming the toast was sent.
|
|
443
|
-
- On Desktop (Windows) a toast click can still fail to raise the window: when the target window is owned by a higher integrity level (elevated / UAC), sits on another virtual desktop, has its foreground repeatedly stolen by another process,
|
|
445
|
+
- On Desktop (Windows) a toast click can still fail to raise the window: when the target window is owned by a higher integrity level (elevated / UAC), sits on another virtual desktop, or has its foreground repeatedly stolen by another process, the host script answers `FOCUSED=0` and the route answers `202`, with the conversation switch intact (see [How the Desktop window gets raised](#how-the-desktop-window-gets-raised)). A window hidden to the tray with `SW_HIDE` is first `SW_SHOW`-ed since 1.21.0, so it no longer falls under this entry ([#40](https://github.com/chromoany/dsh-notify-me/issues/40)).
|
|
444
446
|
- Desktop (macOS / Linux) toast clicks rely on the `dsh://open` deep link: when the system has no `x-scheme-handler/dsh` registration, or the shell has no `second-instance` / `open-url` handling, the window will not raise. Measured to work on Linux; macOS is untested.
|
|
445
447
|
- macOS Desktop: the page's own `new Notification()` never reaches the Notification Centre (`Notification.permission` reads `granted` yet nothing shows), so the plugin posts through a host-spawned helper — build it once with `bash macos/build.sh` (see [How macOS Desktop raises system notifications](#how-macos-desktop-raises-system-notifications)). Without the helper it falls back to the old behaviour, i.e. no system notification on Desktop. Approval buttons still do not render on the macOS desktop host; Windows Desktop posts a native toast with working buttons (see [How Windows Desktop raises buttoned notifications](#how-windows-desktop-raises-buttoned-notifications)).
|
|
446
448
|
|
|
@@ -472,13 +474,13 @@ npm pack --dry-run # preview the published tarball
|
|
|
472
474
|
<details>
|
|
473
475
|
<summary>What each suite covers, and the manual raise check</summary>
|
|
474
476
|
|
|
475
|
-
`smoke/smoke-test.cjs` is the offline state-machine suite: three host generations + master switch + zh/en cases + the quick-decision bridge (worker half included) + idle detection and toast self-dismiss + withdrawing leftover toasts on return + toast tag length handling + the page's host-bridge probe / heartbeat / release and the shape of `debug().hostBridge
|
|
477
|
+
`smoke/smoke-test.cjs` is the offline state-machine suite: three host generations + master switch + zh/en cases + the quick-decision bridge (worker half included) + idle detection and toast self-dismiss + withdrawing leftover toasts on return + toast tag length handling + the page's host-bridge probe / heartbeat / release and the shape of `debug().hostBridge`, plus two desktop native-channel cases — a Windows native approval toast's body click switches only after the host focus route is posted (and a no-session click only raises), and a macOS frontmost click switches through the 1 s poll and stops polling once read. `smoke/host-route-test.mjs` needs no local DSH and runs the `lib/index.js` route, its probe and the 403/405/501 gate on every platform.
|
|
476
478
|
|
|
477
479
|
The three new suites also ship their own fake `ctx`, need no local DSH and touch no network: `smoke/page-bridge-test.mjs` runs the page-bridge route — status shape, heartbeat and release, missing intent header `403`, cross-origin `403`, bad JSON `400`, oversized `413`, the `allowedOrigins`-derived `Host` (a simulated tunnel) being let through, and path collisions; `smoke/host-fallback-test.mjs` runs the host fallback — approval dedupe, `turn/end` throttling, subagent skip, no push on a fresh lease, a push after the lease expires, an immediate push after `alive:false`, language following the heartbeat, credentials re-read after a 401, and the health probe; `smoke/relay-route-test.mjs` runs the relay — the `GET` probe, `405`, cross-origin `403`, `413`, `400`, `503`, the `200` / `502` mapping and "retry exactly once on a 401", `relay.bodyTemplate` rendering and JSON escaping, a broken template registering no route at boot, and the rendered-size cap.
|
|
478
480
|
|
|
479
481
|
`smoke/mac-notify-test.mjs` runs the macOS notification route: registered only on the macOS desktop host, the probe, the `405` / `403` / `501` / `400` refusals, the arguments handed to the helper, and the click hand-off being taken exactly once. It fakes the platform and Electron version, needs no real helper, and runs on every platform.
|
|
480
482
|
|
|
481
|
-
`smoke/win-toast-test.mjs` runs the Windows native-toast route: the Windows desktop gate, the `GET` probe, the `405` / `403` / `501` / `400` refusals, the approval payload and its base64 pass-through, the three `HKCU\Software\Classes\dsh-notify-me` registration commands, approve / reject / open actions being claimed once, token expiry, and `{remove}` withdrawal. It drives `reg.exe` / `powershell.exe` through a fake `spawn`, so it needs no real Windows desktop host and runs on every platform.
|
|
483
|
+
`smoke/win-toast-test.mjs` runs the Windows native-toast route: the Windows desktop gate, the `GET` probe, the `405` / `403` / `501` / `400` refusals, the approval payload and its base64 pass-through, the three `HKCU\Software\Classes\dsh-notify-me` registration commands, approve / reject / open actions being claimed once, token expiry, and `{remove}` withdrawal. It drives `reg.exe` / `powershell.exe` through a fake `spawn`, so it needs no real Windows desktop host and runs on every platform. It also asserts the generated handler script is UTF-16LE with a BOM, pure ASCII, carries the `ExpandEnvironmentStrings` expression, and bakes in no profile path, and that the toast body launches only `dsh-notify-me://open` (never `dsh://open`); a no-session `dsh-notify-me://open` still parses as a plain raise request ([#40](https://github.com/chromoany/dsh-notify-me/issues/40)).
|
|
482
484
|
|
|
483
485
|
When `lib/focus-window.ps1` changes (Windows only), also run it by hand:
|
|
484
486
|
|
|
@@ -512,6 +514,7 @@ powershell -NoProfile -File lib/focus-window.ps1 -ProcessId 0 # the last line
|
|
|
512
514
|
| <a href="https://github.com/xty13114150041"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/xty13114150041.png" width="40" height="40" alt="@xty13114150041"></a> | [#31](https://github.com/chromoany/dsh-notify-me/issues/31) / [#32](https://github.com/chromoany/dsh-notify-me/pull/32): the macOS Desktop "notifications never arrive" investigation and the host-helper approach (`lib/mac-notify.js` + `macos/`) — supported since 1.19.0 |
|
|
513
515
|
| <a href="https://github.com/Inh-ui"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/Inh-ui.png" width="40" height="40" alt="@Inh-ui"></a> | [#33](https://github.com/chromoany/dsh-notify-me/issues/33): the report that Windows Desktop approval notifications carry no Approve / Reject buttons, with the source-level finding that Electron drops `actions` and Desktop cannot register a Service Worker — fixed in 1.19.0 |
|
|
514
516
|
| <a href="https://github.com/sakurakugu"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/sakurakugu.png" width="40" height="40" alt="@sakurakugu"></a> | [#34](https://github.com/chromoany/dsh-notify-me/pull/34): the custom JSON body template for the same-origin relay (`relay.bodyTemplate`), with tests and docs — supported since 1.20.0 |
|
|
517
|
+
| <a href="https://github.com/AlbertDope"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/AlbertDope.png" width="40" height="40" alt="@AlbertDope"></a> | [#36](https://github.com/chromoany/dsh-notify-me/issues/36): the root-cause analysis (WSH decoding the handler in the ANSI code page) and fix verification for the `800A004C` approval-button error under a non-ASCII Windows user name — fixed in 1.20.1 |
|
|
515
518
|
|
|
516
519
|
Attribution policy: external PRs are landed as maintainer commits — the original commit is not reused and no Co-authored-by trailer is added, so GitHub's contributors graph lists the maintainer only and contributors are credited above.
|
|
517
520
|
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
[](https://github.com/chromoany/dsh-notify-me/actions/workflows/test.yml)
|
|
14
14
|
[](#安装)
|
|
15
15
|
[](https://www.npmjs.com/package/dsh-notify-me)
|
|
16
|
-
[](#兼容性)
|
|
17
17
|
[](https://awesome-dsh-plugin.com)
|
|
18
18
|
|
|
19
19
|
</div>
|
|
@@ -210,7 +210,7 @@ dsh-notify-me 把「监督」和「守在屏幕前」解耦:只在真的出现
|
|
|
210
210
|
<summary>通知语言、桌面端抬窗与恢复默认</summary>
|
|
211
211
|
|
|
212
212
|
- **通知语言**:跟随界面 / 简体中文 / English——决定通知文字与 `🔔 …` 标题标记使用的语言;
|
|
213
|
-
- **桌面端抬窗**:Windows 走宿主路由做原生激活、macOS / Linux 走 `dsh://open` 深链;最小化、被别的窗口盖住的窗口在 Windows 与 Linux
|
|
213
|
+
- **桌面端抬窗**:Windows 走宿主路由做原生激活、macOS / Linux 走 `dsh://open` 深链;最小化、被别的窗口盖住的窗口在 Windows 与 Linux 上都实测能抬回来,Windows 上 `SW_HIDE` 到托盘的窗口也会先 `SW_SHOW` 再抬(1.21.0 起,见[桌面端怎么抬窗的](#桌面端怎么抬窗的));
|
|
214
214
|
- **恢复默认设置**:把所有开关与音效设置还原成出厂值(不动外部推送目标和已选的自定义音频文件)。
|
|
215
215
|
|
|
216
216
|
</details>
|
|
@@ -343,7 +343,7 @@ YAML 的单引号里模板原样保留;页面设置里把「自定义 Webhook
|
|
|
343
343
|
|
|
344
344
|
## 兼容性
|
|
345
345
|
|
|
346
|
-
已逐版实测在 `0.1.1-rc.2` 到 `0.2.2-rc.
|
|
346
|
+
已逐版实测在 `0.1.1-rc.2` 到 `0.2.2-rc.2` 上真正激活,含 npm `next` 渠道的 `0.2.2-rc.2` 与桌面端当前打包的 `0.2.2-rc.1`(判定标准:插件条目进启动页 `__DSH_BOOT__`、注入依赖解析通过、`/plugins/??dsh-notify-me/client.js` 返回含新代码的构建、设置里出现「通知提醒」分区)。逐版适配记录、宿主代际的形状差异与两个会静默失效的坑,见 **[docs/compatibility.md](docs/compatibility.md)**。
|
|
347
347
|
|
|
348
348
|
## 控制台高级配置
|
|
349
349
|
|
|
@@ -387,7 +387,7 @@ DSH Desktop 是一层 Electron 壳,页面跑在 `dsh-app://app` 下:DOM 的
|
|
|
387
387
|
<details>
|
|
388
388
|
<summary>展开路由、激活顺序、实测数据与安全闸门</summary>
|
|
389
389
|
|
|
390
|
-
Windows 的宿主路由:壳把 `dsh-app://app` 下除静态资源以外的所有路径原样转发给宿主 HTTP server(带 origin 校验、注入宿主 cookie),所以上面那个 POST 是同源请求,没有 CORS 问题;宿主半(`lib/index.js`)本来就跑在 Electron 主进程的子进程里,`process.ppid` 就是主窗口所属的浏览器进程。点通知时:页面 POST → 宿主起一次 `powershell.exe` 跑 `lib/focus-window.ps1 -ProcessId <ppid>` → 脚本枚举该 pid
|
|
390
|
+
Windows 的宿主路由:壳把 `dsh-app://app` 下除静态资源以外的所有路径原样转发给宿主 HTTP server(带 origin 校验、注入宿主 cookie),所以上面那个 POST 是同源请求,没有 CORS 问题;宿主半(`lib/index.js`)本来就跑在 Electron 主进程的子进程里,`process.ppid` 就是主窗口所属的浏览器进程。点通知时:页面 POST → 宿主起一次 `powershell.exe` 跑 `lib/focus-window.ps1 -ProcessId <ppid>` → 脚本枚举该 pid 下无 owner、非 toolwindow 的顶层窗口(可见的优先;被 `SW_HIDE` 藏到托盘的 DSH 主窗也保留,优先于同进程的可见辅助窗口,选中后先 `ShowWindow(SW_SHOW)`)→ 自适应激活 → 比对 `GetForegroundWindow()` 打印 `FOCUSED=1|0` → 宿主回 `200` / `202`。
|
|
391
391
|
|
|
392
392
|
Windows 的激活顺序是实的:已经在前台就什么都不做(最常见的情况,零闪烁);最小化了先 `SW_RESTORE`;然后合成一次 ALT 按键(`keybd_event` 按下抬起)给本线程前台权限,再 `SetForegroundWindow`;这一串都不行才退到 `SW_MINIMIZE` + `SW_RESTORE` 兜底。单独调 `SetForegroundWindow` 会被前台锁直接拒,按调用算、跟 `ForegroundLockTimeout` 无关;这也重新解释了 1.5.2 那套深链「时灵时不灵」——能抬起来的那些次,多半是系统在通知被点击时自己激活了应用。
|
|
393
393
|
|
|
@@ -397,7 +397,7 @@ Windows 的激活顺序是实的:已经在前台就什么都不做(最常见
|
|
|
397
397
|
|
|
398
398
|
那个头只是「这是页面发来的」标记,不是防线——DNS rebinding 的恶意页对目标地址而言是同源的,能带任意自定义头、也不触发预检。真正的闸门是三层:对端地址必须是 loopback,或恰好是监听器自己绑定的那个 IP;`Host` 必须是 loopback 名(`127.0.0.1` / `localhost` / `[::1]`,可带端口)或同一个绑定地址,因为壳转发时 `host` 已被删掉、由 fetch 按它拨号的 URL 重填,而 rebinding 的页面 Host 仍是攻击者域名;带了 `Origin` 就必须和 `Host` 同源。任一条不符回 `403`,`reason` 分别是 `bad-remote` / `bad-host` / `cross-origin`。`GET` 只回 `{ok, route, enabled, desktop, platform}`,装完可以先用浏览器打开确认路由在不在。400 毫秒内的重复调用合并成一次,脚本超过 8 秒没回话就 kill 掉按失败处理。
|
|
399
399
|
|
|
400
|
-
抬不起来的几种场合与[已知限制](#已知限制)
|
|
400
|
+
抬不起来的几种场合与[已知限制](#已知限制)里列的一致(提权窗口、另一虚拟桌面、前台被反复抢走),一律如实回 `202`、对话照常切。`SW_HIDE` 到托盘的隐藏主窗原来直接回 `202`,1.21.0 起先 `SW_SHOW` 再走同一套激活步骤([#40](https://github.com/chromoany/dsh-notify-me/issues/40))。
|
|
401
401
|
|
|
402
402
|
</details>
|
|
403
403
|
|
|
@@ -407,7 +407,7 @@ Windows 的激活顺序是实的:已经在前台就什么都不做(最常见
|
|
|
407
407
|
|
|
408
408
|
- **一次性准备**:`bash macos/build.sh` 编译出 `macos/DSH Notify.app`(需要 Xcode Command Line Tools,几秒钟)。产物在 `.gitignore` 里,不进仓库也不进 npm 包。首次弹通知时在「系统设置 → 通知 → DSH Notify」里允许。
|
|
409
409
|
- **走哪条路是自动的**:宿主只在「macOS + 桌面壳(Electron 二进制)+ 助手已编译」三个条件都满足时注册这条路由;任一不满足,`GET` 探测报 `enabled: false`,页面继续用自己原来的通知,行为与改动前一致。`dsh web`(浏览器)永远走不到这条路由。
|
|
410
|
-
- **点通知回到对应对话**:小助手把会话 id 写进临时目录的 `dsh-notify-me-click.json` 并打开 `dsh://open` 抬窗;页面重新获得焦点时 `GET` 一次取走这个 id
|
|
410
|
+
- **点通知回到对应对话**:小助手把会话 id 写进临时目录的 `dsh-notify-me-click.json` 并打开 `dsh://open` 抬窗;页面重新获得焦点时 `GET` 一次取走这个 id、切到对应对话,取走后即清掉,不会重复跳转。DSH 本来就处于前台时 `dsh://open` 不产生新的激活,页面收不到 `focus`,所以通知挂出后、页面在前台时还会每秒探测一次宿主(最多 120 秒),点击后 1 秒内完成切换,读到点击即停;窗口不在前台时不轮询。`autoFocus` 关掉时只抬窗不切会话。
|
|
411
411
|
- **提示音**:设置里选「系统通知音」时交给 macOS,其余音效模式仍由页面自己合成,不会两声叠在一起。
|
|
412
412
|
- **通知上仍然没有「同意 / 拒绝」按钮**:macOS 的通知动作要求注册通知类别,助手不碰审批状态,裁决仍在对话里做。
|
|
413
413
|
- **关掉它**:在 profile 的 patch 层给 `notify-me` 加 `macNotify: { enabled: false }`;或删掉 `macos/DSH Notify.app`,路由会退回 `enabled: false`。
|
|
@@ -420,6 +420,8 @@ Windows 的激活顺序是实的:已经在前台就什么都不做(最常见
|
|
|
420
420
|
|
|
421
421
|
- **谁去弹**:宿主半(`lib/index.js`)注册 `POST /__dsh-notify-me/win-toast`,由它起一次 `powershell.exe` 跑 `lib/win-toast.ps1`,用 WinRT `ToastNotificationManager` 把通知发到「DeepSeek Harness」这个 AUMID 下——与 DSH 自己的通知同级,走同一套系统通知设置。
|
|
422
422
|
- **按钮怎么裁决**:Toast 的两个按钮是 `activationType="protocol"`,分别指向 `dsh-notify-me://approve?token=…` / reject。点按钮后系统调起注册在这个协议下的处理器(一个写入动作文件、再打开 `dsh://open` 的 VBS),宿主在页面下一次探针时把动作交回页面;页面仍走审批面板里同一个 `decidePending()`——「同意」就是「允许一次」,不多放行任何东西。
|
|
423
|
+
- **点正文也会抬窗**:正文点击统一走 `dsh-notify-me://open`(有会话时带 `?session=`,没有会话也保留为一次纯抬窗),不再把 `dsh://open` 当 Windows 抬窗手段——那条深链拉不起最小化窗口,更拉不起 `SW_HIDE` 到托盘的窗口。等待审批期间页面每 1.5 秒取一次动作,取到 `open` 先 POST 宿主 focus 路由抬窗、再切会话;托盘隐藏的窗口由 `focus-window.ps1` 先 `SW_SHOW` 再激活([#40](https://github.com/chromoany/dsh-notify-me/issues/40))。
|
|
424
|
+
- **中文用户名等非 ASCII profile**:处理器脚本按 UTF-16LE + BOM 写盘,动作目录在点击时才用 `sh.ExpandEnvironmentStrings("%LOCALAPPDATA%")` 解析——脚本正文因此全是 ASCII,不会再被 WSH 按系统 ANSI 代码页解码后把路径弄乱(此前每次点按钮都弹 `800A004C` 脚本错误,[#36](https://github.com/chromoany/dsh-notify-me/issues/36)),1.20.1 起修复。升级后重启桌面端即可,第一次发带按钮的 Toast 时会重写这份脚本,不用手动清旧文件。
|
|
423
425
|
- **注册**:第一次发带按钮的 Toast 时在 `HKCU\Software\Classes\dsh-notify-me` 注册上面那个处理器(当前用户级,不需要管理员权限),并按 tag 记账到 `ToastNotificationManager.History`。token 单次、3 分钟有效;动作文件被取走后即删。
|
|
424
426
|
- **不弹的场合**:非 Windows 桌面宿主、`winToast.enabled: false`、或 `powershell.exe` 不存在时,路由报 `enabled: false`(`501`),页面继续用自己那条不带按钮的通知,行为与改动前一致。
|
|
425
427
|
- **关掉它**:在 profile 的 patch 层给 `notify-me` 加 `winToast: { enabled: false }`,审批提醒回到页面自己的通知(无按钮)。
|
|
@@ -440,7 +442,7 @@ Windows 的激活顺序是实的:已经在前台就什么都不做(最常见
|
|
|
440
442
|
|
|
441
443
|
- 快捷裁决按钮要 Service Worker:`http://127.0.0.1`、`https` 可用,`http://192.168.x.x` 这类局域网地址不行;**桌面端(`dsh-app://`)已实测无法注册 Service Worker**(宿主未开放 `allowServiceWorkers` 特权)。因此 Windows 桌面端的审批按钮改由宿主发原生 Toast(见 [Windows 桌面端怎么发带按钮的通知](#windows-桌面端怎么发带按钮的通知)),macOS 桌面端仍无按钮、点通知回对话裁决。宿主不渲染通知按钮时,`debug()` 的 `bridge` 字段会说明原因,其余功能不受影响。
|
|
442
444
|
- Windows 的系统通知标签上限 64 字符,而 Chromium 交给平台的是 `n#<origin>#<tag>` 整串——桌面页面 `dsh-app://app` 一项就占去 16 个。插件按当前 `location.origin` 算剩余预算,超长时保留可读前缀、尾部换成短哈希,所以 `debug()` 里看到的标签可能被截短;平台仍然拒发时,原文记在 `debug().lastToastReject`,设置页的测试按钮也会如实报出来,不再「提示已发送但什么都没弹」。
|
|
443
|
-
- 桌面端(Windows)点通知后窗口仍可能抬不起来:目标窗口属于更高完整性级别(提权 / UAC
|
|
445
|
+
- 桌面端(Windows)点通知后窗口仍可能抬不起来:目标窗口属于更高完整性级别(提权 / UAC)、在另一个虚拟桌面、或前台被别的进程反复抢回去时,宿主脚本回 `FOCUSED=0`、路由回 `202`,对话照常切(详见[桌面端怎么抬窗的](#桌面端怎么抬窗的))。`SW_HIDE` 到托盘的隐藏窗口 1.21.0 起先 `SW_SHOW` 再抬,不再属于这一条([#40](https://github.com/chromoany/dsh-notify-me/issues/40))。
|
|
444
446
|
- 桌面端(macOS / Linux)点通知依赖 `dsh://open` 深链:系统未注册 `x-scheme-handler/dsh`、或壳没有 `second-instance` / `open-url` 处理时抬不起来;Linux 上已实测正常,macOS 未实测。
|
|
445
447
|
- macOS 桌面端:页面自带的 `new Notification()` 进不了通知中心(`Notification.permission` 报 `granted` 却什么也不弹),所以插件改由宿主拉起助手发通知,需要先 `bash macos/build.sh`(见 [macOS 桌面端怎么发系统通知](#macos-桌面端怎么发系统通知))。助手未编译时退回原行为,即桌面端弹不出系统通知。审批按钮在 macOS 桌面宿主上仍然不渲染;Windows 桌面端改由宿主发原生 Toast,按钮可用(见 [Windows 桌面端怎么发带按钮的通知](#windows-桌面端怎么发带按钮的通知))。
|
|
446
448
|
|
|
@@ -472,13 +474,13 @@ npm pack --dry-run # 预览发布包
|
|
|
472
474
|
<details>
|
|
473
475
|
<summary>各测试套件覆盖范围与手动检查</summary>
|
|
474
476
|
|
|
475
|
-
`smoke/smoke-test.cjs` 是离线状态机测试:三代宿主 + 主开关 + 中英语言用例 + 快捷裁决桥(Service Worker 半侧一并跑)+ 闲置判定与通知自收 + 回到页面即收起残留通知 + 通知标签长度收口 + 页面侧 host-bridge 探测/心跳/释放与 `debug().hostBridge`
|
|
477
|
+
`smoke/smoke-test.cjs` 是离线状态机测试:三代宿主 + 主开关 + 中英语言用例 + 快捷裁决桥(Service Worker 半侧一并跑)+ 闲置判定与通知自收 + 回到页面即收起残留通知 + 通知标签长度收口 + 页面侧 host-bridge 探测/心跳/释放与 `debug().hostBridge` 形状,外加两条桌面原生通道用例——Windows 原生审批 Toast 正文点击只走宿主 focus 路由才切会话(无 session 时只抬窗不切),macOS 前台点击只靠 1 秒轮询切会话并在读走后停止。`smoke/host-route-test.mjs` 不需要本机 DSH,`lib/index.js` 的路由、探针与 403/405/501 闸门在任何平台都会跑。
|
|
476
478
|
|
|
477
479
|
新增的三个套件同样自带假 `ctx`、不联网、不需要本机 DSH:`smoke/page-bridge-test.mjs` 跑页面桥接路由的状态回包形状、心跳与释放、缺意图头 `403`、跨源 `403`、坏 JSON `400`、超长 `413`,以及 `allowedOrigins` 派生的 `Host`(模拟隧道)放行与路径冲突;`smoke/host-fallback-test.mjs` 跑宿主兜底——审批去重、`turn/end` 节流、子代理跳过、租约新鲜时不发、租约过期后发、`alive:false` 后立刻发、语言跟随心跳、401 后重读凭据、健康探针;`smoke/relay-route-test.mjs` 跑中继——`GET` 探针、`405`、跨源 `403`、`413`、`400`、`503`、`200` / `502` 映射与「401 只重试一次」、`relay.bodyTemplate` 的模板渲染与 JSON 转义、坏模板启动即不注册、渲染体积上限。
|
|
478
480
|
|
|
479
481
|
`smoke/mac-notify-test.mjs` 跑 macOS 通知路由:只在 macOS 桌面宿主注册、探测、`405` / `403` / `501` / `400` 的拒绝、传给助手的参数(含 `--id` / `--sound` 与 `{remove:id}` 撤回)、点击回传只被取走一次。它用假的平台与 Electron 版本号驱动,不需要真的编译助手,在任何平台都会跑。
|
|
480
482
|
|
|
481
|
-
`smoke/win-toast-test.mjs` 跑 Windows 原生 Toast 路由:Windows 桌面门控、`GET` 探针、`405` / `403` / `501` / `400` 的拒绝、审批 payload 与 base64 传递、`HKCU\Software\Classes\dsh-notify-me` 的三条注册命令、approve / reject / open 动作单次认领、token 过期与 `{remove}` 撤回。它用假的 `spawn` 驱动 `reg.exe` / `powershell.exe`,不需要真的 Windows
|
|
483
|
+
`smoke/win-toast-test.mjs` 跑 Windows 原生 Toast 路由:Windows 桌面门控、`GET` 探针、`405` / `403` / `501` / `400` 的拒绝、审批 payload 与 base64 传递、`HKCU\Software\Classes\dsh-notify-me` 的三条注册命令、approve / reject / open 动作单次认领、token 过期与 `{remove}` 撤回。它用假的 `spawn` 驱动 `reg.exe` / `powershell.exe`,不需要真的 Windows 桌面宿主。另外断言处理器脚本是 UTF-16LE + BOM、正文纯 ASCII、含 `ExpandEnvironmentStrings` 表达式、不烘入 profile 路径,且正文点击只发 `dsh-notify-me://open`(不得再出现 `dsh://open`);`dsh-notify-me://open` 不带 session 时仍解析为一次纯抬窗([#40](https://github.com/chromoany/dsh-notify-me/issues/40))。
|
|
482
484
|
|
|
483
485
|
改到 `lib/focus-window.ps1` 时(仅 Windows),另需手动跑一次:
|
|
484
486
|
|
|
@@ -512,6 +514,7 @@ powershell -NoProfile -File lib/focus-window.ps1 -ProcessId 0 # 末行应是 F
|
|
|
512
514
|
| <a href="https://github.com/xty13114150041"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/xty13114150041.png" width="40" height="40" alt="@xty13114150041"></a> | [#31](https://github.com/chromoany/dsh-notify-me/issues/31) / [#32](https://github.com/chromoany/dsh-notify-me/pull/32):macOS 桌面端页面通知不响的排查与宿主助手方案(`lib/mac-notify.js` + `macos/`),1.19.0 起支持 |
|
|
513
515
|
| <a href="https://github.com/Inh-ui"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/Inh-ui.png" width="40" height="40" alt="@Inh-ui"></a> | [#33](https://github.com/chromoany/dsh-notify-me/issues/33):Windows 桌面端审批通知没有「同意 / 拒绝」按钮的反馈,以及 Electron 丢弃 `actions` / 桌面端注册不了 Service Worker 的源码级定位,1.19.0 起支持 |
|
|
514
516
|
| <a href="https://github.com/sakurakugu"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/sakurakugu.png" width="40" height="40" alt="@sakurakugu"></a> | [#34](https://github.com/chromoany/dsh-notify-me/pull/34):同源中继自定义 JSON 请求体模板(`relay.bodyTemplate`),含测试与文档,1.20.0 起支持 |
|
|
517
|
+
| <a href="https://github.com/AlbertDope"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/AlbertDope.png" width="40" height="40" alt="@AlbertDope"></a> | [#36](https://github.com/chromoany/dsh-notify-me/issues/36):Windows 中文用户名下审批按钮必弹 `800A004C` 的根因定位(WSH 按 ANSI 代码页解码处理器脚本)与修复验证,1.20.1 起修复 |
|
|
515
518
|
|
|
516
519
|
署名口径:本仓库收编外部 PR 时以维护者提交落地——不沿用原 commit、不挂 Co-authored-by,GitHub 的 contributors 图只显示维护者,贡献者以上面的致谢署名。
|
|
517
520
|
|
package/lib/client.js
CHANGED
|
@@ -751,9 +751,21 @@
|
|
|
751
751
|
// Notification Center alerts through a small helper app. Probed once at
|
|
752
752
|
// start; when enabled every toast goes there instead of new Notification().
|
|
753
753
|
// A click on such a notification raises DSH via dsh://open and leaves the
|
|
754
|
-
// session id with the host
|
|
754
|
+
// session id with the host. It is collected on the next page focus — and,
|
|
755
|
+
// while a toast is outstanding, by a short poll below: clicking a banner
|
|
756
|
+
// while DSH is already the frontmost app produces no focus event at all
|
|
757
|
+
// (dsh://open activates nothing), so a focus-only read would sit on the
|
|
758
|
+
// click file until the user happens to leave and come back.
|
|
755
759
|
var MAC_NOTIFY_ROUTE = "/__dsh-notify-me/mac-notify";
|
|
756
760
|
var macNative = { enabled: false, last: null };
|
|
761
|
+
// One probe per second for as long as a native toast could still be
|
|
762
|
+
// clicked; the poll mirrors the Windows startWinPoll() below, which has
|
|
763
|
+
// always handled the "window already focused" case. Two minutes is far
|
|
764
|
+
// beyond the 5 s / 12 s auto-dismiss windows and costs one loopback GET.
|
|
765
|
+
var MAC_POLL_INTERVAL_MS = 1000;
|
|
766
|
+
var MAC_POLL_MAX_TICKS = 120;
|
|
767
|
+
var macPoll = null;
|
|
768
|
+
var macPollTicks = 0;
|
|
757
769
|
// A toast emitted before the first probe settles is queued and replayed
|
|
758
770
|
// through whatever channel the probe chooses. Without this, a wait that
|
|
759
771
|
// already existed at boot was "shown" into a channel that did not exist
|
|
@@ -784,7 +796,10 @@
|
|
|
784
796
|
return res && res.ok ? res.json() : null;
|
|
785
797
|
}).then(function (body) {
|
|
786
798
|
macNative.enabled = !!(body && body.enabled);
|
|
787
|
-
if (body && body.click && body.click.sessionId)
|
|
799
|
+
if (body && body.click && body.click.sessionId) {
|
|
800
|
+
stopMacPoll();
|
|
801
|
+
openClickedSession(body.click.sessionId);
|
|
802
|
+
}
|
|
788
803
|
}).catch(function () {});
|
|
789
804
|
} catch (e) { p = null; }
|
|
790
805
|
if (!p || typeof p.then !== "function") { macProbeSettled = true; return null; }
|
|
@@ -793,6 +808,34 @@
|
|
|
793
808
|
flushDeferred();
|
|
794
809
|
});
|
|
795
810
|
}
|
|
811
|
+
/**
|
|
812
|
+
* Read the host's pending notification click without waiting for a focus
|
|
813
|
+
* event. A banner clicked while DSH is already frontmost never focuses the
|
|
814
|
+
* window, so the focus-only read in onPageFocus() cannot see it; the poll
|
|
815
|
+
* turns that click into a switch at most one second late.
|
|
816
|
+
*
|
|
817
|
+
* Only the focused page polls: when the window is not in front, clicking
|
|
818
|
+
* the toast activates it and the focus event already collects the click, so
|
|
819
|
+
* an unfocused poll would only add requests. Bounded so an ignored toast
|
|
820
|
+
* cannot keep a timer alive forever.
|
|
821
|
+
*/
|
|
822
|
+
function startMacPoll() {
|
|
823
|
+
if (!macNative.enabled || !pageFocused) return;
|
|
824
|
+
macPollTicks = 0;
|
|
825
|
+
if (macPoll) return;
|
|
826
|
+
try {
|
|
827
|
+
macPoll = setInterval(function () {
|
|
828
|
+
macPollTicks++;
|
|
829
|
+
if (!macNative.enabled || !pageFocused) { stopMacPoll(); return; }
|
|
830
|
+
try { probeMacNative(); } catch (e) {}
|
|
831
|
+
if (macPollTicks >= MAC_POLL_MAX_TICKS) stopMacPoll();
|
|
832
|
+
}, MAC_POLL_INTERVAL_MS);
|
|
833
|
+
} catch (e) { macPoll = null; }
|
|
834
|
+
}
|
|
835
|
+
function stopMacPoll() {
|
|
836
|
+
if (macPoll) { try { clearInterval(macPoll); } catch (e) {} macPoll = null; }
|
|
837
|
+
macPollTicks = 0;
|
|
838
|
+
}
|
|
796
839
|
function flushDeferred() {
|
|
797
840
|
if (!macDeferred.length) return;
|
|
798
841
|
var queued = macDeferred;
|
|
@@ -855,6 +898,9 @@
|
|
|
855
898
|
// Registered only on success: withdrawToasts()/closeNotificationTag()
|
|
856
899
|
// can now close a notification that really is on screen.
|
|
857
900
|
trackToast(tag, function () { removeMacToast(tag); });
|
|
901
|
+
// The toast is clickable now; from here on a click must be read even
|
|
902
|
+
// when the window never loses focus.
|
|
903
|
+
startMacPoll();
|
|
858
904
|
});
|
|
859
905
|
});
|
|
860
906
|
lastToastPending = p;
|
|
@@ -898,11 +944,24 @@
|
|
|
898
944
|
if (!action || typeof action !== "object") return;
|
|
899
945
|
if (action.action === "approve" && typeof action.key === "string") decidePending(action.key, "allowed-once");
|
|
900
946
|
else if (action.action === "reject" && typeof action.key === "string") decidePending(action.key, "rejected");
|
|
901
|
-
else if (action.action === "open"
|
|
947
|
+
else if (action.action === "open") {
|
|
948
|
+
// Clicking the toast body is a request to come back to DSH. The helper's
|
|
949
|
+
// dsh://open launch cannot raise a minimized or tray-hidden window on
|
|
950
|
+
// Windows, so the host route is the only path that works; raise first,
|
|
951
|
+
// then switch to the session the click carried (if any). Without this,
|
|
952
|
+
// a native-toast click only switched the session and left the window
|
|
953
|
+
// where it was (issue #40).
|
|
954
|
+
raiseWindow();
|
|
955
|
+
if (typeof action.sessionId === "string" && action.sessionId) openClickedSession(action.sessionId);
|
|
956
|
+
}
|
|
902
957
|
}
|
|
903
958
|
// Button clicks always land through the protocol handler, which also opens
|
|
904
959
|
// dsh://open. Polling the host while the wait is open is the only way the
|
|
905
960
|
// decision reaches the page even when the window was already focused.
|
|
961
|
+
function stopWinPoll() {
|
|
962
|
+
if (winNative.poll) { try { clearInterval(winNative.poll); } catch (e) {} winNative.poll = null; }
|
|
963
|
+
winNative.pollKey = null;
|
|
964
|
+
}
|
|
906
965
|
function startWinPoll(key) {
|
|
907
966
|
winNative.pollKey = typeof key === "string" && key ? key : winNative.pollKey;
|
|
908
967
|
if (winNative.poll) return;
|
|
@@ -911,11 +970,7 @@
|
|
|
911
970
|
ticks++;
|
|
912
971
|
probeWinNative();
|
|
913
972
|
var waiting = winNative.pollKey ? !!pendingActions[winNative.pollKey] : true;
|
|
914
|
-
if (!waiting || ticks > 120)
|
|
915
|
-
clearInterval(winNative.poll);
|
|
916
|
-
winNative.poll = null;
|
|
917
|
-
winNative.pollKey = null;
|
|
918
|
-
}
|
|
973
|
+
if (!waiting || ticks > 120) stopWinPoll();
|
|
919
974
|
}, 1500);
|
|
920
975
|
}
|
|
921
976
|
function showWinToast(kind, title, body, sessionId, quick, tag) {
|
|
@@ -3300,7 +3355,7 @@
|
|
|
3300
3355
|
});
|
|
3301
3356
|
} catch (e) {}
|
|
3302
3357
|
// keep in sync with package.json "version" on every release
|
|
3303
|
-
api.version = "1.
|
|
3358
|
+
api.version = "1.21.0";
|
|
3304
3359
|
api.setConfig = function (patch) { return setConfigLocal(patch); };
|
|
3305
3360
|
api.resetConfig = function () {
|
|
3306
3361
|
try {
|
|
@@ -5202,6 +5257,10 @@
|
|
|
5202
5257
|
});
|
|
5203
5258
|
probeMacNative();
|
|
5204
5259
|
probeWinNative();
|
|
5260
|
+
// A poll started for an outstanding native toast must not outlive
|
|
5261
|
+
// the plugin instance that owns it.
|
|
5262
|
+
unsubs.push(stopMacPoll);
|
|
5263
|
+
unsubs.push(stopWinPoll);
|
|
5205
5264
|
// Same re-arm for the other half of "went away": losing window focus.
|
|
5206
5265
|
try { window.addEventListener("focus", onPageFocus); } catch (e) {}
|
|
5207
5266
|
try { window.addEventListener("blur", onPageBlur); } catch (e) {}
|
package/lib/focus-window.ps1
CHANGED
|
@@ -216,7 +216,6 @@ public class FocusNative
|
|
|
216
216
|
|
|
217
217
|
$candidates = @()
|
|
218
218
|
foreach ($w in $allWindows) {
|
|
219
|
-
if (-not $w.Visible) { continue }
|
|
220
219
|
if ($w.HasOwner) { continue }
|
|
221
220
|
if ($w.ToolWindow) { continue }
|
|
222
221
|
$titleMatch = ($w.Title -like '*DeepSeek*')
|
|
@@ -231,6 +230,11 @@ public class FocusNative
|
|
|
231
230
|
if ([int]$w.Pid -ne $ProcessId) { continue }
|
|
232
231
|
$isProcMatch = $true
|
|
233
232
|
}
|
|
233
|
+
# A window hidden with SW_HIDE (the tray toggle) is still the window the
|
|
234
|
+
# user wants back. Keep it only when it belongs to the DSH process, so a
|
|
235
|
+
# hidden window that merely mentions DeepSeek in its title is not shown
|
|
236
|
+
# to the user (issue #40).
|
|
237
|
+
if (-not $w.Visible -and -not $isProcMatch) { continue }
|
|
234
238
|
$isClassTarget = ($w.ClassName -eq [FocusNative]::TARGET_CLASS)
|
|
235
239
|
$candidates += [pscustomobject]@{
|
|
236
240
|
Hwnd = $w.Hwnd
|
|
@@ -239,6 +243,7 @@ public class FocusNative
|
|
|
239
243
|
Title = $w.Title
|
|
240
244
|
Area = [long]$w.Area
|
|
241
245
|
Iconic = [bool]$w.Iconic
|
|
246
|
+
Visible = [bool]$w.Visible
|
|
242
247
|
IsClassTarget = [bool]$isClassTarget
|
|
243
248
|
IsProcMatch = [bool]$isProcMatch
|
|
244
249
|
}
|
|
@@ -250,6 +255,7 @@ public class FocusNative
|
|
|
250
255
|
} else {
|
|
251
256
|
$sortSpec = @(
|
|
252
257
|
@{ Expression = { [int]$_.IsProcMatch }; Descending = $true }
|
|
258
|
+
@{ Expression = { [int]$_.Visible }; Descending = $true }
|
|
253
259
|
@{ Expression = { [int]$_.IsClassTarget }; Descending = $true }
|
|
254
260
|
@{ Expression = { [long]$_.Area }; Descending = $true }
|
|
255
261
|
)
|
|
@@ -257,18 +263,24 @@ public class FocusNative
|
|
|
257
263
|
$idx = 0
|
|
258
264
|
foreach ($c in $ranked) {
|
|
259
265
|
$idx++
|
|
260
|
-
Out-Line ("DETAIL: candidate #{0} hwnd=0x{1:X} pid={2} class={3} area={4} iconic={5}
|
|
261
|
-
$idx, $c.Hwnd.ToInt64(), $c.Pid, $c.ClassName, $c.Area, $c.Iconic, $c.IsProcMatch, (Short-Text $c.Title 70))
|
|
266
|
+
Out-Line ("DETAIL: candidate #{0} hwnd=0x{1:X} pid={2} class={3} area={4} iconic={5} visible={6} procMatch={7} title={8}" -f `
|
|
267
|
+
$idx, $c.Hwnd.ToInt64(), $c.Pid, $c.ClassName, $c.Area, $c.Iconic, $c.Visible, $c.IsProcMatch, (Short-Text $c.Title 70))
|
|
262
268
|
}
|
|
263
269
|
|
|
264
270
|
$chosen = $ranked[0]
|
|
265
271
|
$reason = 'largest area among the remaining candidates'
|
|
266
272
|
if ($chosen.IsClassTarget) { $reason = 'preferred class Chrome_WidgetWin_1, largest area among those' }
|
|
267
273
|
if (-not $chosen.IsProcMatch) { $reason = 'title match only (no process-name match), largest area among those' }
|
|
268
|
-
|
|
269
|
-
|
|
274
|
+
if (-not $chosen.Visible) { $reason = 'tray-hidden DSH window, ' + $reason }
|
|
275
|
+
Out-Line ("DETAIL: selected hwnd=0x{0:X} pid={1} class={2} area={3} visible={4} ({5})" -f `
|
|
276
|
+
$chosen.Hwnd.ToInt64(), $chosen.Pid, $chosen.ClassName, $chosen.Area, $chosen.Visible, $reason)
|
|
270
277
|
|
|
271
278
|
$hwnd = [IntPtr]$chosen.Hwnd
|
|
279
|
+
if (-not $chosen.Visible) {
|
|
280
|
+
Out-Line 'DETAIL: step 0: window is tray-hidden, ShowWindow(SW_SHOW)'
|
|
281
|
+
[void][FocusNative]::ShowWindow($hwnd, [FocusNative]::SW_SHOW)
|
|
282
|
+
Start-Sleep -Milliseconds 50
|
|
283
|
+
}
|
|
272
284
|
$fg0 = [FocusNative]::GetForegroundWindow()
|
|
273
285
|
$iconic0 = [FocusNative]::IsIconic($hwnd)
|
|
274
286
|
Out-Line ("DETAIL: initial foreground=0x{0:X} iconic={1}" -f $fg0.ToInt64(), $iconic0)
|
package/lib/win-toast.js
CHANGED
|
@@ -57,10 +57,26 @@ function wscriptPath() {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
* The protocol handler: record the clicked URL, then raise DSH.
|
|
61
|
-
*
|
|
62
|
-
*
|
|
60
|
+
* The protocol handler: record the clicked URL, then raise DSH.
|
|
61
|
+
*
|
|
62
|
+
* The script stays pure ASCII: the actions directory is resolved from
|
|
63
|
+
* %LOCALAPPDATA% when the click happens rather than baked into the file. A
|
|
64
|
+
* profile path like C:\Users\<中文名>\... written as UTF-8 without a BOM is
|
|
65
|
+
* decoded by WSH with the system ANSI code page, which ate the backslash after
|
|
66
|
+
* the user name and made FolderExists fail with 800A004C (issue #36). Even so
|
|
67
|
+
* the file is written as UTF-16LE with a BOM: any non-ASCII that ever reaches
|
|
68
|
+
* it would then decode correctly.
|
|
63
69
|
*/
|
|
70
|
+
function actionsDirExpression(actionsDir) {
|
|
71
|
+
const defaultDir = process.env.LOCALAPPDATA
|
|
72
|
+
? join(process.env.LOCALAPPDATA, "dsh-notify-me", "actions")
|
|
73
|
+
: "";
|
|
74
|
+
if (defaultDir && actionsDir.toLowerCase() === defaultDir.toLowerCase()) {
|
|
75
|
+
return 'sh.ExpandEnvironmentStrings("%LOCALAPPDATA%") & "\\dsh-notify-me\\actions"';
|
|
76
|
+
}
|
|
77
|
+
return '"' + actionsDir + '"';
|
|
78
|
+
}
|
|
79
|
+
|
|
64
80
|
function handlerVbs(actionsDir) {
|
|
65
81
|
return [
|
|
66
82
|
"' Generated by dsh-notify-me. Records a toast action click and raises DSH.",
|
|
@@ -69,7 +85,7 @@ function handlerVbs(actionsDir) {
|
|
|
69
85
|
'Set fso = CreateObject("Scripting.FileSystemObject")',
|
|
70
86
|
'Set sh = CreateObject("WScript.Shell")',
|
|
71
87
|
"url = WScript.Arguments(0)",
|
|
72
|
-
|
|
88
|
+
"dir = " + actionsDirExpression(actionsDir),
|
|
73
89
|
"If Not fso.FolderExists(dir) Then fso.CreateFolder(dir)",
|
|
74
90
|
"name = fso.GetTempName()",
|
|
75
91
|
"Set out = fso.CreateTextFile(dir & \"\\\" & name, True)",
|
|
@@ -80,6 +96,12 @@ function handlerVbs(actionsDir) {
|
|
|
80
96
|
].join("\r\n");
|
|
81
97
|
}
|
|
82
98
|
|
|
99
|
+
/** UTF-16LE with a BOM: WSH must not decode the handler with the ANSI code page. */
|
|
100
|
+
function writeHandlerScript(vbsPath, actionsDir) {
|
|
101
|
+
const body = Buffer.from(handlerVbs(actionsDir), "utf16le");
|
|
102
|
+
writeFileSync(vbsPath, Buffer.concat([Buffer.from([0xff, 0xfe]), body]));
|
|
103
|
+
}
|
|
104
|
+
|
|
83
105
|
/**
|
|
84
106
|
* Register the route — only on the packed Windows desktop shell.
|
|
85
107
|
* @param webCtx - cordis context holding `webServer`.
|
|
@@ -155,7 +177,7 @@ export function mountWinToast(webCtx, config, shared, logger, deps = {}) {
|
|
|
155
177
|
protocolReady = (async () => {
|
|
156
178
|
try {
|
|
157
179
|
mkdirSync(actionsDir, { recursive: true });
|
|
158
|
-
|
|
180
|
+
writeHandlerScript(vbsPath, actionsDir);
|
|
159
181
|
} catch (e) {
|
|
160
182
|
return false;
|
|
161
183
|
}
|
|
@@ -199,8 +221,11 @@ export function mountWinToast(webCtx, config, shared, logger, deps = {}) {
|
|
|
199
221
|
if (url.protocol !== PROTOCOL + ":") return null;
|
|
200
222
|
const action = (url.hostname || "").toLowerCase();
|
|
201
223
|
if (action === "open") {
|
|
202
|
-
|
|
203
|
-
|
|
224
|
+
// A body click without a session still means "raise the window"; keep the
|
|
225
|
+
// action so the page can run the host-route raise with nothing to open.
|
|
226
|
+
// It used to be dropped here, and a no-session toast fell back to the
|
|
227
|
+
// dsh://open launch that never raised anything (issue #40).
|
|
228
|
+
return { action: "open", sessionId: str(url.searchParams.get("session"), 200) };
|
|
204
229
|
}
|
|
205
230
|
if (action !== "approve" && action !== "reject") return null;
|
|
206
231
|
const rec = tokens[str(url.searchParams.get("token"), 200)];
|
package/lib/win-toast.ps1
CHANGED
|
@@ -45,12 +45,15 @@ if ($payload.approveToken) {
|
|
|
45
45
|
$actions = '<actions><action content="' + (XmlEscape $payload.approveText) + '" activationType="protocol" arguments="' + $approveArgs + '"/><action content="' + (XmlEscape $payload.rejectText) + '" activationType="protocol" arguments="' + $rejectArgs + '"/></actions>'
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
# Body click:
|
|
49
|
-
#
|
|
48
|
+
# Body click: always go through our own protocol handler. The host records the
|
|
49
|
+
# click for the page, which raises the window through the host route (the only
|
|
50
|
+
# way that works on Windows) and switches to the session when there is one.
|
|
51
|
+
# dsh://open used to be the launch target with no session; it never raised a
|
|
52
|
+
# minimized or tray-hidden window (issue #40).
|
|
50
53
|
if ($payload.session) {
|
|
51
54
|
$launch = ' launch="dsh-notify-me://open?session=' + [Uri]::EscapeDataString($payload.session) + '" activationType="protocol"'
|
|
52
55
|
} else {
|
|
53
|
-
$launch = ' launch="dsh://open" activationType="protocol"'
|
|
56
|
+
$launch = ' launch="dsh-notify-me://open" activationType="protocol"'
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
$audio = ""
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-notify-me",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"description": "离开 DSH 页面也能收到提醒:需要你操作 / 后台回复完成时发系统通知、标题标记与提示音,支持审批快捷裁决与外部推送,Web 版与桌面版均可用。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -115,7 +115,8 @@
|
|
|
115
115
|
"0.2.1-rc.4": "compatible",
|
|
116
116
|
"0.2.1-rc.5": "compatible",
|
|
117
117
|
"0.2.2-alpha.2": "compatible",
|
|
118
|
-
"0.2.2-rc.1": "compatible"
|
|
118
|
+
"0.2.2-rc.1": "compatible",
|
|
119
|
+
"0.2.2-rc.2": "compatible"
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
},
|
package/smoke/win-toast-test.mjs
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// PowerShell helper cannot reasonably run in CI, so spawn/exec are injected:
|
|
6
6
|
// what is pinned here is the route contract (405/403/501/400, GET actions,
|
|
7
7
|
// POST send/remove), the decoded toast payload, the HKCU protocol registration,
|
|
8
|
-
// and the token rules — single use,
|
|
8
|
+
// the encoding of the generated VBS handler, and the token rules — single use,
|
|
9
|
+
// bound to one approval key, expiring.
|
|
9
10
|
import fs from 'node:fs';
|
|
10
11
|
import os from 'node:os';
|
|
11
12
|
import path from 'node:path';
|
|
@@ -18,13 +19,23 @@ function assert(cond, msg) { if (!cond) throw new Error('ASSERT FAILED: ' + msg)
|
|
|
18
19
|
|
|
19
20
|
const win = await import(pathToFileURL(path.join(ROOT, 'lib', 'win-toast.js')).href);
|
|
20
21
|
assert(win.WIN_TOAST_ROUTE === '/__dsh-notify-me/win-toast', 'WIN_TOAST_ROUTE is the path the page calls');
|
|
22
|
+
// The toast body click must always come back through our protocol handler: the
|
|
23
|
+
// helper's dsh://open launch is dead on Windows, and the page's host-route raise
|
|
24
|
+
// is what brings a minimized or tray-hidden window back (issue #40).
|
|
25
|
+
const toastPs1 = fs.readFileSync(path.join(ROOT, 'lib', 'win-toast.ps1'), 'utf8');
|
|
26
|
+
assert(!toastPs1.includes('launch="dsh://open"'), 'the toast body never launches dsh://open');
|
|
27
|
+
assert(toastPs1.includes('launch="dsh-notify-me://open"'), 'the toast body launches our own protocol');
|
|
21
28
|
|
|
22
29
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-notify-me-win-'));
|
|
30
|
+
// mountWinToast derives its directories from %LOCALAPPDATA% on Windows; point
|
|
31
|
+
// that at the scratch dir so the test never touches the real profile directory.
|
|
32
|
+
const realLocalAppData = process.env.LOCALAPPDATA;
|
|
33
|
+
process.env.LOCALAPPDATA = tmp;
|
|
23
34
|
const psPath = path.join(tmp, 'powershell.exe');
|
|
24
35
|
const scriptPath = path.join(tmp, 'win-toast.ps1');
|
|
25
36
|
fs.writeFileSync(psPath, '');
|
|
26
37
|
fs.writeFileSync(scriptPath, '');
|
|
27
|
-
const actionsDir = path.join(tmp, 'actions');
|
|
38
|
+
const actionsDir = path.join(tmp, 'dsh-notify-me', 'actions');
|
|
28
39
|
|
|
29
40
|
const spawned = [];
|
|
30
41
|
const execCalls = [];
|
|
@@ -61,7 +72,6 @@ function mount(config = {}, deps = {}) {
|
|
|
61
72
|
win.mountWinToast(ctx, config, { bindHost: undefined, allowedOrigins: [] }, undefined, {
|
|
62
73
|
spawn: fakeSpawn,
|
|
63
74
|
execFile: fakeExec,
|
|
64
|
-
dir: tmp,
|
|
65
75
|
psPath: psPath,
|
|
66
76
|
scriptPath: scriptPath,
|
|
67
77
|
aumid: 'test.aumid',
|
|
@@ -153,9 +163,15 @@ try {
|
|
|
153
163
|
assert(execCalls.length === 3, 'first approval registers the protocol with three reg.exe calls');
|
|
154
164
|
assert(execCalls[0].file === 'reg' && execCalls[0].args.join(' ').includes('HKCU\\Software\\Classes\\dsh-notify-me'),
|
|
155
165
|
'the protocol is registered under HKCU\\Software\\Classes');
|
|
156
|
-
const handlerVbs = path.join(tmp, 'notify-handler.vbs');
|
|
166
|
+
const handlerVbs = path.join(tmp, 'dsh-notify-me', 'notify-handler.vbs');
|
|
157
167
|
assert(fs.existsSync(handlerVbs), 'the protocol handler script is written');
|
|
158
|
-
|
|
168
|
+
const vbsBytes = fs.readFileSync(handlerVbs);
|
|
169
|
+
assert(vbsBytes[0] === 0xff && vbsBytes[1] === 0xfe, 'the handler script carries a UTF-16LE BOM');
|
|
170
|
+
const vbsText = vbsBytes.subarray(2).toString('utf16le');
|
|
171
|
+
assert(/^[\x00-\x7f]*$/.test(vbsText), 'the handler script is pure ASCII, so a non-ASCII profile path cannot be garbled');
|
|
172
|
+
assert(vbsText.includes('sh.ExpandEnvironmentStrings("%LOCALAPPDATA%") & "\\dsh-notify-me\\actions"'),
|
|
173
|
+
'the actions directory is resolved from %LOCALAPPDATA% at click time');
|
|
174
|
+
assert(!vbsText.includes(tmp), 'no profile path is baked into the handler script');
|
|
159
175
|
|
|
160
176
|
// 3b. Approve click: single use, bound to the approval key.
|
|
161
177
|
writeAction('a1.txt', 'dsh-notify-me://approve?token=' + sentBody.token);
|
|
@@ -177,6 +193,14 @@ try {
|
|
|
177
193
|
const opened = JSON.parse((await call(handler, 'GET')).body);
|
|
178
194
|
assert(opened.actions.length === 1 && opened.actions[0].action === 'open' && opened.actions[0].sessionId === 'sess-9',
|
|
179
195
|
'a body click delivers an open action with its session');
|
|
196
|
+
// A body click without a session is still a raise request; the page must see
|
|
197
|
+
// it (issue #40: it used to be dropped here and only dsh://open tried to wake
|
|
198
|
+
// the window, which never worked).
|
|
199
|
+
writeAction('a4b.txt', 'dsh-notify-me://open');
|
|
200
|
+
const openedNoSession = JSON.parse((await call(handler, 'GET')).body);
|
|
201
|
+
assert(openedNoSession.actions.length === 1 && openedNoSession.actions[0].action === 'open'
|
|
202
|
+
&& openedNoSession.actions[0].sessionId === '',
|
|
203
|
+
'a no-session body click keeps an open action with no session');
|
|
180
204
|
|
|
181
205
|
// 3e. Expiry: a token older than the TTL never becomes a decision.
|
|
182
206
|
let clock = 1000;
|
|
@@ -194,6 +218,8 @@ try {
|
|
|
194
218
|
assert(spawned.length === 1 && spawned[0].args.includes('-RemoveTag') && spawned[0].args.includes(sentBody.id),
|
|
195
219
|
'the remove spawns -RemoveTag for the history tag');
|
|
196
220
|
} finally {
|
|
221
|
+
if (realLocalAppData === undefined) delete process.env.LOCALAPPDATA;
|
|
222
|
+
else process.env.LOCALAPPDATA = realLocalAppData;
|
|
197
223
|
Object.defineProperty(process, 'platform', realPlatform);
|
|
198
224
|
if (realElectron === undefined) delete process.versions.electron;
|
|
199
225
|
else Object.defineProperty(process.versions, 'electron', { value: realElectron, configurable: true, writable: true });
|