dsh-notify-me 1.21.1 → 1.21.2

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 CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  All notable changes to **dsh-notify-me** are documented here.
4
4
 
5
+ ## [1.21.2] — 2026-11-16
6
+
7
+ Windows 原生审批通知的「同意 / 拒绝」按钮现在真会把决定送回页面,而不是只把通知收掉。
8
+
9
+ ### 修复
10
+
11
+ - **Windows 审批 Toast 的按钮点了只 dismiss、没有决定**([#41](https://github.com/chromoany/dsh-notify-me/issues/41)):Toast 原来借用 DSH 桌面壳的 AUMID(`electron.app.DeepSeek Harness`),而这个 AUMID 在注册表里挂着一个 COM Toast 激活器(`HKCU\Software\Classes\CLSID\{…}\LocalServer32` 指向 DSH 主程序)。Windows 对这种 AUMID 一律把激活交给那个 COM 服务——正文点击和按钮都一样——Toast XML 里的 `activationType="protocol"` 根本不参与派发;DSH 那一侧没有对应的 Notification 对象,按 Electron 自己的处理([electron/electron#51330](https://github.com/electron/electron/pull/51330))把动作参数丢掉。于是协议处理器一次都没跑过:通知被 dismiss,动作目录里没有文件,`approval/decided` 也不会出现。现在 Toast 改发到插件自己的 AUMID `dsh-notify-me`:首次发送前写 `HKCU\Software\Classes\AppUserModelId\dsh-notify-me`(`DisplayName` 是通知抬头,`CustomActivator` 指一个 CLSID),CLSID 只建一个空的存根、不注册 `LocalServer32`——微软文档里「不实现 COM 激活器」的替代路线,代价是 Toast 上的输入框与 in-process 激活不可用,这两样本插件都没用。当前用户级注册,不需要管理员权限;旧版借 DSH AUMID 发出去的 Toast 留在操作中心没有影响,token 本来就是单次且 3 分钟过期。真机验证(Windows 11 26200 / DSH 0.2.2-rc.3):按本改动注册自有 AUMID 与空存根后,用真实的 `lib/win-toast.ps1` 发一条审批通知,点「同意」,协议处理器收到的就是 `dsh-notify-me://approve/?token=<那条通知的 approveToken>`(Windows 会在无路径的 URI 里补一个 `/`,解析已按这个形式处理);正文点击同样会派发。
12
+ - **在页面里答复后原生 Toast 仍留在操作中心**:`decidePending()` 原来只关 Service Worker 那条通知,不管原生 Toast,于是操作中心里会留一条按钮已失效(token 已被消费)的通知。现在不是从 Toast 上点下来的答复,会按 tag 把原生 Toast 一起撤回。
13
+
14
+ ### 测试
15
+
16
+ - `smoke/win-toast-test.mjs`:HKCU 注册命令从 3 条扩到 6 条(协议 3 条 + AUMID 的 `DisplayName` / `CustomActivator` + 空 CLSID 存根),断言默认 AUMID 是插件自己的、不是 DSH 的,且不带按钮的 Toast 也会先注册身份;另加一条归一化用例——Windows 会把无路径的 URI 改写成 `dsh-notify-me://approve/?token=…` 再交给处理器,这个形式同样要解析成决定。
17
+
5
18
  ## [1.21.1] — 2026-11-16
6
19
 
7
20
  宿主 HTTP 路由补齐 DSH 的访问准入:浏览器里打开的网页不能再借着对本机回环的访问直接调用插件的路由。
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
@@ -420,11 +420,11 @@ Like the window-raise route, this one registers exactly one exact path and refus
420
420
 
421
421
  The page's own `new Notification()` is not refused on Windows Desktop, but it cannot carry buttons: Electron's renderer hands the platform only title / body / tag / icon / silent and drops the `actions` array entirely (`DisplayNotification()` in `shell/browser/notifications/platform_notification_service.cc`); and a `dsh-app://` page cannot register a Service Worker, while only a Service Worker can draw button notifications. The plugin therefore posts approval alerts through the host as native toasts.
422
422
 
423
- - **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.
424
- - **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
+ - **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 plugin's own AUMID, `dsh-notify-me`, so it follows the same system notification settings. **Do not borrow DSH's AUMID**: that one has a COM toast activator registered, and Windows hands every click to DSH itself, so the protocol buttons on the toast are never dispatched ([#41](https://github.com/chromoany/dsh-notify-me/issues/41), fixed in 1.21.2).
424
+ - **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. The chain needs the toast to carry its own AUMID; under another app's AUMID its activator swallows the click.
425
425
  - **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)).
426
426
  - **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.
427
- - **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.
427
+ - **Registration**: before the first toast, `HKCU\Software\Classes\AppUserModelId\dsh-notify-me` is written (`DisplayName` for the toast header, `CustomActivator` pointing at a CLSID) and that CLSID is created as an empty stub with no `LocalServer32` — an unpackaged app without a COM activator is what makes Windows dispatch the `activationType="protocol"` clicks from the XML. The toast is then booked into `ToastNotificationManager.History` by tag. Both are current-user and need no admin rights. Tokens are single-use and valid for 3 minutes; an action file is deleted once taken.
428
428
  - **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.
429
429
  - **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.
430
430
  - **Auto-dismiss and withdrawal**: native toasts are tracked by `trackToast()`: a plain toast closes after 5 s, a buttoned approval after 12 s ("always close" / "never close" still apply), and they are withdrawn when you come back to the page unless "keep alerts when you come back" is on.
package/README.md CHANGED
@@ -420,11 +420,11 @@ Windows 的激活顺序是实的:已经在前台就什么都不做(最常见
420
420
 
421
421
  页面里的 `new Notification()` 在 Windows 桌面端不会被拒,但它带不了按钮:Electron 的渲染进程收到通知请求后只把 title / body / tag / icon / silent 抄给平台,`actions` 数组整个丢掉(`shell/browser/notifications/platform_notification_service.cc` 的 `DisplayNotification()`);`dsh-app://` 页面又注册不了 Service Worker,而按钮通知只有 Service Worker 才画得出来。于是插件把审批提醒改由宿主发原生 Toast。
422
422
 
423
- - **谁去弹**:宿主半(`lib/index.js`)注册 `POST /__dsh-notify-me/win-toast`,由它起一次 `powershell.exe` 跑 `lib/win-toast.ps1`,用 WinRT `ToastNotificationManager` 把通知发到「DeepSeek Harness」这个 AUMID 下——与 DSH 自己的通知同级,走同一套系统通知设置。
424
- - **按钮怎么裁决**:Toast 的两个按钮是 `activationType="protocol"`,分别指向 `dsh-notify-me://approve?token=…` / reject。点按钮后系统调起注册在这个协议下的处理器(一个写入动作文件、再打开 `dsh://open` 的 VBS),宿主在页面下一次探针时把动作交回页面;页面仍走审批面板里同一个 `decidePending()`——「同意」就是「允许一次」,不多放行任何东西。
423
+ - **谁去弹**:宿主半(`lib/index.js`)注册 `POST /__dsh-notify-me/win-toast`,由它起一次 `powershell.exe` 跑 `lib/win-toast.ps1`,用 WinRT `ToastNotificationManager` 把通知发到插件自己的 AUMID `dsh-notify-me` 下,走同一套系统通知设置。**不能借 DSH 的 AUMID**:那个 AUMID 挂着 COM Toast 激活器,Windows 会把每次点击都交给 DSH 本体,Toast 上的协议按钮永远等不到派发([#41](https://github.com/chromoany/dsh-notify-me/issues/41),1.21.2 修)。
424
+ - **按钮怎么裁决**:Toast 的两个按钮是 `activationType="protocol"`,分别指向 `dsh-notify-me://approve?token=…` / reject。点按钮后系统调起注册在这个协议下的处理器(一个写入动作文件、再打开 `dsh://open` 的 VBS),宿主在页面下一次探针时把动作交回页面;页面仍走审批面板里同一个 `decidePending()`——「同意」就是「允许一次」,不多放行任何东西。这条链路要求 Toast 挂在自己的 AUMID 下,否则点击会被别的应用的激活器截走。
425
425
  - **点正文也会抬窗**:正文点击统一走 `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))。
426
426
  - **中文用户名等非 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 时会重写这份脚本,不用手动清旧文件。
427
- - **注册**:第一次发带按钮的 Toast 时在 `HKCU\Software\Classes\dsh-notify-me` 注册上面那个处理器(当前用户级,不需要管理员权限),并按 tag 记账到 `ToastNotificationManager.History`。token 单次、3 分钟有效;动作文件被取走后即删。
427
+ - **注册**:第一次发 Toast 前写 `HKCU\Software\Classes\AppUserModelId\dsh-notify-me`(`DisplayName` = 通知抬头,`CustomActivator` = 一个 CLSID),CLSID 只建空的存根、不注册 `LocalServer32`——未打包应用不实现 COM 激活器时,Windows 才会按 XML 把 `activationType="protocol"` 的点击派发出去;随后按 tag 记账到 `ToastNotificationManager.History`。两者都是当前用户级,不需要管理员权限。token 单次、3 分钟有效;动作文件被取走后即删。
428
428
  - **不弹的场合**:非 Windows 桌面宿主、`winToast.enabled: false`、或 `powershell.exe` 不存在时,路由报 `enabled: false`(`501`),页面继续用自己那条不带按钮的通知,行为与改动前一致。
429
429
  - **关掉它**:在 profile 的 patch 层给 `notify-me` 加 `winToast: { enabled: false }`,审批提醒回到页面自己的通知(无按钮)。
430
430
  - **自动消失与收起**:原生 Toast 归 `trackToast()` 记账,普通通知 5 秒、带按钮的审批 12 秒(「总是关闭 / 从不关闭」照旧),回到页面(`keepOnReturn` 关闭时)同样收起。
package/lib/client.js CHANGED
@@ -910,9 +910,10 @@
910
910
  // Electron's renderer notification drops PlatformNotificationData::actions
911
911
  // before it reaches the Windows toast platform (issue #33), so an approval
912
912
  // alert can only carry 同意 / 拒绝 when the host half posts it through
913
- // WinRT. Its buttons activate the registered dsh-notify-me:// protocol; the
914
- // host collects the chosen action and this side applies it through
915
- // decidePending(), the same path a worker-button click takes.
913
+ // WinRT. The toast carries the plugin's own AUMID and its buttons activate
914
+ // the registered dsh-notify-me:// protocol; the host collects the chosen
915
+ // action and this side applies it through decidePending(), the same path a
916
+ // worker-button click takes.
916
917
  var WIN_TOAST_ROUTE = "/__dsh-notify-me/win-toast";
917
918
  var winNative = { enabled: false, last: null, poll: null, pollKey: null };
918
919
  function isWindowsDesktopPage() {
@@ -942,8 +943,8 @@
942
943
  }
943
944
  function applyWinAction(action) {
944
945
  if (!action || typeof action !== "object") return;
945
- if (action.action === "approve" && typeof action.key === "string") decidePending(action.key, "allowed-once");
946
- else if (action.action === "reject" && typeof action.key === "string") decidePending(action.key, "rejected");
946
+ if (action.action === "approve" && typeof action.key === "string") decidePending(action.key, "allowed-once", true);
947
+ else if (action.action === "reject" && typeof action.key === "string") decidePending(action.key, "rejected", true);
947
948
  else if (action.action === "open") {
948
949
  // Clicking the toast body is a request to come back to DSH. The helper's
949
950
  // dsh://open launch cannot raise a minimized or tray-hidden window on
@@ -1523,12 +1524,18 @@
1523
1524
  } catch (e) {}
1524
1525
  }
1525
1526
  // One toast button press. outcome: 'allowed-once' | 'rejected' — exactly
1526
- // the two decisions a manual answer in the conversation makes.
1527
- function decidePending(key, outcome) {
1527
+ // the two decisions a manual answer in the conversation makes. fromToast
1528
+ // marks the clicks Windows already took out of the Action Center itself;
1529
+ // any other answer has to withdraw the native toast too, or it sits there
1530
+ // with buttons whose token is spent.
1531
+ function decidePending(key, outcome, fromToast) {
1528
1532
  var rec = key ? pendingActions[key] : null;
1529
1533
  if (!rec) return false; // already answered elsewhere, or a stale toast
1530
1534
  delete pendingActions[key];
1531
- if (!rec.test) closeNotificationTag(rec.tag);
1535
+ if (!rec.test) {
1536
+ closeNotificationTag(rec.tag);
1537
+ if (!fromToast && isWindowsDesktopPage()) removeWinToast(rec.tag);
1538
+ }
1532
1539
  if (rec.test) {
1533
1540
  // Test toasts settle nothing real; the feedback toast IS the proof that
1534
1541
  // the button clicked all the way through the worker bridge.
@@ -3355,7 +3362,7 @@
3355
3362
  });
3356
3363
  } catch (e) {}
3357
3364
  // keep in sync with package.json "version" on every release
3358
- api.version = "1.21.1";
3365
+ api.version = "1.21.2";
3359
3366
  api.setConfig = function (patch) { return setConfigLocal(patch); };
3360
3367
  api.resetConfig = function () {
3361
3368
  try {
package/lib/win-toast.js CHANGED
@@ -14,9 +14,21 @@
14
14
  *
15
15
  * The route only exists on the packaged Windows desktop shell. Tokens are
16
16
  * single use, bound to one approval key and expire after three minutes. The
17
- * protocol handler is registered under HKCU\Software\Classes when the first
18
- * approval toast is posted; it survives app updates because it points at the
19
- * actions directory, not at a binary.
17
+ * protocol handler is registered under HKCU\Software\Classes before the first
18
+ * toast is posted; it survives app updates because it points at the actions
19
+ * directory, not at a binary.
20
+ *
21
+ * The toast carries its own AUMID. One posted under another app's AUMID is
22
+ * activated through that app: Windows looks the AUMID up under
23
+ * `HKCU\Software\Classes\AppUserModelId` and, when it names a CustomActivator,
24
+ * hands every activation — body click and buttons alike — to that COM server,
25
+ * so `activationType="protocol"` in the XML is never consulted. The DSH desktop
26
+ * shell registers such an activator for `electron.app.DeepSeek Harness`, which
27
+ * is why the approval buttons only dismissed the toast and the VBS handler
28
+ * never ran (issue #41). dsh-notify-me registers its own AUMID with a CLSID
29
+ * that has no LocalServer32: the documented "no COM activator" fallback, where
30
+ * protocol activation is still dispatched for unpackaged apps (at the cost of
31
+ * toast inputs and in-process activation, neither of which is used here).
20
32
  */
21
33
 
22
34
  import { spawn, execFile } from "node:child_process";
@@ -29,9 +41,14 @@ import { randomBytes } from "node:crypto";
29
41
  import { guardRequest, readBody, respond } from "./page-bridge.js";
30
42
 
31
43
  export const WIN_TOAST_ROUTE = "/__dsh-notify-me/win-toast";
44
+ // The app identity the toasts are posted under, and the stub COM activator it
45
+ // names. Exported so the smoke test can pin them: posting under the DSH shell's
46
+ // AUMID is what silently ate every button click (issue #41).
47
+ export const AUMID = "dsh-notify-me";
48
+ export const ACTIVATOR_CLSID = "{F0C6A9D2-4B7E-4D1A-9C53-8E2B6F7A0D41}";
49
+ const AUMID_DISPLAY_NAME = "DSH Notify Me";
32
50
  const HEADER = "x-dsh-notify-me-win";
33
51
  const HEADER_VALUE = "toast";
34
- const DEFAULT_AUMID = "electron.app.DeepSeek Harness";
35
52
  const PROTOCOL = "dsh-notify-me";
36
53
  const TOAST_GROUP = "dsh-notify-me";
37
54
  const ACTION_TTL_MS = 3 * 60 * 1000;
@@ -121,7 +138,7 @@ export function mountWinToast(webCtx, config, shared, logger, deps = {}) {
121
138
  const vbsPath = join(baseDir, "notify-handler.vbs");
122
139
  const psPath = typeof deps.psPath === "string" && deps.psPath ? deps.psPath : powershellPath();
123
140
  const scriptPath = typeof deps.scriptPath === "string" && deps.scriptPath ? deps.scriptPath : SCRIPT_PATH;
124
- const aumid = typeof deps.aumid === "string" && deps.aumid ? deps.aumid : DEFAULT_AUMID;
141
+ const aumid = typeof deps.aumid === "string" && deps.aumid ? deps.aumid : AUMID;
125
142
  const nowFn = typeof deps.now === "function" ? deps.now : function () { return Date.now(); };
126
143
  const available = config.enabled !== false && existsSync(psPath) && existsSync(scriptPath);
127
144
  if (config.enabled !== false && !available) {
@@ -130,7 +147,7 @@ export function mountWinToast(webCtx, config, shared, logger, deps = {}) {
130
147
 
131
148
  const tokens = Object.create(null);
132
149
  const ids = Object.create(null);
133
- let protocolReady = null;
150
+ let appReady = null;
134
151
  let seq = 0;
135
152
 
136
153
  function runPowerShell(extraArgs) {
@@ -172,9 +189,13 @@ export function mountWinToast(webCtx, config, shared, logger, deps = {}) {
172
189
  });
173
190
  }
174
191
 
175
- function registerProtocol() {
176
- if (protocolReady) return protocolReady;
177
- protocolReady = (async () => {
192
+ // Registers everything a protocol-activated toast needs from this side: the
193
+ // `dsh-notify-me://` handler, the app identity the toast is posted under, and
194
+ // the empty CLSID that identity names (see the module comment). Once per
195
+ // plugin instance, current-user rights only.
196
+ function registerToastApp() {
197
+ if (appReady) return appReady;
198
+ appReady = (async () => {
178
199
  try {
179
200
  mkdirSync(actionsDir, { recursive: true });
180
201
  writeHandlerScript(vbsPath, actionsDir);
@@ -182,10 +203,18 @@ export function mountWinToast(webCtx, config, shared, logger, deps = {}) {
182
203
  return false;
183
204
  }
184
205
  const command = '"' + wscriptPath() + '" "' + vbsPath + '" "%1"';
206
+ const appKey = "HKCU\\Software\\Classes\\AppUserModelId\\" + aumid;
185
207
  const commands = [
186
208
  ["add", "HKCU\\Software\\Classes\\" + PROTOCOL, "/ve", "/d", "URL:DSH Notify Me", "/f"],
187
209
  ["add", "HKCU\\Software\\Classes\\" + PROTOCOL, "/v", "URL Protocol", "/d", "", "/f"],
188
210
  ["add", "HKCU\\Software\\Classes\\" + PROTOCOL + "\\shell\\open\\command", "/ve", "/d", command, "/f"],
211
+ // Own AUMID: the name Windows shows on the toast, and the activator it
212
+ // points at. The CLSID is registered empty on purpose — with no
213
+ // LocalServer32 behind it Windows cannot hand an activation to a COM
214
+ // server, so the protocol in the XML is dispatched instead (#41).
215
+ ["add", appKey, "/v", "DisplayName", "/d", AUMID_DISPLAY_NAME, "/f"],
216
+ ["add", appKey, "/v", "CustomActivator", "/d", ACTIVATOR_CLSID, "/f"],
217
+ ["add", "HKCU\\Software\\Classes\\CLSID\\" + ACTIVATOR_CLSID, "/f"],
189
218
  ];
190
219
  for (let i = 0; i < commands.length; i++) {
191
220
  const args = commands[i];
@@ -196,7 +225,7 @@ export function mountWinToast(webCtx, config, shared, logger, deps = {}) {
196
225
  }
197
226
  return true;
198
227
  })();
199
- return protocolReady;
228
+ return appReady;
200
229
  }
201
230
 
202
231
  function makeToken(approvalKey, sessionId) {
@@ -308,10 +337,13 @@ export function mountWinToast(webCtx, config, shared, logger, deps = {}) {
308
337
  const historyTag = nextHistoryTag();
309
338
  if (pageTag) ids[pageTag] = historyTag;
310
339
  const approvalKey = str(note.approvalKey, 200);
340
+ // Before the toast is shown, not after: Windows has to know this AUMID
341
+ // when the activation comes back, and a body click needs the handler even
342
+ // when the toast has no buttons at all.
343
+ await registerToastApp();
311
344
  let approveToken = "";
312
345
  let rejectToken = "";
313
346
  if (approvalKey) {
314
- await registerProtocol();
315
347
  approveToken = makeToken(approvalKey, str(note.sessionId, 200));
316
348
  rejectToken = makeToken(approvalKey, str(note.sessionId, 200));
317
349
  }
package/lib/win-toast.ps1 CHANGED
@@ -4,9 +4,12 @@
4
4
  # powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File win-toast.ps1 \
5
5
  # -Base64 <base64 JSON payload> [-RemoveTag <history tag>]
6
6
  #
7
- # The toast itself needs no registration: the AUMID is the one the DSH desktop
8
- # shell already owns (it shows the update prompt). Approval buttons use
9
- # protocol activation, so the click leaves the app and comes back through the
7
+ # The toast is posted under dsh-notify-me's own AUMID: lib/win-toast.js
8
+ # registers it (a DisplayName plus a stub CustomActivator with no LocalServer32)
9
+ # before the first toast goes out. Borrowing the DSH shell's AUMID instead made
10
+ # Windows route every activation to DSH's COM activator, which silently dropped
11
+ # it — the buttons only dismissed the toast (issue #41). Approval buttons and
12
+ # the body both use protocol activation, so the click comes back through the
10
13
  # dsh-notify-me:// handler registered in HKCU (see lib/win-toast.js).
11
14
 
12
15
  param(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-notify-me",
3
- "version": "1.21.1",
3
+ "version": "1.21.2",
4
4
  "description": "离开 DSH 页面也能收到提醒:需要你操作 / 后台回复完成时发系统通知、标题标记与提示音,支持审批快捷裁决与外部推送,Web 版与桌面版均可用。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -4,8 +4,9 @@
4
4
  // that environment (a `win32` platform and an `electron` version string). The
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
- // POST send/remove), the decoded toast payload, the HKCU protocol registration,
8
- // the encoding of the generated VBS handler, and the token rules — single use,
7
+ // POST send/remove), the decoded toast payload, the HKCU registrations (the
8
+ // protocol handler, the plugin's own AUMID and its empty activator CLSID), the
9
+ // encoding of the generated VBS handler, and the token rules — single use,
9
10
  // bound to one approval key, expiring.
10
11
  import fs from 'node:fs';
11
12
  import os from 'node:os';
@@ -19,6 +20,13 @@ function assert(cond, msg) { if (!cond) throw new Error('ASSERT FAILED: ' + msg)
19
20
 
20
21
  const win = await import(pathToFileURL(path.join(ROOT, 'lib', 'win-toast.js')).href);
21
22
  assert(win.WIN_TOAST_ROUTE === '/__dsh-notify-me/win-toast', 'WIN_TOAST_ROUTE is the path the page calls');
23
+ // The toast must not borrow the DSH shell's AUMID: that AUMID has a COM toast
24
+ // activator registered, so Windows handed every activation to DSH and the
25
+ // protocol handler never ran — the buttons only dismissed the toast (issue #41).
26
+ assert(win.AUMID === 'dsh-notify-me', "the toast posts under the plugin's own AUMID");
27
+ assert(win.AUMID !== 'electron.app.DeepSeek Harness', 'never under the DSH shell AUMID');
28
+ assert(/^\{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}$/.test(win.ACTIVATOR_CLSID),
29
+ 'the activator stub is a full CLSID');
22
30
  // The toast body click must always come back through our protocol handler: the
23
31
  // helper's dsh://open launch is dead on Windows, and the page's host-route raise
24
32
  // is what brings a minimized or tray-hidden window back (issue #40).
@@ -160,9 +168,17 @@ try {
160
168
  assert(payload.approveText === '同意' && payload.rejectText === '拒绝', 'button labels reach the helper');
161
169
  assert(payload.sound === false, 'the sound flag is off unless the cue is system');
162
170
 
163
- assert(execCalls.length === 3, 'first approval registers the protocol with three reg.exe calls');
164
- assert(execCalls[0].file === 'reg' && execCalls[0].args.join(' ').includes('HKCU\\Software\\Classes\\dsh-notify-me'),
171
+ assert(execCalls.length === 6, 'the first toast registers the protocol, the AUMID and the activator stub');
172
+ const regs = execCalls.map((c) => c.args.join(' '));
173
+ assert(execCalls[0].file === 'reg' && regs[0].includes('HKCU\\Software\\Classes\\dsh-notify-me'),
165
174
  'the protocol is registered under HKCU\\Software\\Classes');
175
+ assert(regs[3].includes('HKCU\\Software\\Classes\\AppUserModelId\\test.aumid') && regs[3].includes('DisplayName'),
176
+ 'the toast AUMID gets the display name the notification header shows');
177
+ assert(regs[4].includes('\\test.aumid') && regs[4].includes('CustomActivator') && regs[4].includes(win.ACTIVATOR_CLSID),
178
+ 'the AUMID names the activator stub');
179
+ assert(regs[5] === 'add HKCU\\Software\\Classes\\CLSID\\' + win.ACTIVATOR_CLSID + ' /f',
180
+ 'the activator CLSID is created empty: with no LocalServer32 Windows dispatches the protocol (issue #41)');
181
+ assert(!regs.some((line) => line.includes('LocalServer32')), 'no COM server is installed');
166
182
  const handlerVbs = path.join(tmp, 'dsh-notify-me', 'notify-handler.vbs');
167
183
  assert(fs.existsSync(handlerVbs), 'the protocol handler script is written');
168
184
  const vbsBytes = fs.readFileSync(handlerVbs);
@@ -181,6 +197,15 @@ try {
181
197
  assert(JSON.parse((await call(handler, 'GET')).body).actions.length === 0, 'the action is delivered once');
182
198
  writeAction('a2.txt', 'dsh-notify-me://approve?token=' + sentBody.token);
183
199
  assert(JSON.parse((await call(handler, 'GET')).body).actions.length === 0, 'a used token is dead');
200
+ // Windows rewrites a protocol URI that has no path before handing it to the
201
+ // handler: dsh-notify-me://approve?token=… arrives as approve/?token=… (seen
202
+ // on Windows 11 26200 with a real toast click). The decision must survive it.
203
+ const rewritten = JSON.parse((await post(handler, { ...APPROVAL, tag: 'tag-4' })).body);
204
+ writeAction('a2b.txt', 'dsh-notify-me://approve/?token=' + rewritten.token);
205
+ const normalized = JSON.parse((await call(handler, 'GET')).body);
206
+ assert(normalized.actions.length === 1 && normalized.actions[0].action === 'approve'
207
+ && normalized.actions[0].key === 'approval:sess-1:1',
208
+ 'a shell-normalized action URL (slash before the query) still delivers the decision');
184
209
 
185
210
  // 3c. Reject click.
186
211
  const second = JSON.parse((await post(handler, { ...APPROVAL, tag: 'tag-2' })).body);
@@ -242,6 +267,16 @@ try {
242
267
  assert(removed.status === 200, 'a remove answers 200');
243
268
  assert(spawned.length === 1 && spawned[0].args.includes('-RemoveTag') && spawned[0].args.includes(sentBody.id),
244
269
  'the remove spawns -RemoveTag for the history tag');
270
+ // 3h. A toast without buttons registers the app identity first too: its body
271
+ // click comes back through the same protocol, and Windows only dispatches it
272
+ // for an AUMID that does not answer to a COM activator.
273
+ const plain = mount({}, { aumid: '' }); // '' falls back to the module default
274
+ const plainSent = JSON.parse((await post(plain[0].handler, { title: 'DSH waiting for input', body: 'session: bash', tag: 'q-1' })).body);
275
+ assert(plainSent.ok === true && plainSent.token === '', 'a toast without an approval key carries no token');
276
+ const plainRegs = execCalls.slice(-6).map((c) => c.args.join(' '));
277
+ assert(plainRegs.some((line) => line.includes('HKCU\\Software\\Classes\\AppUserModelId\\' + win.AUMID)),
278
+ 'without an injected AUMID the registration writes the plugin-owned one');
279
+ assert(!plainRegs.some((line) => line.includes('electron.app')), 'the DSH shell AUMID is never registered here');
245
280
  } finally {
246
281
  if (realLocalAppData === undefined) delete process.env.LOCALAPPDATA;
247
282
  else process.env.LOCALAPPDATA = realLocalAppData;
@@ -251,4 +286,4 @@ try {
251
286
  fs.rmSync(tmp, { recursive: true, force: true });
252
287
  }
253
288
 
254
- console.log('win toast route OK: desktop gate, 405/403/501/400, payload, HKCU protocol, tokens (single-use/TTL), remove');
289
+ console.log('win toast route OK: desktop gate, 405/403/501/400, payload, HKCU protocol + app identity, tokens (single-use/TTL), remove');