dsh-notify-me 1.14.2 → 1.14.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/LICENSE +21 -21
- package/README.en.md +16 -10
- package/README.md +16 -10
- package/cordis.patch.yml +7 -7
- package/lib/client.js +107 -36
- package/lib/index.js +11 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to **dsh-notify-me** are documented here.
|
|
4
4
|
|
|
5
|
+
## [1.14.4] — 2026-10-27
|
|
6
|
+
|
|
7
|
+
### 修复
|
|
8
|
+
|
|
9
|
+
- **非 Windows 桌面端点通知又能把窗口抬回前台了**:1.14.0 把抬窗整条换成宿主路由 + `lib/focus-window.ps1`,可这条路由只对 Windows 放行——宿主在非 `win32` 平台直接回 `501`,于是 Linux / macOS 上点通知只剩切会话,窗口留在后台(issue #21)。现在按平台分流:Windows 继续走宿主路由(深链在 `0.2.1-rc.2` 上复测 3/3 无效),其他桌面端恢复 1.5.2 到 1.13.0 的 `dsh://open` 隐藏 iframe——子框架导航绕过壳的顶层 `will-navigate`,交给系统协议注册,由壳的第二次启动处理 restore + show + focus。已在 Arch Linux + Electron 44.7(Plasma 6.8 / Wayland)上实测最小化与后台窗口都能抬回来;macOS 走同一条深链,未实测。
|
|
10
|
+
- **`debug().raiseChannel` 不再依赖第一次点击**:字段改成按平台直接算(Windows `host-route`、其他桌面端 `dsh-deeplink`、浏览器 `window-focus`),装完打开设置页就能看到这台机器会走哪条通道;`raiseLast` 照旧记录最近一次尝试(深链记 `deeplink`,抬没抬起来要肉眼确认,它说不了)。
|
|
11
|
+
- **「测试提醒」不再谎报已发送**:通知权限没给时,`showToast()` 在尝试之前就返回,设置页却照旧写「已发送测试提醒」;现在按钮直接报「通知权限还没给」。Service Worker 那条路径也一样——`showNotification()` 的拒收是异步的,旧代码同步读 `lastToastReject`,异步拒绝落地时页面早写过「已发送」了(issue #18 在唯一能带按钮的那条路径上的残余)。现在测试按钮等这个 promise 落定再报结果。
|
|
12
|
+
- **存储里的配置不是对象时不再让插件整个起不来**:`JSON.parse` 对 `null`、`"x"`、`7` 都照收,随后填默认值的 `in` 判断在非对象上抛错,整个客户端模块挂掉、页面一条提醒都没有。现在只认普通对象,其余一律回落默认值(`lib/client.js` 的 `readConfig()`)。
|
|
13
|
+
|
|
14
|
+
### 测试
|
|
15
|
+
|
|
16
|
+
- 冒烟在 `desktopRaiseChannel()` 里补上点击前的通道断言(Windows / macOS / Linux 三个 UA),以及 macOS 点通知只插一个 `dsh://open` 帧、不 POST 宿主路由的用例;Windows 的 `iframe` 断言文案改成「Windows 不发深链」。`npm test` 全绿(`cordis-host-test` 在本机无宿主,照旧跳过)。
|
|
17
|
+
- 新增 `corruptStoredConfig()`(`null` / 字符串 / 数字 / 数组四种坏配置都能启动到默认值)、`deniedPermissionFeedback()`(权限被拒时测试按钮报没权限,不再写「已发送」)、`swRefusalFeedback()`(Worker 异步拒收后反馈行是「系统拒收了这条通知」)。两处修复都做过「改回去就挂」的反向验证。
|
|
18
|
+
|
|
19
|
+
### 文档
|
|
20
|
+
|
|
21
|
+
- README 的抬窗章节改成按平台叙述,`501` 闸门的说明改成「非 Windows 宿主」,已知限制里补上非 Windows 深链的前提(系统注册 `x-scheme-handler/dsh`、壳处理第二次启动)。
|
|
22
|
+
- `lib/index.js` 顶部注释改成按平台表述:这条路由是 Windows 专用的,其他桌面端页面根本不发请求。
|
|
23
|
+
|
|
24
|
+
## [1.14.3] — 2026-10-26
|
|
25
|
+
|
|
26
|
+
### 修复
|
|
27
|
+
|
|
28
|
+
- **当前会话的通知正文改用真实会话标题**:以前关于「已经在屏幕上的那个会话」的通知,「回复完成」的正文、以及「需要你」的会话行,对当前会话第一行写死占位符「当前对话 / Current conversation」,而其他会话都带侧栏标题。现在当前会话也从同一条列表行取标题(新增 `sessionTitleOf()`,与侧栏同一个 `displayTitle`/`title`,宿主改名后下一条通知即生效);只有列表还没给出标题的新会话(或列表里暂时没有这一行)才回落到占位符。宿主 0.1.x 与 0.2.x 共用这条 adapter,两代都修复(issue #20)。
|
|
29
|
+
|
|
30
|
+
### 测试
|
|
31
|
+
|
|
32
|
+
- 冒烟新增 `currentSessionTitle()`:当前会话的「需要你」正文以会话标题开头、不含「当前对话」;「回复完成」正文等于标题;没有标题的会话仍回落「当前对话」。`modernHost()` 里当前会话「回复完成」的断言从占位符改为列表标题。`npm test` 全绿(冒烟 + cordis 真宿主两套)。
|
|
33
|
+
|
|
34
|
+
### 文档
|
|
35
|
+
|
|
36
|
+
- `docs/listing.md` 版本口径同步到 1.14.3。
|
|
37
|
+
|
|
5
38
|
## [1.14.2] — 2026-10-24
|
|
6
39
|
|
|
7
40
|
### 修复
|
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
|
@@ -80,7 +80,7 @@ Web users can also test the approval buttons, which then appear on the notificat
|
|
|
80
80
|
window.__dshNotifyMe.test("done") // "reply finished" sample
|
|
81
81
|
window.__dshNotifyMe.test("attention") // "needs you" sample
|
|
82
82
|
window.__dshNotifyMe.test("approval") // Approve / Reject when the bridge is available; a plain notification otherwise (which is what Desktop gets)
|
|
83
|
-
window.__dshNotifyMe.debug() // the bridge field reports the state
|
|
83
|
+
window.__dshNotifyMe.debug() // the bridge field reports the state ("active" = buttons work); a refused toast leaves its platform message in lastToastReject
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
If no test notification appears, check in this order: whether the notification permission was declined (click once on the page and choose **Allow**; or address-bar lock → Site settings → Notifications → Allow → reload), whether DSH was restarted after installing, and whether the browser's notifications are switched off in the OS settings.
|
|
@@ -103,6 +103,8 @@ dsh-notify-me decouples **supervision** from **sitting in front of the screen**:
|
|
|
103
103
|
|
|
104
104
|
**Reply finished** also covers background sessions. A finished but unread session keeps the `✅ Reply finished ·` title marker until opened. Title markers are independent of the alert policy.
|
|
105
105
|
|
|
106
|
+
The first line of the alert body is the session title: the conversation you have open is treated like any other, instead of falling back to "Current conversation"; the placeholder only appears for a brand-new session whose title the host has not published yet.
|
|
107
|
+
|
|
106
108
|
> **Background** subagent child sessions are **not** alerted about by default: DSH lists each of them as its own session, but they are steps inside the parent conversation's turn, so an alert for them is only noise. The subagent session you have open is not part of this and alerts as usual. Settings → "Ignore subagent sessions" turns the mute off.
|
|
107
109
|
|
|
108
110
|
## Configure it from DSH Settings
|
|
@@ -122,7 +124,7 @@ Open **Settings → Notify me**. The page lays out three blocks — how you get
|
|
|
122
124
|
- **When "reply finished" alerts** (default "background only"): background only / quiet for the open one / always — pick one;
|
|
123
125
|
- **Dismiss the toast automatically** (default "keep while away"): keep while away / always close / never close — pick one;
|
|
124
126
|
- **Ignore subagent sessions** (on by default): skips background subagent sessions, while the one you have open still alerts;
|
|
125
|
-
- **Click a toast to open that conversation** (on by default): switches to that conversation and brings the window forward — on
|
|
127
|
+
- **Click a toast to open that conversation** (on by default): switches to that conversation and brings the window forward — on Windows through the host route, on macOS / Linux through the `dsh://open` deep link — and with several tabs only one is raised.
|
|
126
128
|
|
|
127
129
|
<details>
|
|
128
130
|
<summary>Edge cases behind the switches</summary>
|
|
@@ -168,13 +170,13 @@ Off by default. Supports Discord Webhook / Bark / Gotify / Feishu group bots / S
|
|
|
168
170
|
|
|
169
171
|
#### Runtime & diagnostics
|
|
170
172
|
|
|
171
|
-
The last block inside Advanced. The page protocol is detected automatically to tell Web from Desktop (DSH Desktop, `dsh-app://`); override it by hand if detection is wrong — on
|
|
173
|
+
The last block inside Advanced. The page protocol is detected automatically to tell Web from Desktop (DSH Desktop, `dsh-app://`); override it by hand if detection is wrong — on Windows a toast click goes through the host route for native raising, on macOS / Linux through the `dsh://open` deep link (see [How the Desktop window gets raised](#how-the-desktop-window-gets-raised)), and it carries no quick-decision buttons, while Web uses `window.focus()` plus the Service Worker bridge. When the manual override disagrees with detection the page says so.
|
|
172
174
|
|
|
173
175
|
<details>
|
|
174
176
|
<summary>Alert language, Desktop window raising, and reset</summary>
|
|
175
177
|
|
|
176
178
|
- **Alert language**: follow the UI / Simplified Chinese / English — governs the alert copy and the `🔔 …` title marker;
|
|
177
|
-
- **Desktop window raising**:
|
|
179
|
+
- **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));
|
|
178
180
|
- **Reset settings**: restores every switch and sound setting to the factory defaults (external push targets and chosen custom audio files are kept).
|
|
179
181
|
|
|
180
182
|
</details>
|
|
@@ -265,7 +267,7 @@ window.__dshNotifyMe.testExternal() // explicit outbound test to v
|
|
|
265
267
|
|
|
266
268
|
## How it works
|
|
267
269
|
|
|
268
|
-
The reminder core watches session state and pending interactions; approval decisions happen in the page, and Desktop window raising goes through a host route plus native Win32 activation.
|
|
270
|
+
The reminder core watches session state and pending interactions; approval decisions happen in the page, and Desktop window raising goes through a host route plus native Win32 activation on Windows, and through the `dsh://open` deep link on macOS / Linux.
|
|
269
271
|
|
|
270
272
|
<details>
|
|
271
273
|
<summary>Event sources and graceful degradation</summary>
|
|
@@ -296,18 +298,18 @@ The "raise a window and switch its conversation" part of a body click is schedul
|
|
|
296
298
|
|
|
297
299
|
### How the Desktop window gets raised
|
|
298
300
|
|
|
299
|
-
DSH Desktop is a thin Electron shell and its page lives under `dsh-app://app`: DOM `window.focus()` only moves the browsing-context window and never touches the native one, and the shell's `will-navigate` closes the usual page-side exit of firing a `dsh:` URL. The
|
|
301
|
+
DSH Desktop is a thin Electron shell and its page lives under `dsh-app://app`: DOM `window.focus()` only moves the browsing-context window and never touches the native one, and the shell's `will-navigate` closes the usual page-side exit of firing a `dsh:` URL. The plugin therefore takes two channels by platform: on Windows it uses its own host route — the page POSTs `/__dsh-notify-me/focus-window`, the host spawns `powershell.exe` to run `lib/focus-window.ps1`, which enumerates native windows and activates one adaptively; on macOS / Linux it uses the shell's own `dsh://open` deep link — the page navigates a hidden iframe to `dsh://open` inside the click gesture (subframe navigation bypasses the shell's top-level `will-navigate` interception), which reaches the system protocol registration, and the shell's `second-instance` / `open-url` handler restores, shows, and focuses the main window. On Windows that deep link retested 3/3 ineffective on `0.2.1-rc.2`, so 1.14.0 moved Windows to the host route; on Linux (Plasma 6.8 / Wayland) it is measured to raise a minimized or background window back to the front, and macOS is untested.
|
|
300
302
|
|
|
301
303
|
<details>
|
|
302
304
|
<summary>The route, the raise order, the measurements, and the security gate</summary>
|
|
303
305
|
|
|
304
|
-
|
|
306
|
+
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 visible, owner-less, non-toolwindow top-level windows (preferring class `Chrome_WidgetWin_1`, then the largest area from `GetWindowRect`) → activates adaptively → compares `GetForegroundWindow()` and prints `FOCUSED=1|0` → the host answers `200` / `202`.
|
|
305
307
|
|
|
306
|
-
|
|
308
|
+
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.
|
|
307
309
|
|
|
308
310
|
Measured with `powershell.exe` 5.1 in one round: window in front ×3, minimized with Notepad in front ×3, visible but covered ×3 — all `FOCUSED=1` with the foreground comparison matching and every `IsIconic` flipped back from `true` to `false`; Notepad maximized covering it completely, minimized plus fully covered, and `-ProcessId 0` auto-detection all succeeded too. Script-internal time peaked at 434 ms, process start to exit at 782 ms, well inside the 8 s cap; `pwsh` 7.6 behaved the same in a control round, only ~100 ms slower compiling the `Add-Type` helpers (the script deliberately avoids PowerShell 7 syntax). A pid that does not exist and a pid with no visible window both settle on `FOCUSED=0` with `exit 0`.
|
|
309
311
|
|
|
310
|
-
Security-wise the plugin opens exactly one exact route. Requests outside the vocabulary are refused: anything other than GET / HEAD / POST answers `405` (including a preflight `OPTIONS`, and it never returns a CORS header), a non-
|
|
312
|
+
Security-wise the plugin opens exactly one exact route. Requests outside the vocabulary are refused: anything other than GET / HEAD / POST answers `405` (including a preflight `OPTIONS`, and it never returns a CORS header), a non-Windows host (Web, macOS / Linux, plain Node) `501` (macOS / Linux use the deep link and never reach this route), and a missing `x-dsh-notify-me-focus: focus` header `403`.
|
|
311
313
|
|
|
312
314
|
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; `Host` must be a loopback name (`127.0.0.1` / `localhost` / `[::1]`, port optional), because the shell deletes `host` when forwarding and fetch refills it from the loopback URL, 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.
|
|
313
315
|
|
|
@@ -327,7 +329,9 @@ The cases where it will not raise are the same ones listed under [Known limitati
|
|
|
327
329
|
**Platform differences**
|
|
328
330
|
|
|
329
331
|
- 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), so approval toasts fall back to their buttonless form. When the host renders no notification buttons, the `bridge` field of `debug()` explains why, and nothing else is affected.
|
|
332
|
+
- 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.
|
|
330
333
|
- 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, or is hidden to the tray with `SW_HIDE`, 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)).
|
|
334
|
+
- 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.
|
|
331
335
|
- macOS: alerts, sound, the title marker and toast-click navigation carry no platform assumptions and work as usual; but DSH Desktop (Electron) system notifications require the app to be signed — an unsigned build simply emits no notification — and whether the official macOS build meets that precondition is untested; notification button rendering on the macOS desktop host is likewise untested (the Windows desktop host is tested and renders none).
|
|
332
336
|
|
|
333
337
|
**Alert content and timing**
|
|
@@ -349,7 +353,7 @@ The cases where it will not raise are the same ones listed under [Known limitati
|
|
|
349
353
|
```powershell
|
|
350
354
|
node --check lib\client.js
|
|
351
355
|
node --check lib\index.js
|
|
352
|
-
node smoke\smoke-test.cjs # offline state-machine test: three host generations + master switch + zh/en cases + the quick-decision bridge (worker half included) + idle detection and toast self-dismiss
|
|
356
|
+
node smoke\smoke-test.cjs # offline state-machine test: three host generations + master switch + zh/en cases + the quick-decision bridge (worker half included) + idle detection and toast self-dismiss + toast tag length handling
|
|
353
357
|
node smoke\cordis-host-test.mjs # real-cordis end-to-end (skips when no local DSH installation is found)
|
|
354
358
|
powershell -NoProfile -File lib\focus-window.ps1 -ProcessId 0 # manual raise test, the last line should be FOCUSED=1
|
|
355
359
|
npm pack --dry-run # preview the published tarball
|
|
@@ -369,6 +373,8 @@ npm pack --dry-run # preview the published tarball
|
|
|
369
373
|
| <a href="https://github.com/RiZhiZhaoYi"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/RiZhiZhaoYi.png" width="40" height="40" alt="@RiZhiZhaoYi"></a> | [#12](https://github.com/chromoany/dsh-notify-me/issues/12): external notification forwarding (Discord / Bark / Gotify / custom webhook) |
|
|
370
374
|
| <a href="https://github.com/yuexian7"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/yuexian7.png" width="40" height="40" alt="@yuexian7"></a> | [#17](https://github.com/chromoany/dsh-notify-me/issues/17): the ask for Android delivery, which led to the Feishu / ServerChan / WxPusher targets |
|
|
371
375
|
| <a href="https://github.com/shrekcg"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/shrekcg.png" width="40" height="40" alt="@shrekcg"></a> | [#16](https://github.com/chromoany/dsh-notify-me/pull/16): away detection (`idleMinutes`), reply-done routing (`donePolicy`), auto-dismiss (`autoDismiss`) |
|
|
376
|
+
| <a href="https://github.com/Donald-Yip"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/Donald-Yip.png" width="40" height="40" alt="@Donald-Yip"></a> | [#18](https://github.com/chromoany/dsh-notify-me/issues/18): the report that a Windows notification tag over the 64-character cap made the platform silently reject the approval test toast |
|
|
377
|
+
| <a href="https://github.com/dunxuan"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/dunxuan.png" width="40" height="40" alt="@dunxuan"></a> | [#20](https://github.com/chromoany/dsh-notify-me/issues/20): the report that alerts for the open session showed a placeholder instead of the session title |
|
|
372
378
|
|
|
373
379
|
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.
|
|
374
380
|
|
package/README.md
CHANGED
|
@@ -80,7 +80,7 @@ Web 用户可再测审批按钮,通知上会带「同意 / 拒绝」。桌面
|
|
|
80
80
|
window.__dshNotifyMe.test("done") // 「完成」示例
|
|
81
81
|
window.__dshNotifyMe.test("attention") // 「需要你」示例
|
|
82
82
|
window.__dshNotifyMe.test("approval") // 桥可用时带「同意 / 拒绝」按钮;否则只发普通通知(桌面端即如此)
|
|
83
|
-
window.__dshNotifyMe.debug() // 桥接状态看 bridge
|
|
83
|
+
window.__dshNotifyMe.debug() // 桥接状态看 bridge 字段(active = 按钮可用);最近一次被平台拒发的原因在 lastToastReject
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
没有测试通知时,先检查:通知权限是否被拒绝(在页面上点一下 → 选「允许」;或地址栏锁 → 站点设置 → 通知 → 允许 → 刷新)、装完没重启 DSH、系统设置里浏览器通知被关。
|
|
@@ -103,6 +103,8 @@ dsh-notify-me 把「监督」和「守在屏幕前」解耦:只在真的出现
|
|
|
103
103
|
|
|
104
104
|
**回复完成**也覆盖后台会话;完成但还没看时,标题带 `✅ 回复完成 ·` 标记,打开对应会话即撤。标题标记不受提醒策略限制。
|
|
105
105
|
|
|
106
|
+
通知正文的第一行是会话标题:当前正在看的会话和其他会话一样显示自己的标题,只有宿主还没给出标题的新会话才用「当前对话」占位符兜底。
|
|
107
|
+
|
|
106
108
|
> **后台**子代理(subagent)子会话的等待与完成默认**不提醒**:DSH 把每个子代理子会话列成独立会话,但它们是所属主对话那一轮里的步骤,提醒只会是噪音。你当前打开的那个子代理会话不算在内,照常提醒。设置页「子代理会话不提醒」可关掉这个静音。
|
|
107
109
|
|
|
108
110
|
## 在 DSH 设置里改配置
|
|
@@ -122,7 +124,7 @@ dsh-notify-me 把「监督」和「守在屏幕前」解耦:只在真的出现
|
|
|
122
124
|
- **「回复完成」什么时候提醒**(默认「仅后台」):仅后台 / 仅当前对话静默 / 总是提醒,三选一;
|
|
123
125
|
- **通知自动消失**(默认「离开时保留」):离开时保留 / 总是关闭 / 从不关闭,三选一;
|
|
124
126
|
- **子代理会话不提醒**(默认开):跳过后台子代理(subagent)会话,你正开着的那个照常提醒;
|
|
125
|
-
-
|
|
127
|
+
- **点击通知回到对应对话**(默认开):切到对应对话并把窗口带到前台,Windows 桌面走宿主路由原生抬窗、macOS / Linux 走 `dsh://open` 深链,多个标签页只调起一个。
|
|
126
128
|
|
|
127
129
|
<details>
|
|
128
130
|
<summary>展开各开关的边界条件</summary>
|
|
@@ -168,13 +170,13 @@ dsh-notify-me 把「监督」和「守在屏幕前」解耦:只在真的出现
|
|
|
168
170
|
|
|
169
171
|
#### 运行环境与诊断
|
|
170
172
|
|
|
171
|
-
在「高级设置」最后一块。默认自动识别当前是 Web 端还是桌面端(DSH Desktop,`dsh-app
|
|
173
|
+
在「高级设置」最后一块。默认自动识别当前是 Web 端还是桌面端(DSH Desktop,`dsh-app://`);识别不准时可手动指定——Windows 桌面点通知走宿主路由做原生抬窗、macOS / Linux 走 `dsh://open` 深链(见[桌面端怎么抬窗的](#桌面端怎么抬窗的))、通知上不带快捷裁决按钮;Web 端走 `window.focus()` 与 Service Worker 桥。手动覆盖与自动识别不一致时,设置页会明示检测结果。
|
|
172
174
|
|
|
173
175
|
<details>
|
|
174
176
|
<summary>通知语言、桌面端抬窗与恢复默认</summary>
|
|
175
177
|
|
|
176
178
|
- **通知语言**:跟随界面 / 简体中文 / English——决定通知文字与 `🔔 …` 标题标记使用的语言;
|
|
177
|
-
- **桌面端抬窗**:
|
|
179
|
+
- **桌面端抬窗**:Windows 走宿主路由做原生激活、macOS / Linux 走 `dsh://open` 深链;最小化、被别的窗口盖住的窗口在 Windows 与 Linux 上都实测能抬回来(见[桌面端怎么抬窗的](#桌面端怎么抬窗的));
|
|
178
180
|
- **恢复默认设置**:把所有开关与音效设置还原成出厂值(不动外部推送目标和已选的自定义音频文件)。
|
|
179
181
|
|
|
180
182
|
</details>
|
|
@@ -264,7 +266,7 @@ window.__dshNotifyMe.testExternal() // 显式外发测试:向有
|
|
|
264
266
|
|
|
265
267
|
## 工作原理
|
|
266
268
|
|
|
267
|
-
|
|
269
|
+
提醒核心监听会话状态与待处理交互;审批裁决由页面侧完成,Windows 桌面抬窗走宿主路由加 Win32 原生激活、macOS / Linux 走 `dsh://open` 深链。
|
|
268
270
|
|
|
269
271
|
<details>
|
|
270
272
|
<summary>展开事件来源与降级说明</summary>
|
|
@@ -295,18 +297,18 @@ window.__dshNotifyMe.testExternal() // 显式外发测试:向有
|
|
|
295
297
|
|
|
296
298
|
### 桌面端怎么抬窗的
|
|
297
299
|
|
|
298
|
-
DSH Desktop 是一层 Electron 壳,页面跑在 `dsh-app://app` 下:DOM 的 `window.focus()` 只动浏览器窗口对象、碰不到原生窗口,壳的 `will-navigate` 又把页面里发 `dsh:`
|
|
300
|
+
DSH Desktop 是一层 Electron 壳,页面跑在 `dsh-app://app` 下:DOM 的 `window.focus()` 只动浏览器窗口对象、碰不到原生窗口,壳的 `will-navigate` 又把页面里发 `dsh:` 的常规出口堵上了。插件按平台走两条通道:Windows 走插件自己的宿主路由——页面 POST `/__dsh-notify-me/focus-window`,宿主起 `powershell.exe` 跑 `lib/focus-window.ps1`,由它枚举原生窗口、自适应激活;macOS / Linux 走壳自己的 `dsh://open` 深链——页面在点击手势里插一个隐藏 iframe 导航 `dsh://open`(子框架导航不经过壳的顶层 `will-navigate` 拦截),交给系统协议注册,壳的 `second-instance` / `open-url` 处理器据此 restore + show + focus 主窗口。Windows 上这条深链在 `0.2.1-rc.2` 复测 3/3 无效,1.14.0 起改走宿主路由;Linux(Plasma 6.8 / Wayland)已实测能把最小化或后台的窗口抬回前台,macOS 未实测。
|
|
299
301
|
|
|
300
302
|
<details>
|
|
301
303
|
<summary>展开路由、激活顺序、实测数据与安全闸门</summary>
|
|
302
304
|
|
|
303
|
-
|
|
305
|
+
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 的顶层窗口(优先类名 `Chrome_WidgetWin_1`,再按 `GetWindowRect` 面积取最大)→ 自适应激活 → 比对 `GetForegroundWindow()` 打印 `FOCUSED=1|0` → 宿主回 `200` / `202`。
|
|
304
306
|
|
|
305
|
-
|
|
307
|
+
Windows 的激活顺序是实的:已经在前台就什么都不做(最常见的情况,零闪烁);最小化了先 `SW_RESTORE`;然后合成一次 ALT 按键(`keybd_event` 按下抬起)给本线程前台权限,再 `SetForegroundWindow`;这一串都不行才退到 `SW_MINIMIZE` + `SW_RESTORE` 兜底。单独调 `SetForegroundWindow` 会被前台锁直接拒,按调用算、跟 `ForegroundLockTimeout` 无关;这也重新解释了 1.5.2 那套深链「时灵时不灵」——能抬起来的那些次,多半是系统在通知被点击时自己激活了应用。
|
|
306
308
|
|
|
307
309
|
实测(`powershell.exe` 5.1,同一轮跑完):窗口在前台 ×3、最小化 + 记事本在前台 ×3、可见但被盖住 ×3,全部 `FOCUSED=1` 且前台窗口比对一致,最小化那几个的 `IsIconic` 都从 `true` 变回 `false`;记事本最大化完全遮挡、最小化 + 完全遮挡、`-ProcessId 0` 自动探测同样成功。脚本内部耗时最坏 434 ms,进程启动到退出最坏 782 ms,都在 8 秒上限内;`pwsh` 7.6 对照一轮行为一致,只是 `Add-Type` 编译慢约 100 ms(脚本刻意不用 7 的语法)。不存在的 pid、存在但没有可见窗口的 pid 都稳定 `FOCUSED=0` 并 `exit 0`。
|
|
308
310
|
|
|
309
|
-
安全上只开一条 exact 路由。词表之外的请求一律拒:非 GET / HEAD / POST 回 `405`(包括预检的 `OPTIONS`,且从不回任何 CORS
|
|
311
|
+
安全上只开一条 exact 路由。词表之外的请求一律拒:非 GET / HEAD / POST 回 `405`(包括预检的 `OPTIONS`,且从不回任何 CORS 头),非 Windows 宿主(Web 版、macOS / Linux、纯 Node)回 `501`(macOS / Linux 走深链,不经过这条路由),缺 `x-dsh-notify-me-focus: focus` 头回 `403`。
|
|
310
312
|
|
|
311
313
|
那个头只是「这是页面发来的」标记,不是防线——DNS rebinding 的恶意页对目标地址而言是同源的,能带任意自定义头、也不触发预检。真正的闸门是三层:对端地址必须是 loopback;`Host` 必须是 loopback 名(`127.0.0.1` / `localhost` / `[::1]`,可带端口),因为壳转发时 `host` 已被删掉、由 fetch 按 loopback URL 重填,而 rebinding 的页面 Host 仍是攻击者域名;带了 `Origin` 就必须和 `Host` 同源。任一条不符回 `403`,`reason` 分别是 `bad-remote` / `bad-host` / `cross-origin`。`GET` 只回 `{ok, route, enabled, desktop, platform}`,装完可以先用浏览器打开确认路由在不在。400 毫秒内的重复调用合并成一次,脚本超过 8 秒没回话就 kill 掉按失败处理。
|
|
312
314
|
|
|
@@ -326,7 +328,9 @@ DSH Desktop 是一层 Electron 壳,页面跑在 `dsh-app://app` 下:DOM 的
|
|
|
326
328
|
**平台差异**
|
|
327
329
|
|
|
328
330
|
- 快捷裁决按钮要 Service Worker:`http://127.0.0.1`、`https` 可用,`http://192.168.x.x` 这类局域网地址不行;**桌面端(`dsh-app://`)已实测无法注册 Service Worker**(宿主未开放 `allowServiceWorkers` 特权),审批通知退回无按钮样式。宿主不渲染通知按钮时,`debug()` 的 `bridge` 字段会说明原因,其余功能不受影响。
|
|
331
|
+
- Windows 的系统通知标签上限 64 字符,而 Chromium 交给平台的是 `n#<origin>#<tag>` 整串——桌面页面 `dsh-app://app` 一项就占去 16 个。插件按当前 `location.origin` 算剩余预算,超长时保留可读前缀、尾部换成短哈希,所以 `debug()` 里看到的标签可能被截短;平台仍然拒发时,原文记在 `debug().lastToastReject`,设置页的测试按钮也会如实报出来,不再「提示已发送但什么都没弹」。
|
|
329
332
|
- 桌面端(Windows)点通知后窗口仍可能抬不起来:目标窗口属于更高完整性级别(提权 / UAC)、在另一个虚拟桌面、前台被别的进程反复抢回去,或窗口被 `SW_HIDE` 隐藏到托盘时,宿主脚本回 `FOCUSED=0`、路由回 `202`,对话照常切(详见[桌面端怎么抬窗的](#桌面端怎么抬窗的))。
|
|
333
|
+
- 桌面端(macOS / Linux)点通知依赖 `dsh://open` 深链:系统未注册 `x-scheme-handler/dsh`、或壳没有 `second-instance` / `open-url` 处理时抬不起来;Linux 上已实测正常,macOS 未实测。
|
|
330
334
|
- macOS:提醒、提示音、标题标记、点通知跳转都没有平台假设,照常工作;但 DSH Desktop(Electron)的系统通知要求应用已签名,未签名的通知直接发不出去,官方 macOS 版是否满足这一前提未实测;审批按钮在 macOS 桌面宿主上的渲染同样未实测(Windows 桌面端已实测不渲染)。
|
|
331
335
|
|
|
332
336
|
**提醒内容与时机**
|
|
@@ -348,7 +352,7 @@ DSH Desktop 是一层 Electron 壳,页面跑在 `dsh-app://app` 下:DOM 的
|
|
|
348
352
|
```powershell
|
|
349
353
|
node --check lib\client.js
|
|
350
354
|
node --check lib\index.js
|
|
351
|
-
node smoke\smoke-test.cjs # 离线状态机冒烟测试:三代宿主 + 主开关 + 中英语言用例 + 快捷裁决桥(Service Worker 半侧一并跑)+ 闲置判定与通知自收
|
|
355
|
+
node smoke\smoke-test.cjs # 离线状态机冒烟测试:三代宿主 + 主开关 + 中英语言用例 + 快捷裁决桥(Service Worker 半侧一并跑)+ 闲置判定与通知自收 + 通知标签长度收口
|
|
352
356
|
node smoke\cordis-host-test.mjs # 真 cordis 端到端(找不到本机 DSH 时自动跳过)
|
|
353
357
|
powershell -NoProfile -File lib\focus-window.ps1 -ProcessId 0 # 手动验证抬窗脚本,末行应是 FOCUSED=1
|
|
354
358
|
npm pack --dry-run # 预览发布包
|
|
@@ -368,6 +372,8 @@ npm pack --dry-run # 预览发布包
|
|
|
368
372
|
| <a href="https://github.com/RiZhiZhaoYi"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/RiZhiZhaoYi.png" width="40" height="40" alt="@RiZhiZhaoYi"></a> | [#12](https://github.com/chromoany/dsh-notify-me/issues/12):外部通知转发(Discord / Bark / Gotify / 自定义 Webhook) |
|
|
369
373
|
| <a href="https://github.com/yuexian7"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/yuexian7.png" width="40" height="40" alt="@yuexian7"></a> | [#17](https://github.com/chromoany/dsh-notify-me/issues/17):安卓端收消息的诉求,促成飞书 / Server酱 / WxPusher 三种目标 |
|
|
370
374
|
| <a href="https://github.com/shrekcg"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/shrekcg.png" width="40" height="40" alt="@shrekcg"></a> | [#16](https://github.com/chromoany/dsh-notify-me/pull/16):离开判定 `idleMinutes`、「回复完成」判定 `donePolicy`、自动消失 `autoDismiss` |
|
|
375
|
+
| <a href="https://github.com/Donald-Yip"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/Donald-Yip.png" width="40" height="40" alt="@Donald-Yip"></a> | [#18](https://github.com/chromoany/dsh-notify-me/issues/18):Windows 通知 tag 超过 64 字符上限、审批测试通知被平台静默拒收的报告 |
|
|
376
|
+
| <a href="https://github.com/dunxuan"><img src="https://raw.githubusercontent.com/chromoany/dsh-notify-me/main/docs/contributors/dunxuan.png" width="40" height="40" alt="@dunxuan"></a> | [#20](https://github.com/chromoany/dsh-notify-me/issues/20):当前会话的通知正文用占位符、未取会话标题的报告 |
|
|
371
377
|
|
|
372
378
|
署名口径:本仓库收编外部 PR 时以维护者提交落地——不沿用原 commit、不挂 Co-authored-by,GitHub 的 contributors 图只显示维护者,贡献者以上面的致谢署名。
|
|
373
379
|
|
package/cordis.patch.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# dsh-notify-me profile patch layer — insert one loader entry for the
|
|
2
|
-
# plugin package. The entry is a normal cordis loader entry (id + package
|
|
3
|
-
# name); the browser half is picked up by dsh-client-modules through the
|
|
4
|
-
# package's dsh.client declaration, exactly like the shipped ui-* packages.
|
|
5
|
-
- insert:
|
|
6
|
-
- id: notify-me
|
|
7
|
-
name: 'dsh-notify-me'
|
|
1
|
+
# dsh-notify-me profile patch layer — insert one loader entry for the
|
|
2
|
+
# plugin package. The entry is a normal cordis loader entry (id + package
|
|
3
|
+
# name); the browser half is picked up by dsh-client-modules through the
|
|
4
|
+
# package's dsh.client declaration, exactly like the shipped ui-* packages.
|
|
5
|
+
- insert:
|
|
6
|
+
- id: notify-me
|
|
7
|
+
name: 'dsh-notify-me'
|
package/lib/client.js
CHANGED
|
@@ -218,8 +218,8 @@
|
|
|
218
218
|
language: "auto",
|
|
219
219
|
// Which host environment this page runs in: 'auto' detects from the page
|
|
220
220
|
// protocol (dsh-app:// = the packaged DSH Desktop shell), 'desktop' and
|
|
221
|
-
// 'web' force it. The desktop
|
|
222
|
-
// cannot carry quick-decision buttons at all; the browser uses
|
|
221
|
+
// 'web' force it. The desktop needs its own raise path (raiseWindow
|
|
222
|
+
// below) and cannot carry quick-decision buttons at all; the browser uses
|
|
223
223
|
// window.focus() and the Service Worker bridge.
|
|
224
224
|
hostEnv: "auto",
|
|
225
225
|
// toast + sound are only useful while the user is elsewhere; the tab
|
|
@@ -304,6 +304,10 @@
|
|
|
304
304
|
var raw = localStorage.getItem(LS_CONFIG);
|
|
305
305
|
if (raw) cfg = JSON.parse(raw);
|
|
306
306
|
} catch (e) { /* corrupt storage -> defaults */ }
|
|
307
|
+
// JSON.parse also accepts `null`, `"x"` and `7`. A non-object would make
|
|
308
|
+
// the default fill below throw on `in` and take the whole plugin down
|
|
309
|
+
// with it, so anything that is not a plain object falls back to defaults.
|
|
310
|
+
if (!cfg || typeof cfg !== "object" || Array.isArray(cfg)) cfg = {};
|
|
307
311
|
// The in-page delivery options are gone: 1.11.0 removed the overlay as a
|
|
308
312
|
// channel, 1.12.0 the approval card. An old config's `channel` / `overlay`
|
|
309
313
|
// / `toast` / `overlayCorner` keys mean nothing now — dropped here so the
|
|
@@ -506,26 +510,53 @@
|
|
|
506
510
|
var FOCUS_HEADERS = { "x-dsh-notify-me-focus": "focus" };
|
|
507
511
|
// What the last raise attempt did, surfaced through debug() so a failing
|
|
508
512
|
// host path can be diagnosed from the settings page instead of by guesswork.
|
|
509
|
-
var raiseState = {
|
|
513
|
+
var raiseState = { last: null };
|
|
514
|
+
// The desktop is one shell, but the channel that can raise its window is
|
|
515
|
+
// not: Windows has the host route (the deep link is a measured no-op there,
|
|
516
|
+
// see below), macOS / Linux only have the shell's own dsh://open handler.
|
|
517
|
+
// Read from the platform, not from the first click, so debug() can answer
|
|
518
|
+
// what a toast click would do before anything has been clicked.
|
|
519
|
+
function isWindowsPage() {
|
|
520
|
+
try {
|
|
521
|
+
return /Windows/i.test(String((typeof navigator !== "undefined" && navigator.userAgent) || ""));
|
|
522
|
+
} catch (e) { return false; }
|
|
523
|
+
}
|
|
524
|
+
function desktopRaiseChannel() {
|
|
525
|
+
return isWindowsPage() ? "host-route" : "dsh-deeplink";
|
|
526
|
+
}
|
|
510
527
|
// Bring the OS window forward. A browser tab answers to window.focus(); the
|
|
511
528
|
// Electron shell does not — DOM focus() never touches the native window, and
|
|
512
|
-
// Chromium only activates a window the OS already treats as foreground.
|
|
513
|
-
// shell exposes no focus IPC either (preload's dshDesktop carries none), so
|
|
514
|
-
// the activation has to run in the host process: lib/index.js registers
|
|
515
|
-
// /__dsh-notify-me/focus-window there, and this click posts to it. Every
|
|
516
|
-
// non-static dsh-app://app path is forwarded by the shell to the host web
|
|
517
|
-
// server with the host cookie attached, so a relative same-origin fetch
|
|
518
|
-
// reaches that route exactly as it would from a browser tab.
|
|
529
|
+
// Chromium only activates a window the OS already treats as foreground.
|
|
519
530
|
//
|
|
520
|
-
//
|
|
521
|
-
//
|
|
522
|
-
//
|
|
523
|
-
// second instance exited in ~130 ms and
|
|
524
|
-
// changed
|
|
531
|
+
// Two desktop channels exist. Windows keeps the host route — lib/index.js
|
|
532
|
+
// spawns lib/focus-window.ps1 from the process that owns the window, because
|
|
533
|
+
// the deep link below was measured there as three failures (DSH Desktop
|
|
534
|
+
// 0.2.1-rc.2, issue #9: the second instance exited in ~130 ms and IsIconic
|
|
535
|
+
// never changed). Every other desktop uses the shell's own dsh://open
|
|
536
|
+
// handler: the hidden-frame navigation reaches the system protocol
|
|
537
|
+
// registration, whose single-instance owner restores and focuses the
|
|
538
|
+
// window. That was the only channel before 1.14.0 and it still works
|
|
539
|
+
// outside Windows.
|
|
540
|
+
function raiseViaDeepLink() {
|
|
541
|
+
try {
|
|
542
|
+
var f = document.createElement("iframe");
|
|
543
|
+
f.setAttribute("aria-hidden", "true");
|
|
544
|
+
f.setAttribute("tabindex", "-1");
|
|
545
|
+
f.style.cssText = "position:fixed;left:-10px;top:-10px;width:0;height:0;border:0;visibility:hidden";
|
|
546
|
+
f.src = "dsh://open";
|
|
547
|
+
(document.body || document.documentElement).appendChild(f);
|
|
548
|
+
setTimeout(function () {
|
|
549
|
+
try { if (f.parentNode) f.parentNode.removeChild(f); } catch (e) {}
|
|
550
|
+
}, 4000);
|
|
551
|
+
raiseState.last = "deeplink";
|
|
552
|
+
} catch (e) {
|
|
553
|
+
raiseState.last = "error";
|
|
554
|
+
}
|
|
555
|
+
}
|
|
525
556
|
function raiseWindow() {
|
|
526
557
|
try { window.focus(); } catch (e) {}
|
|
527
|
-
if (!isDesktopShell()) { raiseState.
|
|
528
|
-
|
|
558
|
+
if (!isDesktopShell()) { raiseState.last = "browser"; return; }
|
|
559
|
+
if (!isWindowsPage()) { raiseViaDeepLink(); return; }
|
|
529
560
|
try {
|
|
530
561
|
if (typeof fetch !== "function") { raiseState.last = "no-fetch"; return; }
|
|
531
562
|
raiseState.last = "pending";
|
|
@@ -841,6 +872,12 @@
|
|
|
841
872
|
// failure issue #18 reported. Keeping the reason here makes it readable from
|
|
842
873
|
// debug() and lets the test buttons stop claiming success.
|
|
843
874
|
var lastToastReject = null;
|
|
875
|
+
// The Service Worker's showNotification() settles asynchronously, so its
|
|
876
|
+
// refusal lands a tick later than the click that raised it. The settings
|
|
877
|
+
// test keeps this promise and reports only after it settles; otherwise the
|
|
878
|
+
// page claimed "sent" for a toast the platform had already dropped (the
|
|
879
|
+
// surviving half of issue #18 on the only path that carries buttons).
|
|
880
|
+
var lastToastPending = null;
|
|
844
881
|
function noteToastReject(tag, err) {
|
|
845
882
|
var message = "unknown";
|
|
846
883
|
try { message = String((err && err.message) || err || "unknown"); } catch (e) {}
|
|
@@ -876,8 +913,12 @@
|
|
|
876
913
|
});
|
|
877
914
|
// The worker call can refuse asynchronously for the same platform
|
|
878
915
|
// reason; leaving the rejection unhandled would hide it just like
|
|
879
|
-
// the swallowed constructor throw did (issue #18).
|
|
880
|
-
|
|
916
|
+
// the swallowed constructor throw did (issue #18). The same promise
|
|
917
|
+
// is what runTest() waits on before it reports "sent".
|
|
918
|
+
if (shown && typeof shown.then === "function") {
|
|
919
|
+
lastToastPending = shown;
|
|
920
|
+
shown.catch(function (e) { noteToastReject(tag, e); });
|
|
921
|
+
}
|
|
881
922
|
// No auto-close on purpose: an unanswered approval stays clickable
|
|
882
923
|
// (toast, then Action Center) until the request is settled — the
|
|
883
924
|
// wait-teardown path closes it through closeNotificationTag().
|
|
@@ -1702,13 +1743,26 @@
|
|
|
1702
1743
|
fire("attention", copy.title, copy.body, false, copy.sessionId, copy.quick || null);
|
|
1703
1744
|
}
|
|
1704
1745
|
}
|
|
1705
|
-
// A display label for a session row
|
|
1706
|
-
// "当前对话 / Current
|
|
1746
|
+
// A display label for a session row; an empty label and the legacy
|
|
1747
|
+
// "current" sentinel fall back to the localized "当前对话 / Current
|
|
1748
|
+
// conversation" placeholder, which now only stands in for a session whose
|
|
1749
|
+
// title the list cannot supply yet.
|
|
1707
1750
|
function sessionLabelText(row) {
|
|
1708
1751
|
var raw = row && row.label;
|
|
1709
1752
|
if (!raw || raw === "current") return texts().current;
|
|
1710
1753
|
return raw;
|
|
1711
1754
|
}
|
|
1755
|
+
// The session's own sidebar title, or "" while the host has not published
|
|
1756
|
+
// one (a brand-new session) or the list does not carry the row at all.
|
|
1757
|
+
// Read live, so a title the host fills in later reaches the next alert.
|
|
1758
|
+
function sessionTitleOf(sid) {
|
|
1759
|
+
try {
|
|
1760
|
+
var st = listStore && listStore.getSnapshot();
|
|
1761
|
+
var sum = st && st.byId && st.byId[sid];
|
|
1762
|
+
if (sum) return sum.displayTitle || sum.title || "";
|
|
1763
|
+
} catch (e) {}
|
|
1764
|
+
return "";
|
|
1765
|
+
}
|
|
1712
1766
|
// The session the user is looking at, or null while the list is not ready.
|
|
1713
1767
|
// Two host generations own this fact differently:
|
|
1714
1768
|
// * <= 0.1.5-rc.3: the list snapshot carried `current`;
|
|
@@ -2001,7 +2055,11 @@
|
|
|
2001
2055
|
}
|
|
2002
2056
|
}
|
|
2003
2057
|
|
|
2004
|
-
// face -> row adapter (selected session, rich data)
|
|
2058
|
+
// face -> row adapter (selected session, rich data). The label is the
|
|
2059
|
+
// session's own sidebar title like any other row, so "needs you" and
|
|
2060
|
+
// "reply finished" name the conversation instead of the old placeholder;
|
|
2061
|
+
// the placeholder remains the fallback while the title is unknown
|
|
2062
|
+
// (issue #20).
|
|
2005
2063
|
function evalSessionFace(sessionId, snap) {
|
|
2006
2064
|
if (sessionId !== currentFaceId) return;
|
|
2007
2065
|
var pend = (snap.pending || []).map(function (p) {
|
|
@@ -2015,7 +2073,7 @@
|
|
|
2015
2073
|
face: true,
|
|
2016
2074
|
faceSnap: snap,
|
|
2017
2075
|
currentId: sessionId,
|
|
2018
|
-
label: "current"
|
|
2076
|
+
label: sessionTitleOf(sessionId) || "current"
|
|
2019
2077
|
});
|
|
2020
2078
|
}
|
|
2021
2079
|
// list row -> adapter (every other listed session)
|
|
@@ -2302,7 +2360,7 @@
|
|
|
2302
2360
|
});
|
|
2303
2361
|
} catch (e) {}
|
|
2304
2362
|
// keep in sync with package.json "version" on every release
|
|
2305
|
-
api.version = "1.14.
|
|
2363
|
+
api.version = "1.14.4";
|
|
2306
2364
|
api.setConfig = function (patch) { return setConfigLocal(patch); };
|
|
2307
2365
|
api.resetConfig = function () {
|
|
2308
2366
|
try {
|
|
@@ -2406,7 +2464,7 @@
|
|
|
2406
2464
|
hostEnv: config.hostEnv,
|
|
2407
2465
|
hostEnvDetected: detectedDesktop() ? "desktop" : "web",
|
|
2408
2466
|
desktop: isDesktopShell(),
|
|
2409
|
-
raiseChannel: isDesktopShell() ?
|
|
2467
|
+
raiseChannel: isDesktopShell() ? desktopRaiseChannel() : "window-focus",
|
|
2410
2468
|
raiseLast: raiseState.last,
|
|
2411
2469
|
actionKeys: Object.keys(pendingActions),
|
|
2412
2470
|
permission: ("Notification" in window) ? Notification.permission : "n/a",
|
|
@@ -2585,6 +2643,7 @@
|
|
|
2585
2643
|
resetDone: "已恢复默认设置。",
|
|
2586
2644
|
sent: "已发送测试提醒 · 通知语言:",
|
|
2587
2645
|
testRefused: "系统拒收了这条通知:",
|
|
2646
|
+
testNoPermission: "通知权限还没给:先在页面上允许一次,再点测试。",
|
|
2588
2647
|
permHint: "通知权限尚未授予:先在页面上点击一次并允许通知,系统通知才能弹出(提示音不受影响)。",
|
|
2589
2648
|
offHint: "已关闭提醒:先打开「启用提醒」再测试。",
|
|
2590
2649
|
versionLine: "插件版本:dsh-notify-me v"
|
|
@@ -2735,6 +2794,7 @@
|
|
|
2735
2794
|
resetDone: "Defaults restored.",
|
|
2736
2795
|
sent: "Test alert sent · notification language: ",
|
|
2737
2796
|
testRefused: "The platform refused this toast: ",
|
|
2797
|
+
testNoPermission: "Notification permission is not granted: allow it once from the page, then test again.",
|
|
2738
2798
|
permHint: "Notification permission is not granted yet — click once on the page and allow notifications so toasts can appear (sound is unaffected).",
|
|
2739
2799
|
offHint: "Reminders are off: enable them first, then test.",
|
|
2740
2800
|
versionLine: "Plugin version: dsh-notify-me v"
|
|
@@ -3214,22 +3274,33 @@
|
|
|
3214
3274
|
}
|
|
3215
3275
|
function runTest(kind) {
|
|
3216
3276
|
if (!config.enabled) { setFeedback(t("offHint")); return; }
|
|
3277
|
+
// A denied permission means showToast() returns before it tries
|
|
3278
|
+
// anything and records no refusal; saying "sent" there would be the
|
|
3279
|
+
// same lie issue #18 was about, one layer earlier.
|
|
3280
|
+
if (!canToast()) { setFeedback(t("testNoPermission")); return; }
|
|
3217
3281
|
unlockOnce();
|
|
3218
3282
|
// Bypasses the visibility rules on purpose: a test must fire while the
|
|
3219
3283
|
// page is open, otherwise the button proves nothing.
|
|
3220
3284
|
var before = lastToastReject;
|
|
3285
|
+
var report = function () {
|
|
3286
|
+
// "sent" would be a lie when the platform refused the toast: the
|
|
3287
|
+
// constructor throws synchronously, and the worker's
|
|
3288
|
+
// showNotification() rejects a tick later, so the worker path waits
|
|
3289
|
+
// for that promise before it reports (issue #18).
|
|
3290
|
+
var refused = lastToastReject && lastToastReject !== before ? lastToastReject : null;
|
|
3291
|
+
if (refused) { setFeedback(t("testRefused") + refused.message); return; }
|
|
3292
|
+
var langName = effectiveLang() === "en" ? t("langEn") : t("langZh");
|
|
3293
|
+
var msg = t("sent") + langName;
|
|
3294
|
+
if (kind === "approval" && !bridgeActive()) {
|
|
3295
|
+
msg += " · " + (isDesktopShell() ? t("testApprovalNoBridge") : t("bridgeOff") + swState + t("bridgeOffTail"));
|
|
3296
|
+
}
|
|
3297
|
+
setFeedback(msg);
|
|
3298
|
+
};
|
|
3299
|
+
lastToastPending = null;
|
|
3221
3300
|
testAlert(kind);
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
var refused = lastToastReject && lastToastReject !== before ? lastToastReject : null;
|
|
3226
|
-
if (refused) { setFeedback(t("testRefused") + refused.message); return; }
|
|
3227
|
-
var langName = effectiveLang() === "en" ? t("langEn") : t("langZh");
|
|
3228
|
-
var msg = t("sent") + langName;
|
|
3229
|
-
if (kind === "approval" && !bridgeActive()) {
|
|
3230
|
-
msg += " · " + (isDesktopShell() ? t("testApprovalNoBridge") : t("bridgeOff") + swState + t("bridgeOffTail"));
|
|
3231
|
-
}
|
|
3232
|
-
setFeedback(msg);
|
|
3301
|
+
var pending = lastToastPending;
|
|
3302
|
+
if (pending && typeof pending.then === "function") pending.then(report, report);
|
|
3303
|
+
else report();
|
|
3233
3304
|
}
|
|
3234
3305
|
// External forwarding rows. Target edits always patch with a fresh array
|
|
3235
3306
|
// (readConfig may hand out the DEFAULTS entry itself; in-place mutation
|
package/lib/index.js
CHANGED
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
* desktop shell it is not enough, because the shell exposes no focus IPC and
|
|
7
7
|
* Chromium only honours `window.focus()` for a window the OS already treats as
|
|
8
8
|
* foreground. This module therefore owns one loopback route on the host web
|
|
9
|
-
* server: the notification click posts to it
|
|
10
|
-
* Electron window through Win32 (lib/focus-window.ps1) from the process
|
|
11
|
-
* allowed to do so.
|
|
9
|
+
* server: on Windows the notification click posts to it and the host activates
|
|
10
|
+
* the Electron window through Win32 (lib/focus-window.ps1) from the process
|
|
11
|
+
* that is allowed to do so. Every other desktop never posts here — its page
|
|
12
|
+
* fires the shell's own `dsh://open` deep link instead, and this route answers
|
|
13
|
+
* 501.
|
|
12
14
|
*
|
|
13
15
|
* The route is reachable from the desktop page because the shell forwards every
|
|
14
16
|
* non-static `dsh-app://app` path verbatim to the host web server, host cookie
|
|
@@ -50,10 +52,12 @@ const OUTPUT_LIMIT = 4096;
|
|
|
50
52
|
export const name = "dsh-notify-me";
|
|
51
53
|
|
|
52
54
|
/**
|
|
53
|
-
* True when this host process runs on the Electron binary, i.e. inside
|
|
54
|
-
* desktop shell
|
|
55
|
-
*
|
|
56
|
-
*
|
|
55
|
+
* True when this host process runs on the Windows Electron binary, i.e. inside
|
|
56
|
+
* the desktop shell whose window this route can activate through Win32. Other
|
|
57
|
+
* desktop platforms raise through the page's `dsh://open` deep link instead and
|
|
58
|
+
* never reach this route. `process.versions.electron` is the only trustworthy
|
|
59
|
+
* signal: the shell also exports `ELECTRON_RUN_AS_NODE=1` into the host's
|
|
60
|
+
* environment, and every child of the host inherits it, so keying on the
|
|
57
61
|
* variable reports "desktop" from a plain Node test process.
|
|
58
62
|
* @returns whether native window activation is worth attempting here.
|
|
59
63
|
*/
|