dsh-notify-me 1.14.4 → 1.14.5
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 +25 -0
- package/README.en.md +16 -10
- package/README.md +16 -10
- package/lib/client.js +98 -36
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to **dsh-notify-me** are documented here.
|
|
4
4
|
|
|
5
|
+
## [1.14.5] — 2026-10-27
|
|
6
|
+
|
|
7
|
+
### 修复
|
|
8
|
+
|
|
9
|
+
- **外部推送关掉后重试还会继续**:重试链挂在定时器上,旧代码不再复查总开关、也不复查目标还在不在,关掉转发后浏览器仍会往那个地址继续 POST,还把取消掉的投递记成失败。现在每次尝试前复查开关与目标列表,取消的投递不计失败、不写死信;测试按钮仍然照发。
|
|
10
|
+
- **服务码终于在页面侧生效**:`postOnce()` 读的是 `spec.type`,可 `spec` 只是请求体、目标类型在它外面,于是 `externalVerdict()` 的服务码分支(飞书 / Server酱 / WxPusher)从来没跑过,2xx 一律记「已发送」——飞书 token 错了也一样。现在类型正确传入:服务返回 `code != 0`(WxPusher 是 `1000`)记失败并带服务端文案;2xx 但 body 不是该服务的 JSON(空白、代理或 WAF 的网页)记「已送出不可确认」,不再冒充成功。
|
|
11
|
+
- **配置写不进去时页面会说了**:`localStorage.setItem` 抛错(配额、无痕模式、存储被禁)以前被空 `catch` 吞掉,开关看着已保存、刷新就还原。现在记 `configWriteFailed`,`debug().configStored` 给出真假,设置页底部写明「设置没能保存」;写入失败期间后续改动基于内存里的最新配置,不再从旧存储重建。
|
|
12
|
+
- **审批测试通知的按钮 6 秒后失效**:标题标记到点释放时把 `pendingActions` 记录一起删了,可测试通知还留在通知中心,此刻点「同意 / 拒绝」什么都不发生。现在标记照常释放、记录留到 12 秒后与通知一起收。
|
|
13
|
+
- **「从不关闭」对审批通知也作数**:没有按钮的那条路径原来 12 秒必收,选了「从不关闭」照样消失。
|
|
14
|
+
- **通知权限弹窗被关掉后还能再问**:`permAsked` 一旦置真就不再复位,测试按钮从此唤不起授权。现在显式点测试会重新请求一次。
|
|
15
|
+
- **输入监听从模块作用域移进 watchers effect**:客户端插件热重载时不再叠一套指针 / 键盘监听,dispose 能摘干净。
|
|
16
|
+
|
|
17
|
+
### 测试
|
|
18
|
+
|
|
19
|
+
- 新增 `smoke/host-route-test.mjs` 并接进 `npm test`:不依赖本机 DSH,`lib/index.js` 的 exact 路由、GET 探针、403/405/501 闸门与脚本失败路径在任何平台都会跑。`cordis-host-test.mjs` 里原来那份挪走了,不再躲在「本机没装 DSH 就跳过」后面。
|
|
20
|
+
- 冒烟新增:关掉转发后不再重试且不计失败、2xx 非服务 JSON 记不可确认、服务码错误记失败、写配置失败提示与内存兜底、测试通知按钮活过标题标记、权限被拒后可再次请求。
|
|
21
|
+
|
|
22
|
+
### 文档
|
|
23
|
+
|
|
24
|
+
- README 中英:审批通知到底什么时候收,按实际行为重写(带按钮的不设自动撤回,桌面端无按钮的按 12 秒收,「从不关闭」时都不收)。
|
|
25
|
+
- README / CONTRIBUTING 的开发自检改成跨平台写法(正斜杠、`sh` 围栏),PowerShell 那条单独标 Windows;硬刷新补上 macOS 的按键。
|
|
26
|
+
- SECURITY 中英:抬窗入口的鉴权口径改成实际的三条(回环对端、回环 `Host`、带 `Origin` 时须同源),并写明 PowerShell 只在 Windows。
|
|
27
|
+
- `docs/listing.md` 版本口径同步到 1.14.5。
|
|
28
|
+
|
|
5
29
|
## [1.14.4] — 2026-10-27
|
|
6
30
|
|
|
7
31
|
### 修复
|
|
@@ -20,6 +44,7 @@ All notable changes to **dsh-notify-me** are documented here.
|
|
|
20
44
|
|
|
21
45
|
- README 的抬窗章节改成按平台叙述,`501` 闸门的说明改成「非 Windows 宿主」,已知限制里补上非 Windows 深链的前提(系统注册 `x-scheme-handler/dsh`、壳处理第二次启动)。
|
|
22
46
|
- `lib/index.js` 顶部注释改成按平台表述:这条路由是 Windows 专用的,其他桌面端页面根本不发请求。
|
|
47
|
+
- `docs/listing.md` 版本口径同步到 1.14.4。
|
|
23
48
|
|
|
24
49
|
## [1.14.3] — 2026-10-26
|
|
25
50
|
|
package/README.en.md
CHANGED
|
@@ -51,12 +51,12 @@ Just the plugin's own panel (the real component, on the same dark theme as the h
|
|
|
51
51
|
|
|
52
52
|
With the DSH CLI already installed, run in a terminal:
|
|
53
53
|
|
|
54
|
-
```
|
|
54
|
+
```sh
|
|
55
55
|
# Install and auto-mount into the web profile
|
|
56
56
|
dsh plugin --profile web add dsh-notify-me
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
Restart `dsh web`, then hard-refresh the page (Ctrl+Shift+R). If you use another Web profile, replace `web` with its actual name.
|
|
59
|
+
Restart `dsh web`, then hard-refresh the page (Ctrl+Shift+R on Windows / Linux, Cmd+Shift+R on macOS). If you use another Web profile, replace `web` with its actual name.
|
|
60
60
|
|
|
61
61
|
### DSH Desktop
|
|
62
62
|
|
|
@@ -132,7 +132,7 @@ Open **Settings → Notify me**. The page lays out three blocks — how you get
|
|
|
132
132
|
- **What counts as background**: switching to another app, being covered by another window, or minimizing all count; a window left in front with 3 minutes of no keyboard or mouse input counts too, and `idleMinutes: 0` falls back to looking only at the window.
|
|
133
133
|
- **When "stay quiet for the conversation on screen" is replayed**: as usual once the window goes to the background or the idle timer fires; if you already handled it, it is dropped.
|
|
134
134
|
- **The three "reply finished" choices**: "background only" = alert when you are not watching the page; "quiet for the open one" = the one on screen stays silent while other conversations still alert, useful with several open; "always" = never suppress. An old profile's "also alert 'reply finished' while in front" switch migrates to this setting automatically.
|
|
135
|
-
- **"Keep while away"**:
|
|
135
|
+
- **"Keep while away"**: while you are at the page a plain toast closes itself after a few seconds; one that arrived while you were away stays in the notification centre until you come back. A toast with Approve / Reject carries no auto-dismiss timer — it stays until you click a button, answer the request in the page, or a newer request replaces it; a desktop approval toast, which cannot render buttons, closes after 12 s and is likewise not withdrawn while you are away.
|
|
136
136
|
- **Fallback for a toast click**: on Desktop a window that will not raise leaves only the conversation switch, with the reason in `debug().raiseLast`; turn this switch off and a click does nothing.
|
|
137
137
|
|
|
138
138
|
</details>
|
|
@@ -290,7 +290,7 @@ Notifications with Approve / Reject buttons can only be raised by a Service Work
|
|
|
290
290
|
<details>
|
|
291
291
|
<summary>Button-toast bookkeeping and window raising</summary>
|
|
292
292
|
|
|
293
|
-
Each button toast is booked against its interaction key, and one toast claims only one wait; once the request has been answered in the page, or replaced by a newer request, clicking the leftover buttons decides nothing and just closes it quietly. Button toasts stay
|
|
293
|
+
Each button toast is booked against its interaction key, and one toast claims only one wait; once the request has been answered in the page, or replaced by a newer request, clicking the leftover buttons decides nothing and just closes it quietly. Button toasts carry no auto-dismiss timer — they stay until you click or answer; plain toasts close after 5 s, and a desktop approval toast without buttons after 12 s. With "never close" selected neither kind closes itself. If you miss the click, the approval in the conversation is still waiting for you.
|
|
294
294
|
|
|
295
295
|
The "raise a window and switch its conversation" part of a body click is scheduled on the worker half as well: `client.focus()` raises exactly one window (a visible one first) and routes the conversation switch to that window alone, so several DSH tabs never fight over focus or all switch at once.
|
|
296
296
|
|
|
@@ -350,15 +350,21 @@ The cases where it will not raise are the same ones listed under [Known limitati
|
|
|
350
350
|
|
|
351
351
|
## Development
|
|
352
352
|
|
|
353
|
-
```
|
|
354
|
-
node --check lib
|
|
355
|
-
node --check lib
|
|
356
|
-
|
|
357
|
-
node smoke\cordis-host-test.mjs # real-cordis end-to-end (skips when no local DSH installation is found)
|
|
358
|
-
powershell -NoProfile -File lib\focus-window.ps1 -ProcessId 0 # manual raise test, the last line should be FOCUSED=1
|
|
353
|
+
```sh
|
|
354
|
+
node --check lib/client.js
|
|
355
|
+
node --check lib/index.js
|
|
356
|
+
npm test # smoke-test (state machine) + host-route-test (host half) + cordis-host-test
|
|
359
357
|
npm pack --dry-run # preview the published tarball
|
|
360
358
|
```
|
|
361
359
|
|
|
360
|
+
`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 + toast tag length handling. `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.
|
|
361
|
+
|
|
362
|
+
When `lib/focus-window.ps1` changes (Windows only), also run it by hand:
|
|
363
|
+
|
|
364
|
+
```powershell
|
|
365
|
+
powershell -NoProfile -File lib/focus-window.ps1 -ProcessId 0 # the last line should be FOCUSED=1
|
|
366
|
+
```
|
|
367
|
+
|
|
362
368
|
`cordis-host-test.mjs` borrows `@deepseek-ai/cordis` from a local DSH installation (it probes the global npm directory, `~/.dsh/profiles/web/node_modules` and the flat fallback `~/.dsh/profiles/node_modules` in turn); in a source checkout with no profile dependencies, point it there with `DSH_CORDIS_PATH=<checkout>/vendor/cordis/lib/index.js`.
|
|
363
369
|
|
|
364
370
|
## Credits & how contributions land
|
package/README.md
CHANGED
|
@@ -51,12 +51,12 @@ DSH Web / Desktop 的通知插件,让你敢不开完整访问,也不必一
|
|
|
51
51
|
|
|
52
52
|
已安装 DSH CLI 的用户,在终端执行:
|
|
53
53
|
|
|
54
|
-
```
|
|
54
|
+
```sh
|
|
55
55
|
# 安装并自动挂载进 web profile
|
|
56
56
|
dsh plugin --profile web add dsh-notify-me
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
重启 `dsh web`,然后硬刷新页面(Ctrl+Shift+R)。如果你使用其他 Web profile,请把命令中的 `web` 换成实际名称。
|
|
59
|
+
重启 `dsh web`,然后硬刷新页面(Windows / Linux 是 Ctrl+Shift+R,macOS 是 Cmd+Shift+R)。如果你使用其他 Web profile,请把命令中的 `web` 换成实际名称。
|
|
60
60
|
|
|
61
61
|
### DSH Desktop
|
|
62
62
|
|
|
@@ -132,7 +132,7 @@ dsh-notify-me 把「监督」和「守在屏幕前」解耦:只在真的出现
|
|
|
132
132
|
- **后台的判定**:切到别的应用、被别的窗口盖住、最小化都算;窗口一直留在前台但 3 分钟没有任何键鼠输入同样算,`idleMinutes: 0` 退回只看窗口。
|
|
133
133
|
- **「当前对话不弹通知」何时补发**:窗口转到后台或闲置超时后照常提醒;若你已处理掉就作废。
|
|
134
134
|
- **「回复完成」三档**:「仅后台」=不在看页面才提醒;「仅当前对话静默」=屏幕上那条静默、别的对话照常提醒,多开对话时有用;「总是提醒」=从不静默。老配置里的「窗口在前台时也提醒『回复完成』」开关自动迁移到这一项。
|
|
135
|
-
-
|
|
135
|
+
- **「离开时保留」**:你人在页面前时,普通通知几秒后自己收;人不在时收到的那条留在通知中心等你回来。带「同意 / 拒绝」的通知不设自动撤回,留到你点按钮、回页面把请求答掉、或被新请求顶替为止;桌面端画不出按钮的审批通知按 12 秒收,人不在时同样不撤。
|
|
136
136
|
- **点击通知的兜底**:桌面端抬不起来时只切对话,原因记在 `debug().raiseLast` 里;关掉这一项后点通知不做任何事。
|
|
137
137
|
|
|
138
138
|
</details>
|
|
@@ -289,7 +289,7 @@ window.__dshNotifyMe.testExternal() // 显式外发测试:向有
|
|
|
289
289
|
<details>
|
|
290
290
|
<summary>展开按钮通知的记账与调窗口</summary>
|
|
291
291
|
|
|
292
|
-
每条按钮通知按交互 key
|
|
292
|
+
每条按钮通知按交互 key 记账,一次只认领一条等待;请求被页面里答掉、或被新请求顶替之后,残留通知上的按钮再点也不会误裁,只是安静地关掉。带按钮的通知不设自动撤回,等你点按钮或把请求答掉才消失;普通通知 5 秒自收,桌面端没有按钮的审批通知 12 秒自收。「通知自动消失」选「从不关闭」时,这两类都不收。没来得及点就回页面里裁决,对话里的审批一直等着你。
|
|
293
293
|
|
|
294
294
|
点正文的「调窗口 + 切对话」也归 worker 这半侧调度:`client.focus()` 只调起一个窗口(优先当前可见的),也只让那个窗口切对话——多个 DSH 标签页不会互相抢焦点或一起乱切。
|
|
295
295
|
|
|
@@ -349,15 +349,21 @@ Windows 的激活顺序是实的:已经在前台就什么都不做(最常见
|
|
|
349
349
|
|
|
350
350
|
## 开发自检
|
|
351
351
|
|
|
352
|
-
```
|
|
353
|
-
node --check lib
|
|
354
|
-
node --check lib
|
|
355
|
-
|
|
356
|
-
node smoke\cordis-host-test.mjs # 真 cordis 端到端(找不到本机 DSH 时自动跳过)
|
|
357
|
-
powershell -NoProfile -File lib\focus-window.ps1 -ProcessId 0 # 手动验证抬窗脚本,末行应是 FOCUSED=1
|
|
352
|
+
```sh
|
|
353
|
+
node --check lib/client.js
|
|
354
|
+
node --check lib/index.js
|
|
355
|
+
npm test # smoke-test(状态机)+ host-route-test(宿主半路由)+ cordis-host-test
|
|
358
356
|
npm pack --dry-run # 预览发布包
|
|
359
357
|
```
|
|
360
358
|
|
|
359
|
+
`smoke/smoke-test.cjs` 是离线状态机测试:三代宿主 + 主开关 + 中英语言用例 + 快捷裁决桥(Service Worker 半侧一并跑)+ 闲置判定与通知自收 + 通知标签长度收口。`smoke/host-route-test.mjs` 不需要本机 DSH,`lib/index.js` 的路由、探针与 403/405/501 闸门在任何平台都会跑。
|
|
360
|
+
|
|
361
|
+
改到 `lib/focus-window.ps1` 时(仅 Windows),另需手动跑一次:
|
|
362
|
+
|
|
363
|
+
```powershell
|
|
364
|
+
powershell -NoProfile -File lib/focus-window.ps1 -ProcessId 0 # 末行应是 FOCUSED=1
|
|
365
|
+
```
|
|
366
|
+
|
|
361
367
|
`cordis-host-test.mjs` 会从本机 DSH 安装借 `@deepseek-ai/cordis`(依次探测 npm 全局目录、`~/.dsh/profiles/web/node_modules` 与 `~/.dsh/profiles/node_modules` 平铺回退目录);源码 checkout 里没有 profile 依赖时,用 `DSH_CORDIS_PATH=<checkout>/vendor/cordis/lib/index.js` 指定即可。
|
|
362
368
|
|
|
363
369
|
## 致谢与贡献须知
|
package/lib/client.js
CHANGED
|
@@ -329,7 +329,10 @@
|
|
|
329
329
|
return cfg;
|
|
330
330
|
}
|
|
331
331
|
function writeConfig(patch) {
|
|
332
|
-
|
|
332
|
+
// A failed write leaves the live config as the only copy; rebuilding from
|
|
333
|
+
// storage would drop the setting the user just changed and make the page
|
|
334
|
+
// disagree with itself on the next patch.
|
|
335
|
+
var cfg = configWriteFailed && config ? config : readConfig();
|
|
333
336
|
for (var k in patch) cfg[k] = patch[k];
|
|
334
337
|
// Legacy alias, live in both directions: patching the old boolean still
|
|
335
338
|
// selects the policy, so an existing caller keeps its meaning instead of
|
|
@@ -339,9 +342,17 @@
|
|
|
339
342
|
}
|
|
340
343
|
cfg.donePolicy = cfg.donePolicy === "smart" || cfg.donePolicy === "always" ? cfg.donePolicy : "background";
|
|
341
344
|
cfg.doneHiddenOnly = cfg.donePolicy !== "always";
|
|
342
|
-
try {
|
|
345
|
+
try {
|
|
346
|
+
localStorage.setItem(LS_CONFIG, JSON.stringify(cfg));
|
|
347
|
+
configWriteFailed = false;
|
|
348
|
+
} catch (e) {
|
|
349
|
+
// Quota, private-mode storage, a blocked origin: the switch looks saved
|
|
350
|
+
// but dies on reload, so the settings page says so.
|
|
351
|
+
configWriteFailed = true;
|
|
352
|
+
}
|
|
343
353
|
return cfg;
|
|
344
354
|
}
|
|
355
|
+
var configWriteFailed = false;
|
|
345
356
|
var config = readConfig();
|
|
346
357
|
// Persist a patch, swap the live module config and re-apply any active
|
|
347
358
|
// title marker (its prefix follows the notification language).
|
|
@@ -472,8 +483,11 @@
|
|
|
472
483
|
|
|
473
484
|
// ─────────────────────── notification plumbing ───────────────────
|
|
474
485
|
var permAsked = false;
|
|
475
|
-
function requestPermission() {
|
|
476
|
-
|
|
486
|
+
function requestPermission(force) {
|
|
487
|
+
// An explicit "test" click is a fresh intent: after a dismissed prompt
|
|
488
|
+
// (permission stayed "default") the old latch made every later click a
|
|
489
|
+
// no-op until a reload.
|
|
490
|
+
if (!("Notification" in window) || (permAsked && !force)) return;
|
|
477
491
|
permAsked = true;
|
|
478
492
|
try {
|
|
479
493
|
if (Notification.permission === "default") {
|
|
@@ -951,7 +965,12 @@
|
|
|
951
965
|
// picks between the three behaviours (see DEFAULTS).
|
|
952
966
|
var policy = config.autoDismiss === "always" || config.autoDismiss === "never" ? config.autoDismiss : "present";
|
|
953
967
|
if (quick) {
|
|
954
|
-
|
|
968
|
+
// "Never close" means never, approval toast or not.
|
|
969
|
+
setTimeout(function () {
|
|
970
|
+
if (policy === "never") return;
|
|
971
|
+
if (policy !== "always" && hidden()) return;
|
|
972
|
+
n.close();
|
|
973
|
+
}, 12000);
|
|
955
974
|
} else if (policy !== "never") {
|
|
956
975
|
setTimeout(function () { if (policy !== "always" && hidden()) return; n.close(); }, 5000);
|
|
957
976
|
}
|
|
@@ -1310,8 +1329,10 @@
|
|
|
1310
1329
|
if (type === "feishu" || type === "serverchan" || type === "wxpusher") {
|
|
1311
1330
|
// These answer 200 with a service code; a wrong token shows up there,
|
|
1312
1331
|
// not in the HTTP status. DingTalk does the same but cannot be reached
|
|
1313
|
-
// from a page at all, hence no branch for it.
|
|
1314
|
-
|
|
1332
|
+
// from a page at all, hence no branch for it. Anything else on a 2xx —
|
|
1333
|
+
// an empty body, a proxy or WAF HTML page — cannot confirm delivery,
|
|
1334
|
+
// so it is unverified rather than a success the user never got.
|
|
1335
|
+
if (!parsed || typeof parsed !== "object") return { status: "unverified", retry: false };
|
|
1315
1336
|
var code = parsed.code;
|
|
1316
1337
|
var okCode = type === "wxpusher" ? 1000 : 0;
|
|
1317
1338
|
if (code === okCode) return { status: "sent", retry: false };
|
|
@@ -1321,7 +1342,7 @@
|
|
|
1321
1342
|
return { status: "sent", retry: false };
|
|
1322
1343
|
}
|
|
1323
1344
|
// One attempt. Resolves to {status, retry}; never rejects.
|
|
1324
|
-
function postOnce(spec, plain) {
|
|
1345
|
+
function postOnce(spec, plain, type) {
|
|
1325
1346
|
var headers = {};
|
|
1326
1347
|
headers["Content-Type"] = plain ? spec.noCorsType : spec.contentType;
|
|
1327
1348
|
if (!plain) {
|
|
@@ -1339,11 +1360,11 @@
|
|
|
1339
1360
|
if (plain) return { status: "unverified", retry: false }; // opaque: delivered, reply unreadable
|
|
1340
1361
|
// Some hosts (and the smoke harness) hand back a response-like object
|
|
1341
1362
|
// without a body reader; the HTTP status is then all there is to judge.
|
|
1342
|
-
if (typeof res.text !== "function") return externalVerdict(
|
|
1363
|
+
if (typeof res.text !== "function") return externalVerdict(type, res, "");
|
|
1343
1364
|
return res.text().then(function (text) {
|
|
1344
|
-
return externalVerdict(
|
|
1365
|
+
return externalVerdict(type, res, text);
|
|
1345
1366
|
}, function () {
|
|
1346
|
-
return externalVerdict(
|
|
1367
|
+
return externalVerdict(type, res, "");
|
|
1347
1368
|
});
|
|
1348
1369
|
});
|
|
1349
1370
|
}
|
|
@@ -1363,11 +1384,11 @@
|
|
|
1363
1384
|
var built;
|
|
1364
1385
|
try { built = externalRequest(target, ev); } catch (e) { return Promise.resolve({ status: "failed (payload)", retry: false }); }
|
|
1365
1386
|
var spec = built.req;
|
|
1366
|
-
return postOnce(spec, false).catch(function (err) {
|
|
1387
|
+
return postOnce(spec, false, built.type).catch(function (err) {
|
|
1367
1388
|
var msg = "failed (" + (err && err.message ? err.message : String(err)) + ")";
|
|
1368
1389
|
// The browser refused the exchange (CORS or the network): the opaque
|
|
1369
1390
|
// path still gets the request out, only the reply is unreadable.
|
|
1370
|
-
return postOnce(spec, true).catch(function () {
|
|
1391
|
+
return postOnce(spec, true, built.type).catch(function () {
|
|
1371
1392
|
if (built.type !== "bark") return { status: msg, retry: true };
|
|
1372
1393
|
return barkGet(target.url, ev).then(null, function () { return { status: msg, retry: true }; });
|
|
1373
1394
|
});
|
|
@@ -1429,19 +1450,42 @@
|
|
|
1429
1450
|
// lockstep). A final failure is written to the dead-letter log — the alert
|
|
1430
1451
|
// itself was already shown locally, so this log is the only trace that the
|
|
1431
1452
|
// phone did not get it.
|
|
1432
|
-
|
|
1453
|
+
// Same target across two externalTargets() reads: the list is rebuilt from
|
|
1454
|
+
// the config on every call, so identity cannot be compared.
|
|
1455
|
+
function sameExternalTarget(a, b) {
|
|
1456
|
+
if (a.id && b.id) return a.id === b.id;
|
|
1457
|
+
return a.type === b.type && a.url === b.url;
|
|
1458
|
+
}
|
|
1459
|
+
function externalTargetStillWanted(target) {
|
|
1460
|
+
var list = externalTargets();
|
|
1461
|
+
for (var i = 0; i < list.length; i++) if (sameExternalTarget(list[i], target)) return true;
|
|
1462
|
+
return false;
|
|
1463
|
+
}
|
|
1464
|
+
function sendToTarget(target, ev, forced) {
|
|
1433
1465
|
var delays = externalRetryDelays();
|
|
1434
1466
|
var attempts = 0;
|
|
1467
|
+
// Switching forwarding off (or deleting / disabling the target) has to
|
|
1468
|
+
// stop a retry chain that is already asleep on a timer: without this the
|
|
1469
|
+
// browser kept posting to an endpoint the user had just turned off, and
|
|
1470
|
+
// logged the aborted delivery as a failure (`forced` marks the explicit
|
|
1471
|
+
// test button, which posts even while forwarding is off).
|
|
1472
|
+
function wanted() {
|
|
1473
|
+
if (!forced && !config.externalEnabled) return false;
|
|
1474
|
+
return externalTargetStillWanted(target);
|
|
1475
|
+
}
|
|
1435
1476
|
function run() {
|
|
1477
|
+
if (!wanted()) return Promise.resolve({ status: "cancelled" });
|
|
1436
1478
|
attempts++;
|
|
1437
1479
|
return deliverAttempt(target, ev).then(function (r) {
|
|
1438
1480
|
if (r.status === "sent" || r.status === "unverified") return r;
|
|
1439
1481
|
if (!r.retry || attempts > delays.length) return r;
|
|
1482
|
+
if (!wanted()) return { status: "cancelled" };
|
|
1440
1483
|
var wait = Math.round(delays[attempts - 1] * (1 + Math.random() * 0.25));
|
|
1441
1484
|
return new Promise(function (resolve) { setTimeout(function () { resolve(run()); }, wait); });
|
|
1442
1485
|
});
|
|
1443
1486
|
}
|
|
1444
1487
|
return run().then(function (r) {
|
|
1488
|
+
if (r.status === "cancelled") return r.status;
|
|
1445
1489
|
var failed = r.status.indexOf("failed") === 0;
|
|
1446
1490
|
recordExternalHealth(target.id, r.status, attempts, failed ? r.status.slice(7) : "");
|
|
1447
1491
|
if (failed) {
|
|
@@ -1473,9 +1517,9 @@
|
|
|
1473
1517
|
if (!config.externalEnabled) return;
|
|
1474
1518
|
if (kind === "attention" && !config.externalAttention) return;
|
|
1475
1519
|
if (kind === "done" && !config.externalDone) return;
|
|
1476
|
-
sendExternalToAll(kind, title, body, sessionId, onDone);
|
|
1520
|
+
sendExternalToAll(kind, title, body, sessionId, false, onDone);
|
|
1477
1521
|
}
|
|
1478
|
-
function sendExternalToAll(kind, title, body, sessionId, onDone) {
|
|
1522
|
+
function sendExternalToAll(kind, title, body, sessionId, forced, onDone) {
|
|
1479
1523
|
var targets = externalTargets();
|
|
1480
1524
|
if (!targets.length) { if (typeof onDone === "function") onDone([]); return; }
|
|
1481
1525
|
var ev = {
|
|
@@ -1487,7 +1531,7 @@
|
|
|
1487
1531
|
};
|
|
1488
1532
|
var ps = [];
|
|
1489
1533
|
for (var i = 0; i < targets.length; i++) {
|
|
1490
|
-
try { ps.push(sendToTarget(targets[i], ev)); } catch (e) { ps.push(Promise.resolve("failed (dispatch)")); }
|
|
1534
|
+
try { ps.push(sendToTarget(targets[i], ev, !!forced)); } catch (e) { ps.push(Promise.resolve("failed (dispatch)")); }
|
|
1491
1535
|
}
|
|
1492
1536
|
if (typeof onDone === "function") Promise.all(ps).then(onDone, function () {});
|
|
1493
1537
|
}
|
|
@@ -1575,16 +1619,18 @@
|
|
|
1575
1619
|
attentionKeysMarked[key] = true;
|
|
1576
1620
|
acquireTitleMark();
|
|
1577
1621
|
}
|
|
1578
|
-
function unmarkAttention(key) {
|
|
1622
|
+
function unmarkAttention(key, keepPending) {
|
|
1579
1623
|
delete quietedAttention[key]; // the wait is over; a queued alert dies with it
|
|
1580
1624
|
// A toast that still carries buttons for this wait dies with it too —
|
|
1581
1625
|
// otherwise a settled request would leave a clickable (but stale)
|
|
1582
|
-
// approval toast behind.
|
|
1583
|
-
//
|
|
1626
|
+
// approval toast behind. A test toast releases its title mark long before
|
|
1627
|
+
// its buttons are done being useful, so that call passes keepPending: the
|
|
1628
|
+
// record stays until the later unmark(), which closes the toast with it.
|
|
1629
|
+
// Without that the buttons went dead while the toast was still on screen.
|
|
1584
1630
|
var rec = pendingActions[key];
|
|
1585
|
-
if (rec) {
|
|
1631
|
+
if (rec && !(keepPending && rec.test)) {
|
|
1586
1632
|
delete pendingActions[key];
|
|
1587
|
-
|
|
1633
|
+
closeNotificationTag(rec.tag);
|
|
1588
1634
|
}
|
|
1589
1635
|
if (!attentionKeysMarked[key]) return;
|
|
1590
1636
|
delete attentionKeysMarked[key];
|
|
@@ -1636,12 +1682,9 @@
|
|
|
1636
1682
|
lastActivityAt = Date.now();
|
|
1637
1683
|
if (!idleTimer) armIdle();
|
|
1638
1684
|
}
|
|
1639
|
-
(
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
try { window.addEventListener(events[ai], noteActivity, { passive: true, capture: true }); } catch (e) {}
|
|
1643
|
-
}
|
|
1644
|
-
})();
|
|
1685
|
+
// Registered from the watchers effect (see apply below) so a client-plugin
|
|
1686
|
+
// reload removes the previous set instead of stacking another one.
|
|
1687
|
+
var ACTIVITY_EVENTS = ["pointerdown", "pointermove", "keydown", "wheel", "touchstart"];
|
|
1645
1688
|
function idleMinutes() {
|
|
1646
1689
|
var m = config && config.idleMinutes;
|
|
1647
1690
|
return (typeof m === "number" && isFinite(m) && m > 0) ? m : 0;
|
|
@@ -1880,9 +1923,12 @@
|
|
|
1880
1923
|
var quick = quickForTest(key);
|
|
1881
1924
|
deliver("attention", "DSH · " + d.kind.approval, d.testApproval, null, quick);
|
|
1882
1925
|
markAttention(key);
|
|
1883
|
-
// The title mark drops like every other test's, but the toast
|
|
1884
|
-
//
|
|
1885
|
-
|
|
1926
|
+
// The title mark drops like every other test's, but the toast outlives
|
|
1927
|
+
// it — its buttons are the very thing being tested. It gets the same
|
|
1928
|
+
// 12 s a real approval toast has on the constructor path, then the
|
|
1929
|
+
// record and the toast go together.
|
|
1930
|
+
setTimeout(function () { unmarkAttention(key, true); }, TEST_MARK_RELEASE_MS);
|
|
1931
|
+
setTimeout(function () { unmarkAttention(key); }, 12000);
|
|
1886
1932
|
return;
|
|
1887
1933
|
}
|
|
1888
1934
|
if (kind === "attention") {
|
|
@@ -2360,7 +2406,7 @@
|
|
|
2360
2406
|
});
|
|
2361
2407
|
} catch (e) {}
|
|
2362
2408
|
// keep in sync with package.json "version" on every release
|
|
2363
|
-
api.version = "1.14.
|
|
2409
|
+
api.version = "1.14.5";
|
|
2364
2410
|
api.setConfig = function (patch) { return setConfigLocal(patch); };
|
|
2365
2411
|
api.resetConfig = function () {
|
|
2366
2412
|
try {
|
|
@@ -2403,7 +2449,7 @@
|
|
|
2403
2449
|
var targets = externalTargets();
|
|
2404
2450
|
if (!targets.length) { resolve({ sent: 0, unverified: 0, failed: 0, statuses: [] }); return; }
|
|
2405
2451
|
var d = texts();
|
|
2406
|
-
sendExternalToAll("attention", d.testExternalTitle, d.testExternalBody, currentSessionId(), function (statuses) {
|
|
2452
|
+
sendExternalToAll("attention", d.testExternalTitle, d.testExternalBody, currentSessionId(), true, function (statuses) {
|
|
2407
2453
|
var out = { sent: 0, unverified: 0, failed: 0, statuses: statuses };
|
|
2408
2454
|
for (var i = 0; i < statuses.length; i++) {
|
|
2409
2455
|
if (statuses[i] === "sent") out.sent++;
|
|
@@ -2466,6 +2512,7 @@
|
|
|
2466
2512
|
desktop: isDesktopShell(),
|
|
2467
2513
|
raiseChannel: isDesktopShell() ? desktopRaiseChannel() : "window-focus",
|
|
2468
2514
|
raiseLast: raiseState.last,
|
|
2515
|
+
configStored: !configWriteFailed,
|
|
2469
2516
|
actionKeys: Object.keys(pendingActions),
|
|
2470
2517
|
permission: ("Notification" in window) ? Notification.permission : "n/a",
|
|
2471
2518
|
visibility: hidden() ? "hidden" : "visible",
|
|
@@ -2646,6 +2693,7 @@
|
|
|
2646
2693
|
testNoPermission: "通知权限还没给:先在页面上允许一次,再点测试。",
|
|
2647
2694
|
permHint: "通知权限尚未授予:先在页面上点击一次并允许通知,系统通知才能弹出(提示音不受影响)。",
|
|
2648
2695
|
offHint: "已关闭提醒:先打开「启用提醒」再测试。",
|
|
2696
|
+
storageFailed: "设置没能保存:浏览器拒绝了这次本地存储写入(空间不足或存储被禁用),改动只在当前页面有效,刷新即还原。",
|
|
2649
2697
|
versionLine: "插件版本:dsh-notify-me v"
|
|
2650
2698
|
};
|
|
2651
2699
|
var UI_en = {
|
|
@@ -2797,6 +2845,7 @@
|
|
|
2797
2845
|
testNoPermission: "Notification permission is not granted: allow it once from the page, then test again.",
|
|
2798
2846
|
permHint: "Notification permission is not granted yet — click once on the page and allow notifications so toasts can appear (sound is unaffected).",
|
|
2799
2847
|
offHint: "Reminders are off: enable them first, then test.",
|
|
2848
|
+
storageFailed: "Settings were not saved: the browser refused this local-storage write (quota or storage disabled), so the change lasts only for this page and is gone on reload.",
|
|
2800
2849
|
versionLine: "Plugin version: dsh-notify-me v"
|
|
2801
2850
|
};
|
|
2802
2851
|
// ─────────────────── sidebar row glyph ───────────────────────────
|
|
@@ -3277,7 +3326,11 @@
|
|
|
3277
3326
|
// A denied permission means showToast() returns before it tries
|
|
3278
3327
|
// anything and records no refusal; saying "sent" there would be the
|
|
3279
3328
|
// same lie issue #18 was about, one layer earlier.
|
|
3280
|
-
if (!canToast()) {
|
|
3329
|
+
if (!canToast()) {
|
|
3330
|
+
requestPermission(true);
|
|
3331
|
+
setFeedback(t("testNoPermission"));
|
|
3332
|
+
return;
|
|
3333
|
+
}
|
|
3281
3334
|
unlockOnce();
|
|
3282
3335
|
// Bypasses the visibility rules on purpose: a test must fire while the
|
|
3283
3336
|
// page is open, otherwise the button proves nothing.
|
|
@@ -3454,7 +3507,7 @@
|
|
|
3454
3507
|
if (!externalTargets().length) { setFeedback(t("externalNoTargets")); return; }
|
|
3455
3508
|
setFeedback(t("externalSending"));
|
|
3456
3509
|
var d = texts();
|
|
3457
|
-
sendExternalToAll("attention", d.testExternalTitle, d.testExternalBody, currentSessionId(), function (statuses) {
|
|
3510
|
+
sendExternalToAll("attention", d.testExternalTitle, d.testExternalBody, currentSessionId(), true, function (statuses) {
|
|
3458
3511
|
var s = 0, u = 0, f = 0;
|
|
3459
3512
|
for (var i = 0; i < statuses.length; i++) {
|
|
3460
3513
|
if (statuses[i] === "sent") s++;
|
|
@@ -3752,7 +3805,8 @@
|
|
|
3752
3805
|
] : null,
|
|
3753
3806
|
// Always-visible version line at the page foot: bug reports need it,
|
|
3754
3807
|
// and "which build am I on" should not require the console.
|
|
3755
|
-
h("p", { className: "dnm-hint" }, t("versionLine") + api.version)
|
|
3808
|
+
h("p", { className: "dnm-hint" }, t("versionLine") + api.version),
|
|
3809
|
+
configWriteFailed ? h("p", { className: "dnm-warn" }, t("storageFailed")) : null
|
|
3756
3810
|
]);
|
|
3757
3811
|
}
|
|
3758
3812
|
|
|
@@ -3828,6 +3882,14 @@
|
|
|
3828
3882
|
var onVisibility = function () { try { flushQuieted(); } catch (e) {} };
|
|
3829
3883
|
try { document.addEventListener("visibilitychange", onVisibility); } catch (e) {}
|
|
3830
3884
|
unsubs.push(function () { try { document.removeEventListener("visibilitychange", onVisibility); } catch (e) {} });
|
|
3885
|
+
for (var ai = 0; ai < ACTIVITY_EVENTS.length; ai++) {
|
|
3886
|
+
try { window.addEventListener(ACTIVITY_EVENTS[ai], noteActivity, { passive: true, capture: true }); } catch (e) {}
|
|
3887
|
+
}
|
|
3888
|
+
unsubs.push(function () {
|
|
3889
|
+
for (var ai = 0; ai < ACTIVITY_EVENTS.length; ai++) {
|
|
3890
|
+
try { window.removeEventListener(ACTIVITY_EVENTS[ai], noteActivity, { capture: true }); } catch (e) {}
|
|
3891
|
+
}
|
|
3892
|
+
});
|
|
3831
3893
|
// Same re-arm for the other half of "went away": losing window focus.
|
|
3832
3894
|
try { window.addEventListener("focus", onPageFocus); } catch (e) {}
|
|
3833
3895
|
try { window.addEventListener("blur", onPageBlur); } catch (e) {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-notify-me",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.5",
|
|
4
4
|
"description": "离开 DSH 页面也能收到提醒:需要你操作 / 后台回复完成时发系统通知、标题标记与提示音,支持审批快捷裁决与外部推送,Web 版与桌面版均可用。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"node": ">=18"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
|
-
"test": "node smoke/smoke-test.cjs && node smoke/cordis-host-test.mjs",
|
|
69
|
+
"test": "node smoke/smoke-test.cjs && node smoke/host-route-test.mjs && node smoke/cordis-host-test.mjs",
|
|
70
70
|
"pack": "npm pack --dry-run"
|
|
71
71
|
},
|
|
72
72
|
"publishConfig": {
|