@laraveladmin/dsh-stay-awake 0.2.13 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -0
- package/README.en.md +35 -11
- package/README.md +35 -11
- package/client.js +181 -30
- package/docs/REQUIREMENTS.md +35 -11
- package/docs/VERIFICATION.md +60 -0
- package/index.js +107 -1
- package/lib/auto-resume.js +95 -0
- package/lib/config.js +35 -0
- package/lib/probe.js +50 -0
- package/lib/resume.js +173 -0
- package/lib/server.js +22 -8
- package/lib/sound.js +19 -4
- package/lib/state.js +2 -1
- package/locale/en.json +1 -1
- package/locale/zh-Hant.json +6 -0
- package/locale/zh.json +1 -1
- package/market/index.json +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,64 @@
|
|
|
1
1
|
# 变更记录 · Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.0 — 2026-12-03
|
|
4
|
+
|
|
5
|
+
### 新功能:断网自动重试
|
|
6
|
+
|
|
7
|
+
- 合盖休眠导致正在跑的一轮断网失败后,网络恢复时**自动按下 DSH 的「重试」**:调用宿主
|
|
8
|
+
`sessionController.prompt` 发送空内容(`retry` 来源)消息重跑失败的那一步,不往对话里插文字、
|
|
9
|
+
不重放已完成的工具调用。
|
|
10
|
+
- 触发判定与 DSH 自己的可续跑语义一致:本轮有被接纳的人类输入、有一次失败的模型请求、以网络类错误
|
|
11
|
+
(默认 `TRANSPORT` / `TIMEOUT`)结束;用户中断、等待审批、限流/服务端错误不触发。
|
|
12
|
+
- 重试前用 **TCP 探测**(默认 `api.deepseek.com:443`,只建连不发数据)确认网络真的恢复;
|
|
13
|
+
宿主休眠时定时器暂停,唤醒后 Wi-Fi 未连通就继续等。
|
|
14
|
+
- 预算:每会话每次故障最多 3 次、60 分钟内有效;用户自己发消息或该轮成功完成会重置;子代理会话不处理。
|
|
15
|
+
- 弹层新增「断网自动重试」开关(默认开,持久化到 `state.json`),开关下方实时显示
|
|
16
|
+
「等待网络恢复… / 正在自动重试… / 自动重试未成功」,底部状态行提示「已自动重试」。
|
|
17
|
+
- 宿主协议升到 3;不再假设旧宿主可用:协议不匹配时弹层提示重新加载。
|
|
18
|
+
|
|
19
|
+
### 新功能:需要你回答时响一声
|
|
20
|
+
|
|
21
|
+
- agent 提问(`ask_user_question`)或工具调用等审批时立即响一声——这是唯一「回合还没结束也会响」的
|
|
22
|
+
提示音,否则它在你离开后会一直安静地等。监听宿主 waterfall 事件 `user-questions/request` 与
|
|
23
|
+
`approval/request`,旁路调用 `next()`,不干扰问答本身。
|
|
24
|
+
- 第三种音效:macOS `Ping`、Windows `SystemSounds.Question`、Linux `message.oga`,可自定义
|
|
25
|
+
`questionSound`;受同一个「提示音」总开关约束,1 秒节流防连响。
|
|
26
|
+
|
|
27
|
+
### 界面与多语言
|
|
28
|
+
|
|
29
|
+
- 弹层「完成提示音」改名「提示音」,旁边改为「完成 / 失败 / 提醒」三个小按钮,可分别试听三种音效
|
|
30
|
+
(宿主 `test-sound` 新增 `kind` 参数,未知值 400)。
|
|
31
|
+
- 新增**繁体中文**完整字典:DSH 只内置简体,插件通过 `ctx.locale.addLanguage` 贡献可选语言
|
|
32
|
+
「繁體中文」(id `zh-Hant`,回退 `zh`),并新增 `locale/zh-Hant.json` 供插件管理器显示;三套字典
|
|
33
|
+
各 54 键、键集合一致。
|
|
34
|
+
|
|
35
|
+
### 文档与测试
|
|
36
|
+
|
|
37
|
+
- README 中英新增「断网自动重试」「提示音(含提问提醒)」章节与繁体说明,并更正「不联网」表述:
|
|
38
|
+
唯一外发动作是探测,且可关闭。
|
|
39
|
+
- REQUIREMENTS 新增 FR-12 与 AC-21~24、FR-10.15~17;VERIFICATION 记录本轮验证范围与未验证项。
|
|
40
|
+
- 新增 28 项测试(失败判定状态机、探测、调度器、预算/窗口、开关、提问提醒、试听三音效),单测 81 → 109。
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## 0.2.14 — 2026-12-03
|
|
44
|
+
|
|
45
|
+
### 修复
|
|
46
|
+
|
|
47
|
+
- 0.2.13 把底部说明文字替换成反馈文案:高度不跳了,**宽度开始跳**——那行说明是面板里最宽的一行,
|
|
48
|
+
被换成短文案后 `width: max-content` 立刻收缩到次宽的行。现在说明文字始终留在流里(它决定面板宽度),
|
|
49
|
+
反馈改为绝对定位的浮层盖在它上面(`inset: 0`,不参与布局):说明 `opacity 1→0`(140ms),
|
|
50
|
+
浮层 `opacity 0→1` + `translateY(2px→0)`(160ms),2.5 秒后反向。弹层宽高全程不变。
|
|
51
|
+
- 浮层 `pointer-events: none`,不挡操作;`prefers-reduced-motion` 下取消过渡。
|
|
52
|
+
- 去掉「请求进行中」的全局禁用:以前一次开关点击会把整块面板(三个开关 + 试听 + 临时保持按钮)
|
|
53
|
+
同时置灰(`.dsa-button:disabled{opacity:.5}` / `.dsa-switch:disabled{opacity:.5}`),本地接口很快,
|
|
54
|
+
置灰只持续一两帧——所以看起来是「临时保持那块有时候闪一下」。现在飞行中的请求不再改变任何控件的
|
|
55
|
+
禁用态,只在回包后更新状态与底部反馈;语义禁用(宿主不可达、总开关关闭)保持不变。
|
|
56
|
+
|
|
57
|
+
### 测试
|
|
58
|
+
|
|
59
|
+
- 81 项单测/接线测试保持全绿;`node --check` 通过;中英字典键集合一致。
|
|
60
|
+
|
|
61
|
+
|
|
3
62
|
## 0.2.13 — 2026-12-03
|
|
4
63
|
|
|
5
64
|
### 优化
|
package/README.en.md
CHANGED
|
@@ -31,14 +31,27 @@ Most existing plugins equate "a task" with "a session in the running state". DSH
|
|
|
31
31
|
|
|
32
32
|
The rule is a pure function: `wanted = enabled && (agents + maintenance + jobs > 0)`. Exactly one system power assertion is held process-wide.
|
|
33
33
|
|
|
34
|
-
##
|
|
34
|
+
## Sounds
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
Three moments each get one cue, played on the machine that runs the DSH host — they reach you even when the window is minimised.
|
|
37
37
|
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
38
|
+
- **Done**: one chime per work segment (from work starting to everything finishing), including background jobs and multiple sessions. `Glass` by default.
|
|
39
|
+
- **Failed**: the turn ended with an error or an interrupt. `Basso` by default.
|
|
40
|
+
- **Your turn**: the agent asked a question (`ask_user_question`) or a tool call waits for approval — rings immediately. `Ping` by default. This is the only cue that can fire while the turn is still open; without it the agent would wait for you in silence.
|
|
41
|
+
- Segments shorter than 20 seconds stay silent; autonomous goal/scheduled rounds stay silent (questions and approvals still ring).
|
|
42
|
+
- The panel's **Sounds** master switch covers all three; three small buttons (Done / Error / Alert) audition each cue.
|
|
43
|
+
- Sound files, volume, the minimum duration and whether questions ring live in `cordis.patch.yml`.
|
|
44
|
+
|
|
45
|
+
## Retry after reconnect
|
|
46
|
+
|
|
47
|
+
A closed lid drops the connection under a running turn: DSH retries `TRANSPORT` / `TIMEOUT` five times with backoff, then stops and waits for you to press Retry. This feature **presses that button for you once the network is back**.
|
|
48
|
+
|
|
49
|
+
- **Trigger**: a turn ended with a network-class failure (default `TRANSPORT` / `TIMEOUT`) after you had sent input and a model request had actually been attempted. User aborts, approval waits, rate limits and server errors never trigger it.
|
|
50
|
+
- **When it fires**: every 15 seconds the plugin makes a **TCP connection probe** to `api.deepseek.com:443` — handshake only, no request data, no session content read. The retry happens on the first successful probe. Timers are suspended during host sleep, so after a wake it simply keeps waiting until Wi-Fi is really up.
|
|
51
|
+
- **How it retries**: exactly like the Retry button — an **empty `retry` message** re-runs the failed step. No text is injected into the conversation and completed tool calls are not replayed.
|
|
52
|
+
- **Budget**: at most **3** automatic retries per failure, valid for **60 minutes**. A message you send yourself, or a later successful turn, resets the budget. Subagent sessions are left alone (their parent owns the failure).
|
|
53
|
+
- **Off means off**: switching the panel toggle off clears the queue immediately; a host restart does not keep pending retries.
|
|
54
|
+
- **Dependency**: needs DSH's `sessionController` service (present in Desktop and Web). Without it the feature degrades silently — keep-awake and the sound keep working.
|
|
42
55
|
|
|
43
56
|
## Behaviour
|
|
44
57
|
|
|
@@ -157,13 +170,22 @@ Override the row by id in the profile's `cordis.patch.yml`:
|
|
|
157
170
|
reconcileSeconds: 60 # reconciliation interval, 0 = disabled
|
|
158
171
|
maxMaintenanceMinutes: 120 # longest a maintenance bracket may stay open
|
|
159
172
|
caffeinatePath: /usr/bin/caffeinate # macOS only, advanced override
|
|
160
|
-
sound: true #
|
|
173
|
+
sound: true # sounds master switch (panel toggle)
|
|
161
174
|
soundOnError: true # different sound for failures
|
|
162
175
|
soundMinSeconds: 20 # stay silent below this duration, 0 = always
|
|
163
176
|
soundOnlyUserTasks: true # ignore autonomous rounds
|
|
177
|
+
soundOnQuestion: true # ring when a question/approval waits (no separate toggle)
|
|
178
|
+
questionSound: '' # custom "your turn" sound file (absolute path)
|
|
164
179
|
soundVolume: 1 # 0-3, macOS/Linux
|
|
165
180
|
successSound: '' # custom completion file (absolute path)
|
|
166
181
|
errorSound: '' # custom failure file
|
|
182
|
+
autoResume: true # retry after reconnect (panel toggle)
|
|
183
|
+
autoResumeCodes: [TRANSPORT, TIMEOUT] # failure codes that trigger it
|
|
184
|
+
autoResumeProbeHost: api.deepseek.com # probe target (TCP, no data sent)
|
|
185
|
+
autoResumeProbePort: 443
|
|
186
|
+
autoResumeProbeIntervalMs: 15000 # probe interval
|
|
187
|
+
autoResumeWindowMinutes: 60 # how long a failure stays retryable
|
|
188
|
+
autoResumeMaxAttempts: 3 # automatic retries per failure
|
|
167
189
|
```
|
|
168
190
|
|
|
169
191
|
Invalid values fall back to their defaults with a warning; a bad config never blocks loading.
|
|
@@ -185,7 +207,8 @@ Clicking the icon or the "Stay awake" label opens a panel **above the status bar
|
|
|
185
207
|
|---|---|
|
|
186
208
|
| Enabled | Turning it off releases the assertion immediately |
|
|
187
209
|
| Allow display sleep | On = block system sleep only; off = keep the screen on too |
|
|
188
|
-
|
|
|
210
|
+
| Sounds | One cue when a task ends, fails, or needs your answer; three buttons audition each |
|
|
211
|
+
| Retry after reconnect | Retry the turn that failed offline once the network is back (on by default) |
|
|
189
212
|
| Hold for | 30 min / 2 h / cancel, for temporary keeps |
|
|
190
213
|
| Status block | Active sources, scope, backend, hold duration, error reason |
|
|
191
214
|
| Footer | Where advanced options live, source link, version |
|
|
@@ -232,12 +255,13 @@ systemd-inhibit --list
|
|
|
232
255
|
|
|
233
256
|
**Compatibility**: `package.json` declares `engines.dsh: >=0.2.0`, which the plugin market uses for its compatibility badge; older DSH versions are refused.
|
|
234
257
|
|
|
235
|
-
**Local writes**: exactly one state file, `~/.dsh/plugin-data/dsh-stay-awake/state.json` (the
|
|
258
|
+
**Local writes and network**: exactly one state file, `~/.dsh/plugin-data/dsh-stay-awake/state.json` (the panel preferences). It does not modify system power plans, request privileges, read session content, or use the network for update checks. The one outbound action is the **TCP reachability probe** (default `api.deepseek.com:443`, handshake only, no data) while Retry after reconnect is enabled; turning that toggle off stops it.
|
|
236
259
|
|
|
237
260
|
## Internationalization
|
|
238
261
|
|
|
239
|
-
- The
|
|
240
|
-
-
|
|
262
|
+
- The indicator and panel follow the active DSH locale with three complete dictionaries: **Simplified Chinese, Traditional Chinese and English**; other locales fall back to English.
|
|
263
|
+
- DSH ships Simplified Chinese only, so the plugin registers 「繁體中文」 through `ctx.locale.addLanguage` (id `zh-Hant`, falling back to `zh`): plugin copy becomes fully Traditional while the rest of the GUI falls back to Simplified and stays readable.
|
|
264
|
+
- The plugin manager title and description are localized as well (`locale/zh.json`, `locale/zh-Hant.json`, `locale/en.json`).
|
|
241
265
|
- Repository documentation: [简体中文](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/README.md) / [English](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/README.en.md).
|
|
242
266
|
|
|
243
267
|
## Development
|
package/README.md
CHANGED
|
@@ -31,14 +31,27 @@ DSH 跑长任务时你离开电脑,系统按空闲策略休眠:进程被挂
|
|
|
31
31
|
|
|
32
32
|
判定为纯函数:`wanted = enabled && (会话 + 维护期 + 后台任务 > 0)`。全局只持有一个系统电源断言。
|
|
33
33
|
|
|
34
|
-
##
|
|
34
|
+
## 提示音
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
三种时机各响一声,不用盯着屏幕——声音在**运行 DSH 的这台机器**上播放,窗口最小化也听得到。
|
|
37
37
|
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
38
|
+
- **完成**:一次「工作段」(从有工作到全部结束)结束时响一次,含后台任务与多会话。默认 `Glass`。
|
|
39
|
+
- **失败**:这一轮以错误/中断结束,默认 `Basso`。
|
|
40
|
+
- **需要你回答**:agent 用 `ask_user_question` 提问、或工具调用等审批时立刻响,默认 `Ping`——这是唯一一个「回合还没结束也响」的情况,否则它会一直安静地等你。
|
|
41
|
+
- 短于 20 秒的任务不响;goal/定时任务等自主轮次不响,避免连响(但提问/审批仍然会提醒你)。
|
|
42
|
+
- 弹层「提示音」总开关控制全部三种;旁边三个小按钮「完成 / 失败 / 提醒」可分别试听。
|
|
43
|
+
- 音效文件、音量、最短时长、是否提醒提问在 `cordis.patch.yml` 配置。
|
|
44
|
+
|
|
45
|
+
## 断网自动重试
|
|
46
|
+
|
|
47
|
+
合盖休眠会让正在跑的那一轮断网失败:DSH 自己会按 `TRANSPORT` / `TIMEOUT` 退避重试 5 次,仍失败就停下等你点「重试」。这个功能在**网络恢复后替你按下那个按钮**。
|
|
48
|
+
|
|
49
|
+
- **触发条件**:某一轮以网络类错误结束(默认 `TRANSPORT` / `TIMEOUT`),且这一轮有你发出的输入、也真的发起过模型请求。用户主动中断、等待审批、限流/服务端错误都不会触发。
|
|
50
|
+
- **生效时机**:每 15 秒对 `api.deepseek.com:443` 做一次 **TCP 连接探测**——只建连,不发任何数据、不读会话内容;通了才重试。宿主休眠时定时器本来就会暂停,唤醒后 Wi-Fi 还没连上就继续等。
|
|
51
|
+
- **重试方式**:等价于界面上的「重试」按钮——发一条**空内容的 retry 消息**重跑失败的那一步,不会往对话里塞文字,也不会重放已完成的工具调用。
|
|
52
|
+
- **上限**:每个会话每次故障最多自动重试 **3 次**、**60 分钟**内有效;你在这期间自己发了消息、或这一轮后来成功完成,计数就重置。子代理会话不处理(由父会话负责)。
|
|
53
|
+
- **关掉即取消**:关闭弹层里的开关会立即清空等待队列;宿主重启后不保留待重试队列。
|
|
54
|
+
- **依赖**:需要 DSH 的 `sessionController` 服务(桌面版与 Web 版都提供);拿不到时功能静默降级,不影响保活与提示音。
|
|
42
55
|
|
|
43
56
|
## 释放与自愈
|
|
44
57
|
|
|
@@ -158,13 +171,22 @@ DSH 默认不带任何索引源。添加本项目随 npm 包发布的索引文
|
|
|
158
171
|
reconcileSeconds: 60 # 对账间隔,0 = 关闭
|
|
159
172
|
maxMaintenanceMinutes: 120 # 维护期括号的最长有效期
|
|
160
173
|
caffeinatePath: /usr/bin/caffeinate # 仅 macOS,高级覆盖
|
|
161
|
-
sound: true #
|
|
174
|
+
sound: true # 提示音总开关(弹层开关)
|
|
162
175
|
soundOnError: true # 失败/中断用不同音效
|
|
163
176
|
soundMinSeconds: 20 # 短于该时长不响,0 = 都响
|
|
164
177
|
soundOnlyUserTasks: true # 只响用户发起的任务,自主轮次不响
|
|
178
|
+
soundOnQuestion: true # 提问/等待审批时提醒(默认开,无独立开关)
|
|
179
|
+
questionSound: '' # 自定义「提醒」音文件(绝对路径)
|
|
165
180
|
soundVolume: 1 # 0~3,macOS/Linux 生效
|
|
166
181
|
successSound: '' # 自定义完成音文件(绝对路径)
|
|
167
182
|
errorSound: '' # 自定义失败音文件
|
|
183
|
+
autoResume: true # 断网自动重试(弹层开关)
|
|
184
|
+
autoResumeCodes: [TRANSPORT, TIMEOUT] # 触发自动重试的失败码
|
|
185
|
+
autoResumeProbeHost: api.deepseek.com # 探测目标(TCP,不发送数据)
|
|
186
|
+
autoResumeProbePort: 443
|
|
187
|
+
autoResumeProbeIntervalMs: 15000 # 探测间隔
|
|
188
|
+
autoResumeWindowMinutes: 60 # 失败后多久内仍然自动重试
|
|
189
|
+
autoResumeMaxAttempts: 3 # 每次故障最多自动重试几次
|
|
168
190
|
```
|
|
169
191
|
|
|
170
192
|
非法值会回落到默认值并记一条 warning,不会导致插件加载失败。
|
|
@@ -186,7 +208,8 @@ DSH 默认不带任何索引源。添加本项目随 npm 包发布的索引文
|
|
|
186
208
|
|---|---|
|
|
187
209
|
| 总开关 | 关掉后立即释放断言,不再自动保持 |
|
|
188
210
|
| 允许屏幕休眠 | 开 = 只防系统休眠;关 = 连屏幕一起保持 |
|
|
189
|
-
|
|
|
211
|
+
| 提示音 | 完成 / 失败 / 需要你回答时各响一声;旁边三个按钮可分别试听 |
|
|
212
|
+
| 断网自动重试 | 网络恢复后自动重试因断网失败的那一轮(默认开) |
|
|
190
213
|
| 临时保持 | 30 分钟 / 2 小时 / 取消,用于临时不想让机器睡 |
|
|
191
214
|
| 状态区 | 活跃源、范围、后端、已持续时长、错误原因 |
|
|
192
215
|
| 底部 | 高级参数在哪改、源码链接、版本号 |
|
|
@@ -235,12 +258,13 @@ systemd-inhibit --list
|
|
|
235
258
|
|
|
236
259
|
**兼容性声明**:`package.json` 声明 `engines.dsh: >=0.2.0`,插件市场据此显示兼容性;低于该版本的 DSH 会被拒绝安装。
|
|
237
260
|
|
|
238
|
-
|
|
261
|
+
**本地写入与网络**:只写一个状态文件 `~/.dsh/plugin-data/dsh-stay-awake/state.json`(弹层里的偏好),不碰系统电源计划、不申请提权、不读取会话内容、不联网检查更新。唯一的外发动作是开启「断网自动重试」后对配置的主机做 **TCP 连接探测**(默认 `api.deepseek.com:443`,只建连、不发送任何数据);关掉该开关即停止。
|
|
239
262
|
|
|
240
263
|
## 多语言
|
|
241
264
|
|
|
242
|
-
-
|
|
243
|
-
-
|
|
265
|
+
- 状态栏指示器与弹层跟随 DSH 当前语言,内置**简体中文、繁體中文、英文**三套完整字典;其余语言回退到英文。
|
|
266
|
+
- DSH 本身只内置简体中文,因此插件通过 `ctx.locale.addLanguage` 注册了「繁體中文」(id `zh-Hant`,回退到 `zh`):选择它之后插件文案是完整繁体,DSH 其余界面回退简体,仍然可读。
|
|
267
|
+
- 插件管理器中的标题与说明同样提供三种语言(`locale/zh.json`、`locale/zh-Hant.json`、`locale/en.json`)。
|
|
244
268
|
- 仓库文档:[简体中文](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/README.md) / [English](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/README.en.md)。
|
|
245
269
|
|
|
246
270
|
## 开发
|
package/client.js
CHANGED
|
@@ -22,6 +22,8 @@ window.__ModuleLoader__.load({
|
|
|
22
22
|
const NPM_URL = `https://www.npmjs.com/package/${PACKAGE_NAME}/v/`
|
|
23
23
|
const POLL_MIN_MS = 3000
|
|
24
24
|
const POLL_MAX_MS = 60000
|
|
25
|
+
// Host protocol this client understands: 3 adds the auto-resume switch.
|
|
26
|
+
const PROTOCOL = 3
|
|
25
27
|
// A protection indicator must never claim "holding" while it cannot prove it.
|
|
26
28
|
const UNKNOWN_AFTER_FAILURES = 2
|
|
27
29
|
|
|
@@ -60,10 +62,19 @@ window.__ModuleLoader__.load({
|
|
|
60
62
|
'panel.hold30': '30 分钟',
|
|
61
63
|
'panel.hold120': '2 小时',
|
|
62
64
|
'panel.holdCancel': '取消',
|
|
63
|
-
'panel.sound': '
|
|
65
|
+
'panel.sound': '提示音',
|
|
64
66
|
'panel.testSound': '试听',
|
|
67
|
+
'panel.testSuccess': '完成',
|
|
68
|
+
'panel.testError': '失败',
|
|
69
|
+
'panel.testQuestion': '提醒',
|
|
65
70
|
'panel.testPlayed': '试听已播放',
|
|
66
71
|
'panel.testUnavailable': '试听失败:没有可用的播放器',
|
|
72
|
+
'panel.autoResume': '断网自动重试',
|
|
73
|
+
'panel.autoResumeHint': '网络恢复后自动重试因断网失败的那一轮',
|
|
74
|
+
'panel.resumeWaiting': '等待网络恢复…',
|
|
75
|
+
'panel.resumeRetrying': '正在自动重试…',
|
|
76
|
+
'panel.resumeFailed': '自动重试未成功',
|
|
77
|
+
'panel.resumeRetried': '已自动重试(网络已恢复)',
|
|
67
78
|
'panel.holdDisabled': '总开关关闭时无法临时保持',
|
|
68
79
|
'panel.holdLeft': '剩余',
|
|
69
80
|
'panel.saved': '已保存',
|
|
@@ -109,10 +120,19 @@ window.__ModuleLoader__.load({
|
|
|
109
120
|
'panel.hold30': '30 min',
|
|
110
121
|
'panel.hold120': '2 h',
|
|
111
122
|
'panel.holdCancel': 'Cancel',
|
|
112
|
-
'panel.sound': '
|
|
123
|
+
'panel.sound': 'Sounds',
|
|
113
124
|
'panel.testSound': 'Test',
|
|
125
|
+
'panel.testSuccess': 'Done',
|
|
126
|
+
'panel.testError': 'Error',
|
|
127
|
+
'panel.testQuestion': 'Alert',
|
|
114
128
|
'panel.testPlayed': 'Test sound played',
|
|
115
129
|
'panel.testUnavailable': 'Test failed: no player found',
|
|
130
|
+
'panel.autoResume': 'Retry after reconnect',
|
|
131
|
+
'panel.autoResumeHint': 'Retry the turn that failed offline once the network is back',
|
|
132
|
+
'panel.resumeWaiting': 'Waiting for the network…',
|
|
133
|
+
'panel.resumeRetrying': 'Retrying automatically…',
|
|
134
|
+
'panel.resumeFailed': 'Automatic retry did not go through',
|
|
135
|
+
'panel.resumeRetried': 'Retried after the network came back',
|
|
116
136
|
'panel.holdDisabled': 'Enable the plugin first to hold',
|
|
117
137
|
'panel.holdLeft': 'left',
|
|
118
138
|
'panel.saved': 'Saved',
|
|
@@ -123,6 +143,64 @@ window.__ModuleLoader__.load({
|
|
|
123
143
|
'panel.npm': 'View this version on npm',
|
|
124
144
|
}
|
|
125
145
|
|
|
146
|
+
const ZHT = {
|
|
147
|
+
'brand': '守夜',
|
|
148
|
+
'state.connecting': '連線中',
|
|
149
|
+
'state.idle': '未保持',
|
|
150
|
+
'state.releasing': '釋放中',
|
|
151
|
+
'state.holding': '保持中',
|
|
152
|
+
'state.failed': '異常',
|
|
153
|
+
'state.disabled': '已關閉',
|
|
154
|
+
'state.unknown': '狀態未知',
|
|
155
|
+
'detail.backend': '後端',
|
|
156
|
+
'detail.scope': '範圍',
|
|
157
|
+
'detail.sources': '作用中來源',
|
|
158
|
+
'detail.since': '已持續',
|
|
159
|
+
'detail.error': '原因',
|
|
160
|
+
'sources.agents': '會話',
|
|
161
|
+
'sources.maintenance': '維護',
|
|
162
|
+
'sources.jobs': '背景工作',
|
|
163
|
+
'scope.system': '僅系統',
|
|
164
|
+
'scope.display': '含螢幕',
|
|
165
|
+
'unit.none': '無',
|
|
166
|
+
'hint.unreachable': '無法連線宿主狀態服務,DSH 可能正在重新啟動',
|
|
167
|
+
'error.exited': '電源斷言被意外終止,正在重試',
|
|
168
|
+
'error.backend': '無法啟動電源斷言後端',
|
|
169
|
+
'error.unsupported': '目前平台沒有可用的電源後端',
|
|
170
|
+
'error.unknown': '電源斷言發生未知錯誤',
|
|
171
|
+
'backend.caffeinate': 'macOS 系統喚醒(caffeinate)',
|
|
172
|
+
'backend.setthreadexecutionstate': 'Windows 執行狀態鎖',
|
|
173
|
+
'backend.systemd-inhibit': 'systemd 抑制鎖',
|
|
174
|
+
'panel.enabled': '總開關',
|
|
175
|
+
'panel.allowDisplaySleep': '允許螢幕休眠',
|
|
176
|
+
'panel.allowDisplaySleepHint': '開啟後只防止系統休眠,螢幕依系統設定熄滅',
|
|
177
|
+
'panel.hold': '臨時保持',
|
|
178
|
+
'panel.hold30': '30 分鐘',
|
|
179
|
+
'panel.hold120': '2 小時',
|
|
180
|
+
'panel.holdCancel': '取消',
|
|
181
|
+
'panel.sound': '提示音',
|
|
182
|
+
'panel.testSound': '試聽',
|
|
183
|
+
'panel.testSuccess': '完成',
|
|
184
|
+
'panel.testError': '失敗',
|
|
185
|
+
'panel.testQuestion': '提醒',
|
|
186
|
+
'panel.testPlayed': '試聽已播放',
|
|
187
|
+
'panel.testUnavailable': '試聽失敗:沒有可用的播放程式',
|
|
188
|
+
'panel.autoResume': '斷網自動重試',
|
|
189
|
+
'panel.autoResumeHint': '網路恢復後自動重試因斷網失敗的那一輪',
|
|
190
|
+
'panel.resumeWaiting': '等待網路恢復…',
|
|
191
|
+
'panel.resumeRetrying': '正在自動重試…',
|
|
192
|
+
'panel.resumeFailed': '自動重試未成功',
|
|
193
|
+
'panel.resumeRetried': '已自動重試(網路已恢復)',
|
|
194
|
+
'panel.holdDisabled': '總開關關閉時無法臨時保持',
|
|
195
|
+
'panel.holdLeft': '剩餘',
|
|
196
|
+
'panel.saved': '已儲存',
|
|
197
|
+
'panel.saveFailed': '儲存失敗,請重試',
|
|
198
|
+
'panel.staleHost': '宿主端未載入最新版本:請在外掛頁面停用再啟用「守夜」,或重新啟動 DSH',
|
|
199
|
+
'panel.advanced': '防抖、兜底時長等進階參數在 profile 的 cordis.patch.yml 中設定',
|
|
200
|
+
'panel.repo': '開啟程式碼倉庫',
|
|
201
|
+
'panel.npm': '在 npm 查看此版本',
|
|
202
|
+
}
|
|
203
|
+
|
|
126
204
|
const CSS = `
|
|
127
205
|
.dsa-pill{box-sizing:border-box;border-radius:var(--dsw-radius-sm);max-width:100%;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:calc(var(--dsh-content-font-size-secondary,13px) - 1px);line-height:calc(20px + var(--dsh-content-font-delta-secondary,0px));font-variant-numeric:tabular-nums;white-space:nowrap;background:0 0;border:none;align-items:center;gap:6px;padding:1px 8px;display:inline-flex;cursor:pointer;anchor-name:--dsh-stay-awake-panel}
|
|
128
206
|
.dsa-pill[aria-expanded="true"]{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary)}
|
|
@@ -162,14 +240,26 @@ window.__ModuleLoader__.load({
|
|
|
162
240
|
.dsa-actions{display:flex;gap:6px;flex-wrap:wrap;margin-top:6px}
|
|
163
241
|
.dsa-button{border:0;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);border-radius:var(--dsw-radius-sm);padding:4px 10px;cursor:pointer;font:inherit;line-height:16px}
|
|
164
242
|
.dsa-button:active:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}
|
|
243
|
+
.dsa-choices{display:inline-flex;align-items:center;gap:2px;padding:2px;border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-bg-layer-2);flex:none}
|
|
244
|
+
.dsa-choice{border:0;background:0 0;border-radius:calc(var(--dsw-radius-sm) - 1px);padding:2px 6px;color:var(--dsw-alias-label-secondary);font:inherit;font-size:11px;line-height:14px;cursor:pointer}
|
|
245
|
+
@media (hover:hover){.dsa-choice:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}}
|
|
246
|
+
.dsa-choice:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
|
|
247
|
+
.dsa-choice:disabled{opacity:.5;cursor:default}
|
|
165
248
|
.dsa-button:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
166
249
|
.dsa-button:disabled{opacity:.5;cursor:default}
|
|
167
250
|
.dsa-button:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
|
|
168
251
|
.dsa-note{color:var(--dsw-alias-label-tertiary);margin-top:8px}
|
|
169
|
-
|
|
170
|
-
|
|
252
|
+
/* The hint stays in flow (it decides the panel width) and the transient notice
|
|
253
|
+
is layered on top of it: swapping the text instead resized the fit-content
|
|
254
|
+
panel, first in height, then in width. */
|
|
255
|
+
.dsa-status{position:relative;overflow:hidden}
|
|
256
|
+
.dsa-status-hint,.dsa-status-note{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
257
|
+
.dsa-status-hint{transition:opacity .14s ease}
|
|
258
|
+
.dsa-status-hint[data-hidden="true"]{opacity:0}
|
|
259
|
+
.dsa-status-note{position:absolute;inset:0;opacity:0;transform:translateY(2px);transition:opacity .16s ease,transform .16s ease;pointer-events:none}
|
|
260
|
+
.dsa-status-note[data-visible="true"]{opacity:1;transform:none}
|
|
171
261
|
.dsa-ok{color:var(--dsw-alias-label-secondary)}
|
|
172
|
-
@media (prefers-reduced-motion:reduce){.dsa-status{
|
|
262
|
+
@media (prefers-reduced-motion:reduce){.dsa-status-hint,.dsa-status-note{transition:none}}
|
|
173
263
|
.dsa-error{color:var(--dsw-alias-state-error-primary)}
|
|
174
264
|
.dsa-foot{display:flex;gap:10px;align-items:center;margin-top:14px;padding-top:10px;border-top:.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px}
|
|
175
265
|
.dsa-foot .dsa-grow{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
@@ -181,7 +271,7 @@ window.__ModuleLoader__.load({
|
|
|
181
271
|
`
|
|
182
272
|
|
|
183
273
|
function createStore() {
|
|
184
|
-
let state = { open: false, status: null, failures: 0,
|
|
274
|
+
let state = { open: false, status: null, failures: 0, notice: null, localeRevision: 0 }
|
|
185
275
|
const listeners = new Set()
|
|
186
276
|
const store = {
|
|
187
277
|
get: () => state,
|
|
@@ -277,6 +367,8 @@ window.__ModuleLoader__.load({
|
|
|
277
367
|
if (notice === null || notice === undefined || notice === 'stale') return null
|
|
278
368
|
if (notice === 'testPlayed') return { text: `\u2713 ${t('panel.testPlayed')}` }
|
|
279
369
|
if (notice === 'testUnavailable') return { text: t('panel.testUnavailable'), tone: 'error' }
|
|
370
|
+
if (notice === 'resumeRetried') return { text: `\u2713 ${t('panel.resumeRetried')}` }
|
|
371
|
+
if (notice === 'resumeFailed') return { text: t('panel.resumeFailed'), tone: 'error' }
|
|
280
372
|
if (notice === 'failed') {
|
|
281
373
|
return {
|
|
282
374
|
text: `${t('panel.saveFailed')}${snapshot.noticeStatus ? ` (${snapshot.noticeStatus})` : ''}`,
|
|
@@ -392,8 +484,9 @@ window.__ModuleLoader__.load({
|
|
|
392
484
|
const enabled = status === null ? true : status.enabled !== false
|
|
393
485
|
const allowDisplaySleep = (status === null ? 'system' : status.scope) === 'system'
|
|
394
486
|
const soundOn = status === null ? true : status.sound !== false
|
|
395
|
-
const
|
|
396
|
-
const
|
|
487
|
+
const autoResumeOn = status === null ? true : status.autoResume !== false
|
|
488
|
+
const resume = status !== null && status.resume !== null && typeof status.resume === 'object' ? status.resume : null
|
|
489
|
+
const staleHost = status !== null && status.protocol !== PROTOCOL
|
|
397
490
|
const counts = status && status.counts ? status.counts : { agents: 0, maintenance: 0, jobs: 0 }
|
|
398
491
|
const holdLeft = status && typeof status.manualUntil === 'number' && status.manualUntil > Date.now()
|
|
399
492
|
? status.manualUntil - Date.now()
|
|
@@ -419,6 +512,16 @@ window.__ModuleLoader__.load({
|
|
|
419
512
|
|
|
420
513
|
if (!open) return null
|
|
421
514
|
|
|
515
|
+
const resumeHint = resume === null
|
|
516
|
+
? t('panel.autoResumeHint')
|
|
517
|
+
: resume.state === 'waiting'
|
|
518
|
+
? t('panel.resumeWaiting')
|
|
519
|
+
: resume.state === 'retrying'
|
|
520
|
+
? t('panel.resumeRetrying')
|
|
521
|
+
: resume.state === 'failed'
|
|
522
|
+
? t('panel.resumeFailed')
|
|
523
|
+
: t('panel.autoResumeHint')
|
|
524
|
+
|
|
422
525
|
const backend = backendInfo(t, status)
|
|
423
526
|
const rows = [
|
|
424
527
|
[t('detail.sources'), `${t('sources.agents')} ${counts.agents ?? 0} · ${t('sources.maintenance')} ${counts.maintenance ?? 0} · ${t('sources.jobs')} ${counts.jobs ?? 0}`],
|
|
@@ -440,7 +543,7 @@ window.__ModuleLoader__.load({
|
|
|
440
543
|
role: 'switch',
|
|
441
544
|
'aria-checked': checked,
|
|
442
545
|
'aria-label': label,
|
|
443
|
-
disabled:
|
|
546
|
+
disabled: unreachable || extraDisabled,
|
|
444
547
|
onClick,
|
|
445
548
|
})
|
|
446
549
|
|
|
@@ -495,14 +598,35 @@ window.__ModuleLoader__.load({
|
|
|
495
598
|
'div',
|
|
496
599
|
{ className: 'dsa-row' },
|
|
497
600
|
h('span', { className: 'dsa-grow' }, t('panel.sound')),
|
|
498
|
-
h(
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
601
|
+
h(
|
|
602
|
+
'span',
|
|
603
|
+
{
|
|
604
|
+
className: 'dsa-choices',
|
|
605
|
+
role: 'group',
|
|
606
|
+
'aria-label': t('panel.testSound'),
|
|
607
|
+
title: t('panel.testSound'),
|
|
608
|
+
},
|
|
609
|
+
[['success', 'panel.testSuccess'], ['error', 'panel.testError'], ['question', 'panel.testQuestion']]
|
|
610
|
+
.map(([kind, key]) => h('button', {
|
|
611
|
+
key: kind,
|
|
612
|
+
type: 'button',
|
|
613
|
+
className: 'dsa-choice',
|
|
614
|
+
disabled: unreachable || staleHost,
|
|
615
|
+
title: `${t('panel.testSound')} · ${t(key)}`,
|
|
616
|
+
onClick: () => act({ action: 'test-sound', kind }),
|
|
617
|
+
}, t(key))),
|
|
618
|
+
),
|
|
504
619
|
switchOf(soundOn, () => act({ action: 'set-sound', enabled: !soundOn }), t('panel.sound')),
|
|
505
620
|
),
|
|
621
|
+
h(
|
|
622
|
+
'div',
|
|
623
|
+
{ className: 'dsa-row' },
|
|
624
|
+
h('span', { className: 'dsa-grow' },
|
|
625
|
+
h('div', null, t('panel.autoResume')),
|
|
626
|
+
h('div', { className: 'dsa-sub' }, resumeHint),
|
|
627
|
+
),
|
|
628
|
+
switchOf(autoResumeOn, () => act({ action: 'set-auto-resume', enabled: !autoResumeOn }), t('panel.autoResume'), staleHost),
|
|
629
|
+
),
|
|
506
630
|
),
|
|
507
631
|
h(
|
|
508
632
|
'div',
|
|
@@ -513,19 +637,19 @@ window.__ModuleLoader__.load({
|
|
|
513
637
|
{ className: 'dsa-actions' },
|
|
514
638
|
h('button', {
|
|
515
639
|
type: 'button', className: 'dsa-button',
|
|
516
|
-
disabled:
|
|
640
|
+
disabled: unreachable || !enabled,
|
|
517
641
|
title: enabled ? undefined : t('panel.holdDisabled'),
|
|
518
642
|
onClick: () => act({ action: 'hold', minutes: 30 }),
|
|
519
643
|
}, t('panel.hold30')),
|
|
520
644
|
h('button', {
|
|
521
645
|
type: 'button', className: 'dsa-button',
|
|
522
|
-
disabled:
|
|
646
|
+
disabled: unreachable || !enabled,
|
|
523
647
|
title: enabled ? undefined : t('panel.holdDisabled'),
|
|
524
648
|
onClick: () => act({ action: 'hold', minutes: 120 }),
|
|
525
649
|
}, t('panel.hold120')),
|
|
526
650
|
holdLeft === null ? null : h('button', {
|
|
527
651
|
type: 'button', className: 'dsa-button',
|
|
528
|
-
disabled:
|
|
652
|
+
disabled: unreachable,
|
|
529
653
|
onClick: () => act({ action: 'cancel-hold' }),
|
|
530
654
|
}, t('panel.holdCancel')),
|
|
531
655
|
),
|
|
@@ -534,14 +658,21 @@ window.__ModuleLoader__.load({
|
|
|
534
658
|
'div',
|
|
535
659
|
{ className: 'dsa-foot', key: 'foot' },
|
|
536
660
|
h('span', {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
661
|
+
className: 'dsa-grow dsa-status',
|
|
662
|
+
title: notice === null ? t('panel.advanced') : notice.text,
|
|
663
|
+
},
|
|
664
|
+
h('span', {
|
|
665
|
+
// Always in flow: it is the widest row in most panels, so keeping
|
|
666
|
+
// it mounted is what keeps the fit-content width steady.
|
|
667
|
+
className: 'dsa-status-hint',
|
|
668
|
+
'data-hidden': notice === null ? undefined : 'true',
|
|
669
|
+
}, t('panel.advanced')),
|
|
670
|
+
h('span', {
|
|
671
|
+
className: `dsa-status-note${notice === null ? '' : notice.tone === 'error' ? ' dsa-error' : ' dsa-ok'}`,
|
|
672
|
+
'data-visible': notice === null ? 'false' : 'true',
|
|
541
673
|
role: 'status',
|
|
542
674
|
'aria-live': 'polite',
|
|
543
|
-
|
|
544
|
-
}, notice === null ? t('panel.advanced') : notice.text),
|
|
675
|
+
}, notice === null ? '' : notice.text)),
|
|
545
676
|
h('a', {
|
|
546
677
|
className: 'dsa-icon-link',
|
|
547
678
|
href: REPO_URL,
|
|
@@ -571,12 +702,25 @@ window.__ModuleLoader__.load({
|
|
|
571
702
|
apply(ctx) {
|
|
572
703
|
const t = ctx.locale.bind(NS)
|
|
573
704
|
|
|
705
|
+
// DSH ships Simplified Chinese but not Traditional; a language pack may
|
|
706
|
+
// extend the catalog. Falling back to `zh` means the rest of the GUI
|
|
707
|
+
// stays readable, and only this plugin's copy switches to 繁體中文.
|
|
708
|
+
ctx.effect(() => {
|
|
709
|
+
try {
|
|
710
|
+
return ctx.locale.addLanguage({ id: 'zh-Hant', label: '繁體中文', fallback: 'zh' })
|
|
711
|
+
} catch {
|
|
712
|
+
// Already contributed (another language pack, or a reload): the
|
|
713
|
+
// dictionary registration below is what actually matters.
|
|
714
|
+
return () => {}
|
|
715
|
+
}
|
|
716
|
+
}, 'stay-awake: zh-Hant language')
|
|
717
|
+
|
|
574
718
|
ctx.effect(() => {
|
|
575
719
|
const disposers = []
|
|
576
720
|
try {
|
|
577
|
-
disposers.push(ctx.locale.register(NS, { zh: ZH, en: EN }))
|
|
721
|
+
disposers.push(ctx.locale.register(NS, { zh: ZH, en: EN, 'zh-Hant': ZHT }))
|
|
578
722
|
} catch {
|
|
579
|
-
for (const [locale, dict] of [['zh', ZH], ['en', EN]]) {
|
|
723
|
+
for (const [locale, dict] of [['zh', ZH], ['en', EN], ['zh-Hant', ZHT]]) {
|
|
580
724
|
try {
|
|
581
725
|
disposers.push(ctx.locale.register(NS, locale, dict))
|
|
582
726
|
} catch {
|
|
@@ -630,8 +774,17 @@ window.__ModuleLoader__.load({
|
|
|
630
774
|
const value = await response.json()
|
|
631
775
|
if (cancelled) return
|
|
632
776
|
delay = POLL_MIN_MS
|
|
633
|
-
const
|
|
777
|
+
const before = store.get().status
|
|
778
|
+
const clearStale = store.get().notice === 'stale' && value.protocol === PROTOCOL
|
|
634
779
|
store.set({ status: value, failures: 0, ...(clearStale ? { notice: null, noticeStatus: null } : {}) })
|
|
780
|
+
// The host performs the retry on its own clock, so the only way
|
|
781
|
+
// to report it is a transition between two polls.
|
|
782
|
+
const was = before && before.resume ? before.resume : null
|
|
783
|
+
const now = value && value.resume ? value.resume : null
|
|
784
|
+
if (was !== null && now !== null && was.state !== now.state) {
|
|
785
|
+
if (was.state !== 'retrying' && now.state === 'idle' && now.retries > was.retries) flashNotice('resumeRetried', null)
|
|
786
|
+
else if (was.state !== 'failed' && now.state === 'failed') flashNotice('resumeFailed', null)
|
|
787
|
+
}
|
|
635
788
|
} catch {
|
|
636
789
|
if (cancelled) return
|
|
637
790
|
delay = Math.min(Math.max(delay * 2, POLL_MIN_MS), POLL_MAX_MS)
|
|
@@ -683,7 +836,6 @@ window.__ModuleLoader__.load({
|
|
|
683
836
|
}
|
|
684
837
|
|
|
685
838
|
async function act(body) {
|
|
686
|
-
store.set({ busy: true, notice: null, noticeStatus: null })
|
|
687
839
|
let statusCode = 'network'
|
|
688
840
|
try {
|
|
689
841
|
const response = await globalThis.fetch(ROUTE, {
|
|
@@ -703,11 +855,10 @@ window.__ModuleLoader__.load({
|
|
|
703
855
|
throw new Error(reason === 'invalid-action' ? 'stale-host' : `HTTP ${response.status}`)
|
|
704
856
|
}
|
|
705
857
|
const value = await response.json()
|
|
706
|
-
store.set({ status: value, failures: 0
|
|
858
|
+
store.set({ status: value, failures: 0 })
|
|
707
859
|
flashNotice(noticeFor(body, value), null)
|
|
708
860
|
} catch (error) {
|
|
709
861
|
const stale = error instanceof Error && error.message === 'stale-host'
|
|
710
|
-
store.set({ busy: false })
|
|
711
862
|
flashNotice(stale ? 'stale' : 'failed', statusCode)
|
|
712
863
|
}
|
|
713
864
|
}
|