dsh-powertoys 0.4.0 → 0.5.1
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/README.md +26 -1
- package/lib/client.js +768 -3
- package/lib/index.js +264 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-powertoys
|
|
2
2
|
|
|
3
|
-
**DSH PowerToys** — 模块化的 DeepSeek Harness
|
|
3
|
+
**DSH PowerToys** — 模块化的 DeepSeek Harness 工作台小工具集,解决长任务跑起来之后最常见的六个痛点。所有模块均可在 **设置 → DSH PowerToys** 中独立开启或关闭,改动即时生效,无需刷新页面。
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
| **会话内查找** (`find`) | 头部放大镜按钮 / 快捷键 | 页内高亮、实时计数、上下跳转,默认只搜当前会话可见正文 |
|
|
12
12
|
| **刷新页面按钮** (`reload`) | 会话头部刷新按钮 | 一键重载界面,装卸或修改插件后不必重启 DSH |
|
|
13
13
|
| **需要确认时重复提醒** (`alert`) | 设置 → DSH PowerToys | 审批或提问弹窗出现后按间隔反复响铃,处理后自动停;支持自定义音效 |
|
|
14
|
+
| **本轮结束提醒与自动关机** (`turnEnd`) | 设置 → DSH PowerToys | 本轮输出全部完成后响铃(可设置重复),并可在本轮结束后关机 |
|
|
14
15
|
|
|
15
16
|
## 界面预览
|
|
16
17
|
|
|
@@ -76,6 +77,27 @@ AI 刚生成了截图、构建产物或日志,想直接拖给别人或用外
|
|
|
76
77
|
|
|
77
78
|
新增、卸载或改名插件后,页面里缓存的插件清单还是旧的。点会话头部最右侧的圆形箭头即可重载界面,不必关掉重开整个 DSH。
|
|
78
79
|
|
|
80
|
+
### 6. 本轮结束提醒与自动关机:跑完不用守着
|
|
81
|
+
|
|
82
|
+
长任务真正的痛点是「跑完了我不知道」。盯着屏幕等浪费注意力,走开又可能几小时后才想起来。
|
|
83
|
+
|
|
84
|
+
在 **设置 → DSH PowerToys** 的「本轮结束提醒与自动关机」模块里,可以提前给**下一轮**布置两个任务,本轮输出全部完成后执行:
|
|
85
|
+
|
|
86
|
+
| 设置项 | 说明 |
|
|
87
|
+
|---|---|
|
|
88
|
+
| **本轮结束后提醒** | 非持久化单次开关:全部运行中会话完成后弹出闹铃并自动复位,点击弹窗按钮立即停铃 |
|
|
89
|
+
| **响过一次后继续重复** | 默认开启,像闹铃一样按间隔反复响直到点击弹窗停止;关闭则只响一次 |
|
|
90
|
+
| **重复间隔** | 3–600 秒,默认 15 秒;仅在开启重复时生效 |
|
|
91
|
+
| **最长重复** | 默认 600 秒,0 表示一直响直到手动点停 |
|
|
92
|
+
| **本轮结束后关机** | 非持久化单次开关:全部运行中会话完成后触发延迟关机并自动复位,弹出倒计时窗口可一键取消 |
|
|
93
|
+
| **关机延迟** | 10–3600 秒,默认 60 秒;留出反悔倒计时窗口,也可在终端运行 `shutdown /a` 取消 |
|
|
94
|
+
|
|
95
|
+
两个开关**都不落盘**,也不跨轮次保留:页面刷新或触发一次即自动复位;开启待命后主界面右下角会显示轻量待命条(可一键取消),多会话同时运行时会等全部运行中会话结束再触发,避免支线提问提前误触。
|
|
96
|
+
|
|
97
|
+
关机只在 Windows 上实现;其他平台点开只会得到「unsupported-platform」提示,不会执行任何命令。
|
|
98
|
+
|
|
99
|
+
如果只想确认功能是否装好、不想让机器真的关掉,启动 DSH 前设置环境变量 `DSH_POWERTOYS_NO_SHUTDOWN=1`:关机会变成纯预览,接口会返回它本来要执行的参数,其余功能全部照常。
|
|
100
|
+
|
|
79
101
|
## 安装
|
|
80
102
|
|
|
81
103
|
本插件为纯 JavaScript、零外部依赖、无构建步骤,按使用方式任选一种即可。
|
|
@@ -159,6 +181,9 @@ New-Item -ItemType Junction `
|
|
|
159
181
|
|
|
160
182
|
- 会话内查找只覆盖当前已加载到页面的消息;查找更早历史时,先向上滚动加载。
|
|
161
183
|
- 子代理内部的耗时不并入父会话统计,父会话仅计入该次调用跨度。
|
|
184
|
+
- 本轮结束提醒判断的是「会话从运行态回到空闲态」,因此被取消或失败的一轮同样会触发。
|
|
185
|
+
- 自动关机仅 Windows 可用,且延迟不少于 10 秒;触发前可用 `shutdown /a` 撤销。
|
|
186
|
+
- 关机会真的执行,不会二次确认。不确定时先用 `DSH_POWERTOYS_NO_SHUTDOWN=1` 试一遍。
|
|
162
187
|
|
|
163
188
|
## 开发文档
|
|
164
189
|
|
package/lib/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* dsh-powertoys — browser half.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Six PowerToys-style modular utilities, one package, each toggleable live
|
|
5
5
|
* from Settings → DSH PowerToys without a page reload:
|
|
6
6
|
* 1. 会话耗时徽章 (`duration`, header utilities) — reads the host
|
|
7
7
|
* `powertoysStats` projection, with a window fold as fallback.
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
* which is the only way to pick up a changed plugin manifest.
|
|
16
16
|
* 5. 需要确认时重复提醒 (`alert`, shell.overlay) — repeats an audible alert
|
|
17
17
|
* while any session has a pending approval or user-question prompt.
|
|
18
|
+
* 6. 本轮结束提醒与自动关机 (`turnEnd`, shell.overlay) — non-persistent one-shot
|
|
19
|
+
* completion alarm (click popup to stop) and delayed Windows auto-shutdown
|
|
20
|
+
* with live countdown and one-click cancel.
|
|
18
21
|
*
|
|
19
22
|
* Nothing here imports anything: the shipped client bundle runs each plugin
|
|
20
23
|
* inside `window.__ModuleLoader__.load`, where only `require` for a fixed set
|
|
@@ -32,6 +35,7 @@ window.__ModuleLoader__.load({
|
|
|
32
35
|
const FIND_BAR_ID = 'powertoys:find-bar'
|
|
33
36
|
const RELOAD_ID = 'powertoys:reload'
|
|
34
37
|
const ALERT_ID = 'powertoys:alert'
|
|
38
|
+
const TURNEND_ID = 'powertoys:turnend'
|
|
35
39
|
const STYLE_ID = 'dsh-powertoys-style'
|
|
36
40
|
const PANEL_ID = 'dsh-powertoys-panel'
|
|
37
41
|
const FIND_OPEN_EVENT = 'dsh-powertoys:find-open'
|
|
@@ -91,6 +95,13 @@ window.__ModuleLoader__.load({
|
|
|
91
95
|
description: '审批弹窗或提问弹窗出现后,按设定间隔循环播放提示音直到处理完成,避免错过确认。',
|
|
92
96
|
defaultEnabled: true,
|
|
93
97
|
},
|
|
98
|
+
{
|
|
99
|
+
id: 'turnEnd',
|
|
100
|
+
slotId: TURNEND_ID,
|
|
101
|
+
title: '本轮结束提醒与自动关机',
|
|
102
|
+
description: '本轮输出全部完成后响一次,并可设置隔几秒重复提醒;也可让机器在本轮结束后关机。每次触发后自动关闭,需手动再次开启。',
|
|
103
|
+
defaultEnabled: true,
|
|
104
|
+
},
|
|
94
105
|
]
|
|
95
106
|
|
|
96
107
|
const DEFAULT_FEATURES = Object.fromEntries(
|
|
@@ -433,6 +444,89 @@ window.__ModuleLoader__.load({
|
|
|
433
444
|
color: var(--dsw-alias-label-secondary, rgba(233,233,236,.52));
|
|
434
445
|
font-size: 11.5px;
|
|
435
446
|
}
|
|
447
|
+
.dsh-powertoys-toast-stack {
|
|
448
|
+
position: fixed; right: 20px; bottom: 20px; z-index: 600;
|
|
449
|
+
display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
|
|
450
|
+
pointer-events: none;
|
|
451
|
+
font-family: inherit;
|
|
452
|
+
}
|
|
453
|
+
.dsh-powertoys-armed-pill {
|
|
454
|
+
pointer-events: auto;
|
|
455
|
+
display: inline-flex; align-items: center; gap: 8px;
|
|
456
|
+
padding: 6px 10px 6px 12px; border-radius: 999px;
|
|
457
|
+
background: var(--dsw-alias-bg-layer-2, rgba(28,28,32,.94));
|
|
458
|
+
border: 1px solid var(--dsw-alias-border-secondary, rgba(128,128,128,.35));
|
|
459
|
+
color: var(--dsw-alias-label-primary, #ececef);
|
|
460
|
+
box-shadow: 0 8px 24px rgba(0,0,0,.22);
|
|
461
|
+
backdrop-filter: blur(10px);
|
|
462
|
+
font-size: 12px; line-height: 1.3;
|
|
463
|
+
}
|
|
464
|
+
.dsh-powertoys-armed-pill[data-danger="true"] {
|
|
465
|
+
border-color: rgba(239, 108, 68, .65);
|
|
466
|
+
}
|
|
467
|
+
.dsh-powertoys-armed-dot {
|
|
468
|
+
width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto;
|
|
469
|
+
background: var(--dsw-alias-brand-primary, #4f8cff);
|
|
470
|
+
}
|
|
471
|
+
.dsh-powertoys-armed-pill[data-danger="true"] .dsh-powertoys-armed-dot {
|
|
472
|
+
background: #ef6c44;
|
|
473
|
+
}
|
|
474
|
+
.dsh-powertoys-pill-close {
|
|
475
|
+
border: 0; background: transparent; color: inherit; cursor: pointer;
|
|
476
|
+
padding: 2px 5px; border-radius: 999px; font-size: 13px; line-height: 1; opacity: .72;
|
|
477
|
+
}
|
|
478
|
+
.dsh-powertoys-pill-close:hover { opacity: 1; background: rgba(128,128,128,.2); }
|
|
479
|
+
.dsh-powertoys-alarm-card {
|
|
480
|
+
pointer-events: auto;
|
|
481
|
+
width: 340px; max-width: calc(100vw - 32px);
|
|
482
|
+
padding: 14px 16px; border-radius: 12px;
|
|
483
|
+
background: var(--dsw-alias-bg-layer-2, rgba(26,26,30,.97));
|
|
484
|
+
border: 1.5px solid var(--dsw-alias-brand-primary, #4f8cff);
|
|
485
|
+
color: var(--dsw-alias-label-primary, #f0f0f3);
|
|
486
|
+
box-shadow: 0 14px 40px rgba(0,0,0,.32);
|
|
487
|
+
backdrop-filter: blur(12px);
|
|
488
|
+
display: flex; flex-direction: column; gap: 10px;
|
|
489
|
+
}
|
|
490
|
+
.dsh-powertoys-alarm-card[data-kind="shutdown"] {
|
|
491
|
+
border-color: #e5534b;
|
|
492
|
+
}
|
|
493
|
+
.dsh-powertoys-alarm-card[data-kind="dryrun"] {
|
|
494
|
+
border-color: var(--dsw-alias-border-secondary, rgba(128,128,128,.45));
|
|
495
|
+
}
|
|
496
|
+
.dsh-powertoys-alarm-head {
|
|
497
|
+
display: flex; align-items: center; justify-content: space-between; gap: 8px;
|
|
498
|
+
}
|
|
499
|
+
.dsh-powertoys-alarm-title {
|
|
500
|
+
font-size: 14px; font-weight: 700; line-height: 1.3;
|
|
501
|
+
}
|
|
502
|
+
.dsh-powertoys-alarm-badge {
|
|
503
|
+
font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
|
|
504
|
+
background: rgba(79, 140, 255, .16); color: var(--dsw-alias-brand-primary, #6ea3ff);
|
|
505
|
+
font-variant-numeric: tabular-nums;
|
|
506
|
+
}
|
|
507
|
+
.dsh-powertoys-alarm-card[data-kind="shutdown"] .dsh-powertoys-alarm-badge {
|
|
508
|
+
background: rgba(229, 83, 75, .18); color: #ff7b72;
|
|
509
|
+
}
|
|
510
|
+
.dsh-powertoys-alarm-desc {
|
|
511
|
+
font-size: 12.5px; line-height: 1.5;
|
|
512
|
+
color: var(--dsw-alias-label-secondary, rgba(233,233,236,.78));
|
|
513
|
+
word-break: break-word;
|
|
514
|
+
}
|
|
515
|
+
.dsh-powertoys-alarm-actions {
|
|
516
|
+
display: flex; align-items: center; justify-content: flex-end; gap: 8px;
|
|
517
|
+
}
|
|
518
|
+
.dsh-powertoys-alarm-btn {
|
|
519
|
+
padding: 6px 14px; border-radius: 8px; border: 0; cursor: pointer;
|
|
520
|
+
font: inherit; font-size: 12.5px; font-weight: 600;
|
|
521
|
+
background: var(--dsw-alias-brand-primary, #4f8cff); color: #fff;
|
|
522
|
+
}
|
|
523
|
+
.dsh-powertoys-alarm-btn:hover { filter: brightness(1.08); }
|
|
524
|
+
.dsh-powertoys-alarm-btn[data-danger="true"] { background: #d9433b; }
|
|
525
|
+
.dsh-powertoys-alarm-btn[data-secondary="true"] {
|
|
526
|
+
background: var(--dsw-alias-bg-layer-3, rgba(128,128,128,.22));
|
|
527
|
+
color: inherit;
|
|
528
|
+
}
|
|
529
|
+
.dsh-powertoys-alarm-btn[disabled] { opacity: .5; cursor: default; }
|
|
436
530
|
`
|
|
437
531
|
|
|
438
532
|
function ensureStyle() {
|
|
@@ -1519,6 +1613,142 @@ window.__ModuleLoader__.load({
|
|
|
1519
1613
|
function resetAllConfig() {
|
|
1520
1614
|
featureStore.reset({ syncNotify: false })
|
|
1521
1615
|
notifyStore.reset({ syncFeatures: false })
|
|
1616
|
+
// One-shot intents are not persisted, but "恢复默认" must also drop an
|
|
1617
|
+
// armed switch: leaving the machine set to power off after a reset would
|
|
1618
|
+
// be the worst possible surprise.
|
|
1619
|
+
turnEndStore.reset()
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
/* ------------------------------------------------------------------ *
|
|
1623
|
+
* Turn-end one-shot intents
|
|
1624
|
+
*
|
|
1625
|
+
* Two switches act exactly once, when the AI finishes its whole reply:
|
|
1626
|
+
* ring a reminder (optionally repeating), and/or shut the machine down.
|
|
1627
|
+
*
|
|
1628
|
+
* Both are ARMED BY HAND, EVERY TURN. Nothing here reaches localStorage:
|
|
1629
|
+
* an arming that survived a restart would mean the next session shuts the
|
|
1630
|
+
* machine down because of a click made days ago. The store lives in module
|
|
1631
|
+
* scope, so it survives a hot reload of the components that read it and
|
|
1632
|
+
* dies with the page — the lifetime a one-shot intent should have.
|
|
1633
|
+
*
|
|
1634
|
+
* Firing disarms. That is the contract the user asked for: after one
|
|
1635
|
+
* trigger you must switch it back on yourself.
|
|
1636
|
+
* ------------------------------------------------------------------ */
|
|
1637
|
+
|
|
1638
|
+
const DEFAULT_TURN_END = {
|
|
1639
|
+
alertArmed: false,
|
|
1640
|
+
alertRepeat: true,
|
|
1641
|
+
alertIntervalSec: 15,
|
|
1642
|
+
alertMaxSeconds: 600,
|
|
1643
|
+
shutdownArmed: false,
|
|
1644
|
+
shutdownDelaySec: 60,
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
function sanitizeTurnEnd(raw) {
|
|
1648
|
+
const out = { ...DEFAULT_TURN_END }
|
|
1649
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return out
|
|
1650
|
+
if (typeof raw.alertArmed === 'boolean') out.alertArmed = raw.alertArmed
|
|
1651
|
+
if (typeof raw.alertRepeat === 'boolean') out.alertRepeat = raw.alertRepeat
|
|
1652
|
+
if (Number.isFinite(raw.alertIntervalSec)) {
|
|
1653
|
+
out.alertIntervalSec = Math.min(600, Math.max(3, Math.round(raw.alertIntervalSec)))
|
|
1654
|
+
}
|
|
1655
|
+
if (Number.isFinite(raw.alertMaxSeconds)) {
|
|
1656
|
+
out.alertMaxSeconds = Math.min(7200, Math.max(0, Math.round(raw.alertMaxSeconds)))
|
|
1657
|
+
}
|
|
1658
|
+
if (typeof raw.shutdownArmed === 'boolean') out.shutdownArmed = raw.shutdownArmed
|
|
1659
|
+
if (Number.isFinite(raw.shutdownDelaySec)) {
|
|
1660
|
+
out.shutdownDelaySec = Math.min(3600, Math.max(10, Math.round(raw.shutdownDelaySec)))
|
|
1661
|
+
}
|
|
1662
|
+
return out
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
function createTurnEndStore() {
|
|
1666
|
+
let value = { ...DEFAULT_TURN_END }
|
|
1667
|
+
let busy = ''
|
|
1668
|
+
let notice = { tone: '', text: '' }
|
|
1669
|
+
let alarm = null
|
|
1670
|
+
let shutdown = null
|
|
1671
|
+
const listeners = new Set()
|
|
1672
|
+
const emit = () => {
|
|
1673
|
+
for (const listener of [...listeners]) listener()
|
|
1674
|
+
}
|
|
1675
|
+
return {
|
|
1676
|
+
getSnapshot: () => ({ value, busy, notice, alarm, shutdown }),
|
|
1677
|
+
subscribe(listener) {
|
|
1678
|
+
listeners.add(listener)
|
|
1679
|
+
return () => listeners.delete(listener)
|
|
1680
|
+
},
|
|
1681
|
+
set(patch) {
|
|
1682
|
+
value = sanitizeTurnEnd({ ...value, ...patch })
|
|
1683
|
+
emit()
|
|
1684
|
+
},
|
|
1685
|
+
/** Set the transient "正在请求…" label and the last result line. */
|
|
1686
|
+
setStatus(nextBusy, nextNotice) {
|
|
1687
|
+
busy = nextBusy
|
|
1688
|
+
if (nextNotice !== undefined) notice = nextNotice
|
|
1689
|
+
emit()
|
|
1690
|
+
},
|
|
1691
|
+
/** Disarm after a fire or manual cancel; keep the parameters the user chose. */
|
|
1692
|
+
disarm(which) {
|
|
1693
|
+
if (which === 'all') {
|
|
1694
|
+
if (!value.alertArmed && !value.shutdownArmed) return
|
|
1695
|
+
value = { ...value, alertArmed: false, shutdownArmed: false }
|
|
1696
|
+
emit()
|
|
1697
|
+
return
|
|
1698
|
+
}
|
|
1699
|
+
if (which === 'alert' && !value.alertArmed) return
|
|
1700
|
+
if (which === 'shutdown' && !value.shutdownArmed) return
|
|
1701
|
+
value = which === 'alert'
|
|
1702
|
+
? { ...value, alertArmed: false }
|
|
1703
|
+
: { ...value, shutdownArmed: false }
|
|
1704
|
+
emit()
|
|
1705
|
+
},
|
|
1706
|
+
startAlarm({ repeating, intervalSec }) {
|
|
1707
|
+
alarm = {
|
|
1708
|
+
startedAt: Date.now(),
|
|
1709
|
+
count: 1,
|
|
1710
|
+
repeating: Boolean(repeating),
|
|
1711
|
+
intervalSec: Math.max(3, Math.round(intervalSec)),
|
|
1712
|
+
timedOut: false,
|
|
1713
|
+
}
|
|
1714
|
+
emit()
|
|
1715
|
+
},
|
|
1716
|
+
bumpAlarmCount() {
|
|
1717
|
+
if (alarm === null) return
|
|
1718
|
+
alarm = { ...alarm, count: alarm.count + 1 }
|
|
1719
|
+
emit()
|
|
1720
|
+
},
|
|
1721
|
+
markAlarmTimedOut() {
|
|
1722
|
+
if (alarm === null) return
|
|
1723
|
+
alarm = { ...alarm, repeating: false, timedOut: true }
|
|
1724
|
+
emit()
|
|
1725
|
+
},
|
|
1726
|
+
stopAlarm() {
|
|
1727
|
+
if (alarm === null) return
|
|
1728
|
+
alarm = null
|
|
1729
|
+
emit()
|
|
1730
|
+
},
|
|
1731
|
+
setShutdown(next) {
|
|
1732
|
+
shutdown = next
|
|
1733
|
+
emit()
|
|
1734
|
+
},
|
|
1735
|
+
reset() {
|
|
1736
|
+
value = { ...DEFAULT_TURN_END }
|
|
1737
|
+
busy = ''
|
|
1738
|
+
notice = { tone: '', text: '' }
|
|
1739
|
+
alarm = null
|
|
1740
|
+
shutdown = null
|
|
1741
|
+
emit()
|
|
1742
|
+
},
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
const turnEndStore = createTurnEndStore()
|
|
1747
|
+
|
|
1748
|
+
function useTurnEnd() {
|
|
1749
|
+
const [snapshot, setSnapshot] = useState(() => turnEndStore.getSnapshot())
|
|
1750
|
+
useEffect(() => turnEndStore.subscribe(() => setSnapshot(turnEndStore.getSnapshot())), [])
|
|
1751
|
+
return snapshot
|
|
1522
1752
|
}
|
|
1523
1753
|
|
|
1524
1754
|
/* --- IndexedDB: the chosen clip is a data URL, too big for localStorage --- */
|
|
@@ -1748,8 +1978,7 @@ window.__ModuleLoader__.load({
|
|
|
1748
1978
|
* stops the moment the prompt is answered — that stop is the whole point of
|
|
1749
1979
|
* reading `pendingInteraction` instead of a one-shot event.
|
|
1750
1980
|
*/
|
|
1751
|
-
function AlertRuntime({ useSessionStatus }) {
|
|
1752
|
-
const alertEnabled = useFeatureEnabled('alert')
|
|
1981
|
+
function AlertRuntime({ useSessionStatus }) { const alertEnabled = useFeatureEnabled('alert')
|
|
1753
1982
|
const config = useNotifyConfig()
|
|
1754
1983
|
const effectiveEnabled = alertEnabled && config.enabled
|
|
1755
1984
|
const pending = useSessionStatus(snapshot => {
|
|
@@ -1795,6 +2024,349 @@ window.__ModuleLoader__.load({
|
|
|
1795
2024
|
return null
|
|
1796
2025
|
}
|
|
1797
2026
|
|
|
2027
|
+
/**
|
|
2028
|
+
* Watch one Session's `running` flag and act once when it falls to false.
|
|
2029
|
+
*
|
|
2030
|
+
* Why `running` and not a log event: the log lives in the host, and a
|
|
2031
|
+
* browser half that folded it would have to duplicate the whole projection
|
|
2032
|
+
* just to learn "the turn is over". `SessionStatus.running` is the host's
|
|
2033
|
+
* own answer to that question, already published per session, and it drops
|
|
2034
|
+
* only when the turn really ends — including a cancelled one.
|
|
2035
|
+
*
|
|
2036
|
+
* Frame-wide (`shell.overlay`), so the reminder fires for whichever Session
|
|
2037
|
+
* is actually finishing, not just the one on screen.
|
|
2038
|
+
*
|
|
2039
|
+
* @param root0 - standard overlay props.
|
|
2040
|
+
* @param root0.useSessionStatus - per-Session running/pending snapshot.
|
|
2041
|
+
*/
|
|
2042
|
+
async function cancelShutdownOnHost() {
|
|
2043
|
+
turnEndStore.setStatus('cancel', { tone: '', text: '正在取消自动关机…' })
|
|
2044
|
+
try {
|
|
2045
|
+
const response = await fetch('powertoys/shutdown', {
|
|
2046
|
+
method: 'POST',
|
|
2047
|
+
headers: { 'content-type': 'application/json' },
|
|
2048
|
+
body: JSON.stringify({ cancel: true }),
|
|
2049
|
+
})
|
|
2050
|
+
const body = await response.json().catch(() => ({}))
|
|
2051
|
+
if (!response.ok) {
|
|
2052
|
+
if (body.scheduled === null) turnEndStore.setShutdown(null)
|
|
2053
|
+
turnEndStore.setStatus('', {
|
|
2054
|
+
tone: 'warn',
|
|
2055
|
+
text: body.message === undefined || body.message === ''
|
|
2056
|
+
? `取消关机失败(HTTP ${response.status})`
|
|
2057
|
+
: `取消关机失败:${body.message}`,
|
|
2058
|
+
})
|
|
2059
|
+
return
|
|
2060
|
+
}
|
|
2061
|
+
turnEndStore.setShutdown(null)
|
|
2062
|
+
turnEndStore.setStatus('', { tone: '', text: '已取消自动关机。' })
|
|
2063
|
+
} catch (error) {
|
|
2064
|
+
turnEndStore.setStatus('', { tone: 'warn', text: `取消关机失败:${String(error?.message ?? error)}` })
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
function TurnEndRuntime({ useSessionStatus }) {
|
|
2069
|
+
const config = useNotifyConfig()
|
|
2070
|
+
const enabled = useFeatureEnabled('turnEnd')
|
|
2071
|
+
const { value: turnEnd, busy, alarm, shutdown } = useTurnEnd()
|
|
2072
|
+
const [nowMs, setNowMs] = useState(() => Date.now())
|
|
2073
|
+
|
|
2074
|
+
/** sessionId → last observed running flag, so an all-idle fall can be detected. */
|
|
2075
|
+
const runningRef = useRef(new Map())
|
|
2076
|
+
/** Interval handle for the repeating alarm. */
|
|
2077
|
+
const repeatRef = useRef(null)
|
|
2078
|
+
/** Live notify config ref so an active alarm uses latest sound/volume. */
|
|
2079
|
+
const configRef = useRef(config)
|
|
2080
|
+
configRef.current = config
|
|
2081
|
+
|
|
2082
|
+
const stopRepeat = useCallback(() => {
|
|
2083
|
+
if (repeatRef.current !== null) {
|
|
2084
|
+
clearInterval(repeatRef.current.timer)
|
|
2085
|
+
repeatRef.current = null
|
|
2086
|
+
}
|
|
2087
|
+
}, [])
|
|
2088
|
+
|
|
2089
|
+
const dismissAlarm = useCallback(() => {
|
|
2090
|
+
stopRepeat()
|
|
2091
|
+
turnEndStore.stopAlarm()
|
|
2092
|
+
}, [stopRepeat])
|
|
2093
|
+
|
|
2094
|
+
// Stop the interval whenever the module is turned off or the alarm popup is dismissed.
|
|
2095
|
+
useEffect(() => {
|
|
2096
|
+
if (!enabled) {
|
|
2097
|
+
stopRepeat()
|
|
2098
|
+
turnEndStore.stopAlarm()
|
|
2099
|
+
return
|
|
2100
|
+
}
|
|
2101
|
+
if (alarm === null || !alarm.repeating) stopRepeat()
|
|
2102
|
+
}, [enabled, alarm, stopRepeat])
|
|
2103
|
+
|
|
2104
|
+
// Re-hydrate an already-scheduled host shutdown on mount (e.g. after page reload)
|
|
2105
|
+
// so the user always gets a one-click Cancel button during the countdown window.
|
|
2106
|
+
useEffect(() => {
|
|
2107
|
+
if (!enabled) return undefined
|
|
2108
|
+
let cancelled = false
|
|
2109
|
+
fetch('powertoys/shutdown')
|
|
2110
|
+
.then(res => (res.ok ? res.json().catch(() => null) : null))
|
|
2111
|
+
.then(body => {
|
|
2112
|
+
if (cancelled || body === null) return
|
|
2113
|
+
if (body.scheduled && typeof body.scheduled.at === 'number' && body.scheduled.at > Date.now()) {
|
|
2114
|
+
turnEndStore.setShutdown(body.scheduled)
|
|
2115
|
+
setNowMs(Date.now())
|
|
2116
|
+
}
|
|
2117
|
+
})
|
|
2118
|
+
.catch(() => {})
|
|
2119
|
+
return () => { cancelled = true }
|
|
2120
|
+
}, [enabled])
|
|
2121
|
+
|
|
2122
|
+
// Live 1s countdown while a real shutdown is scheduled.
|
|
2123
|
+
useEffect(() => {
|
|
2124
|
+
if (!enabled || shutdown === null || shutdown.dryRun || typeof shutdown.at !== 'number') {
|
|
2125
|
+
return undefined
|
|
2126
|
+
}
|
|
2127
|
+
setNowMs(Date.now())
|
|
2128
|
+
const timer = setInterval(() => {
|
|
2129
|
+
const t = Date.now()
|
|
2130
|
+
setNowMs(t)
|
|
2131
|
+
if (t >= shutdown.at) {
|
|
2132
|
+
clearInterval(timer)
|
|
2133
|
+
turnEndStore.setShutdown(null)
|
|
2134
|
+
}
|
|
2135
|
+
}, 1000)
|
|
2136
|
+
return () => clearInterval(timer)
|
|
2137
|
+
}, [enabled, shutdown])
|
|
2138
|
+
|
|
2139
|
+
const requestShutdown = useCallback(async delaySeconds => {
|
|
2140
|
+
turnEndStore.setStatus('shutdown', { tone: '', text: `正在请求关机(延迟 ${delaySeconds} 秒)…` })
|
|
2141
|
+
try {
|
|
2142
|
+
const response = await fetch('powertoys/shutdown', {
|
|
2143
|
+
method: 'POST',
|
|
2144
|
+
headers: { 'content-type': 'application/json' },
|
|
2145
|
+
body: JSON.stringify({ delaySeconds }),
|
|
2146
|
+
})
|
|
2147
|
+
const body = await response.json().catch(() => ({}))
|
|
2148
|
+
if (!response.ok) {
|
|
2149
|
+
turnEndStore.setStatus('', {
|
|
2150
|
+
tone: 'warn',
|
|
2151
|
+
text: body.message === undefined
|
|
2152
|
+
? `关机请求失败(HTTP ${response.status})`
|
|
2153
|
+
: `关机请求失败:${body.message}`,
|
|
2154
|
+
})
|
|
2155
|
+
return
|
|
2156
|
+
}
|
|
2157
|
+
if (body.dryRun === true || body.disabled === true) {
|
|
2158
|
+
const previewArgv = Array.isArray(body.argv) ? body.argv : []
|
|
2159
|
+
const previewDelay = Number.isFinite(body.delaySeconds) ? body.delaySeconds : delaySeconds
|
|
2160
|
+
turnEndStore.setShutdown({
|
|
2161
|
+
at: null,
|
|
2162
|
+
delaySeconds: previewDelay,
|
|
2163
|
+
dryRun: true,
|
|
2164
|
+
argv: previewArgv,
|
|
2165
|
+
message: typeof body.message === 'string' ? body.message : '',
|
|
2166
|
+
})
|
|
2167
|
+
turnEndStore.setStatus('', {
|
|
2168
|
+
tone: '',
|
|
2169
|
+
text: `演练模式:未执行真实关机(模拟命令:shutdown ${previewArgv.join(' ')})。`,
|
|
2170
|
+
})
|
|
2171
|
+
return
|
|
2172
|
+
}
|
|
2173
|
+
const scheduled = body.scheduled && typeof body.scheduled.at === 'number'
|
|
2174
|
+
? body.scheduled
|
|
2175
|
+
: { at: Date.now() + delaySeconds * 1000, delaySeconds }
|
|
2176
|
+
turnEndStore.setShutdown(scheduled)
|
|
2177
|
+
setNowMs(Date.now())
|
|
2178
|
+
turnEndStore.setStatus('', {
|
|
2179
|
+
tone: '',
|
|
2180
|
+
text: `已安排在 ${scheduled.delaySeconds ?? delaySeconds} 秒后关机,可点击弹窗或运行 shutdown /a 取消。`,
|
|
2181
|
+
})
|
|
2182
|
+
} catch (error) {
|
|
2183
|
+
turnEndStore.setStatus('', { tone: 'warn', text: `关机请求失败:${String(error?.message ?? error)}` })
|
|
2184
|
+
}
|
|
2185
|
+
}, [])
|
|
2186
|
+
|
|
2187
|
+
// A selector returning only the running IDs: an unrelated status publish
|
|
2188
|
+
// (pendingInteraction, completionUnread) cannot retrigger the effect.
|
|
2189
|
+
const runningBits = useSessionStatus(snapshot => {
|
|
2190
|
+
const ids = []
|
|
2191
|
+
for (const [id, status] of snapshot) {
|
|
2192
|
+
if (status.running === true) ids.push(id)
|
|
2193
|
+
}
|
|
2194
|
+
return ids.join('|')
|
|
2195
|
+
})
|
|
2196
|
+
|
|
2197
|
+
useEffect(() => {
|
|
2198
|
+
if (!enabled) {
|
|
2199
|
+
runningRef.current = new Map()
|
|
2200
|
+
return undefined
|
|
2201
|
+
}
|
|
2202
|
+
const nowRunning = new Set(runningBits === '' ? [] : runningBits.split('|'))
|
|
2203
|
+
const previous = runningRef.current
|
|
2204
|
+
|
|
2205
|
+
// Fire only when at least one session was running and ALL running
|
|
2206
|
+
// sessions have now finished, so a quick side conversation never
|
|
2207
|
+
// prematurely rings or shuts down while a long task is still running.
|
|
2208
|
+
const allIdleAfterRun = previous.size > 0 && nowRunning.size === 0
|
|
2209
|
+
runningRef.current = new Map([...nowRunning].map(id => [id, true]))
|
|
2210
|
+
if (!allIdleAfterRun) return undefined
|
|
2211
|
+
|
|
2212
|
+
const state = turnEndStore.getSnapshot().value
|
|
2213
|
+
if (!state.alertArmed && !state.shutdownArmed) return undefined
|
|
2214
|
+
|
|
2215
|
+
if (state.alertArmed) {
|
|
2216
|
+
stopRepeat()
|
|
2217
|
+
playAlert(configRef.current)
|
|
2218
|
+
turnEndStore.disarm('alert')
|
|
2219
|
+
const intervalSec = Math.max(3, state.alertIntervalSec)
|
|
2220
|
+
turnEndStore.startAlarm({ repeating: state.alertRepeat, intervalSec })
|
|
2221
|
+
if (state.alertRepeat) {
|
|
2222
|
+
const timer = setInterval(() => {
|
|
2223
|
+
const snap = turnEndStore.getSnapshot()
|
|
2224
|
+
if (snap.alarm === null || !snap.alarm.repeating) {
|
|
2225
|
+
stopRepeat()
|
|
2226
|
+
return
|
|
2227
|
+
}
|
|
2228
|
+
if (snap.value.alertMaxSeconds > 0 && Date.now() - snap.alarm.startedAt >= snap.value.alertMaxSeconds * 1000) {
|
|
2229
|
+
stopRepeat()
|
|
2230
|
+
turnEndStore.markAlarmTimedOut()
|
|
2231
|
+
return
|
|
2232
|
+
}
|
|
2233
|
+
playAlert(configRef.current)
|
|
2234
|
+
turnEndStore.bumpAlarmCount()
|
|
2235
|
+
}, intervalSec * 1000)
|
|
2236
|
+
repeatRef.current = { timer }
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
if (state.shutdownArmed) {
|
|
2241
|
+
turnEndStore.disarm('shutdown')
|
|
2242
|
+
void requestShutdown(state.shutdownDelaySec)
|
|
2243
|
+
}
|
|
2244
|
+
return undefined
|
|
2245
|
+
}, [enabled, runningBits, requestShutdown, stopRepeat])
|
|
2246
|
+
|
|
2247
|
+
useEffect(() => () => stopRepeat(), [stopRepeat])
|
|
2248
|
+
|
|
2249
|
+
const armed = turnEnd.alertArmed || turnEnd.shutdownArmed
|
|
2250
|
+
if (!enabled || (!armed && alarm === null && shutdown === null)) return null
|
|
2251
|
+
|
|
2252
|
+
const remainingSec = shutdown !== null && !shutdown.dryRun && typeof shutdown.at === 'number'
|
|
2253
|
+
? Math.max(0, Math.ceil((shutdown.at - nowMs) / 1000))
|
|
2254
|
+
: 0
|
|
2255
|
+
|
|
2256
|
+
const armedParts = []
|
|
2257
|
+
if (turnEnd.alertArmed) {
|
|
2258
|
+
armedParts.push(turnEnd.alertRepeat ? `完成后每 ${turnEnd.alertIntervalSec}s 响铃` : '完成后响铃')
|
|
2259
|
+
}
|
|
2260
|
+
if (turnEnd.shutdownArmed) {
|
|
2261
|
+
armedParts.push(`完成后 ${turnEnd.shutdownDelaySec}s 关机`)
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
return React.createElement('div', {
|
|
2265
|
+
className: 'dsh-powertoys-toast-stack',
|
|
2266
|
+
'data-role': 'turnend-overlay',
|
|
2267
|
+
},
|
|
2268
|
+
alarm === null
|
|
2269
|
+
? null
|
|
2270
|
+
: React.createElement('div', {
|
|
2271
|
+
className: 'dsh-powertoys-alarm-card',
|
|
2272
|
+
role: 'alertdialog',
|
|
2273
|
+
'aria-label': '任务完成闹铃提醒',
|
|
2274
|
+
'data-kind': 'alarm',
|
|
2275
|
+
'data-role': 'turnend-alarm-dialog',
|
|
2276
|
+
},
|
|
2277
|
+
React.createElement('div', { className: 'dsh-powertoys-alarm-head' },
|
|
2278
|
+
React.createElement('span', { className: 'dsh-powertoys-alarm-title' }, '本轮任务已完成'),
|
|
2279
|
+
React.createElement('span', { className: 'dsh-powertoys-alarm-badge' },
|
|
2280
|
+
alarm.repeating ? `响铃中 · 第 ${alarm.count} 次` : `已响 ${alarm.count} 次`),
|
|
2281
|
+
),
|
|
2282
|
+
React.createElement('div', { className: 'dsh-powertoys-alarm-desc' },
|
|
2283
|
+
alarm.repeating
|
|
2284
|
+
? `每隔 ${alarm.intervalSec} 秒重复响铃,点击下方按钮立即停止。`
|
|
2285
|
+
: alarm.timedOut
|
|
2286
|
+
? '已达最长提醒时长,响铃已自动停止。'
|
|
2287
|
+
: '单次提醒已完成,本次开关已自动复位。'),
|
|
2288
|
+
React.createElement('div', { className: 'dsh-powertoys-alarm-actions' },
|
|
2289
|
+
React.createElement('button', {
|
|
2290
|
+
type: 'button',
|
|
2291
|
+
className: 'dsh-powertoys-alarm-btn',
|
|
2292
|
+
'data-role': 'turnend-alarm-stop',
|
|
2293
|
+
onClick: dismissAlarm,
|
|
2294
|
+
}, alarm.repeating ? '停止响铃' : '知道了'),
|
|
2295
|
+
),
|
|
2296
|
+
),
|
|
2297
|
+
|
|
2298
|
+
shutdown === null
|
|
2299
|
+
? null
|
|
2300
|
+
: shutdown.dryRun === true
|
|
2301
|
+
? React.createElement('div', {
|
|
2302
|
+
className: 'dsh-powertoys-alarm-card',
|
|
2303
|
+
role: 'status',
|
|
2304
|
+
'data-kind': 'dryrun',
|
|
2305
|
+
'data-role': 'turnend-dryrun-dialog',
|
|
2306
|
+
},
|
|
2307
|
+
React.createElement('div', { className: 'dsh-powertoys-alarm-head' },
|
|
2308
|
+
React.createElement('span', { className: 'dsh-powertoys-alarm-title' }, '关机演练已触发(未真实关机)'),
|
|
2309
|
+
React.createElement('span', { className: 'dsh-powertoys-alarm-badge' }, 'DRY RUN'),
|
|
2310
|
+
),
|
|
2311
|
+
React.createElement('div', { className: 'dsh-powertoys-alarm-desc' },
|
|
2312
|
+
`已拦截真实关机,模拟命令:shutdown ${(shutdown.argv ?? []).join(' ')}`),
|
|
2313
|
+
React.createElement('div', { className: 'dsh-powertoys-alarm-actions' },
|
|
2314
|
+
React.createElement('button', {
|
|
2315
|
+
type: 'button',
|
|
2316
|
+
className: 'dsh-powertoys-alarm-btn',
|
|
2317
|
+
'data-secondary': 'true',
|
|
2318
|
+
'data-role': 'turnend-dryrun-dismiss',
|
|
2319
|
+
onClick: () => turnEndStore.setShutdown(null),
|
|
2320
|
+
}, '关闭'),
|
|
2321
|
+
),
|
|
2322
|
+
)
|
|
2323
|
+
: React.createElement('div', {
|
|
2324
|
+
className: 'dsh-powertoys-alarm-card',
|
|
2325
|
+
role: 'alertdialog',
|
|
2326
|
+
'aria-label': '自动关机倒计时',
|
|
2327
|
+
'data-kind': 'shutdown',
|
|
2328
|
+
'data-role': 'turnend-shutdown-dialog',
|
|
2329
|
+
},
|
|
2330
|
+
React.createElement('div', { className: 'dsh-powertoys-alarm-head' },
|
|
2331
|
+
React.createElement('span', { className: 'dsh-powertoys-alarm-title' }, '即将自动关机'),
|
|
2332
|
+
React.createElement('span', { className: 'dsh-powertoys-alarm-badge' }, `${remainingSec} 秒`),
|
|
2333
|
+
),
|
|
2334
|
+
React.createElement('div', { className: 'dsh-powertoys-alarm-desc' },
|
|
2335
|
+
`本轮输出已完成,系统将在 ${remainingSec} 秒后关机。点击下方按钮或运行 shutdown /a 可立即取消。`),
|
|
2336
|
+
React.createElement('div', { className: 'dsh-powertoys-alarm-actions' },
|
|
2337
|
+
React.createElement('button', {
|
|
2338
|
+
type: 'button',
|
|
2339
|
+
className: 'dsh-powertoys-alarm-btn',
|
|
2340
|
+
'data-danger': 'true',
|
|
2341
|
+
'data-role': 'turnend-shutdown-cancel',
|
|
2342
|
+
disabled: busy === 'cancel',
|
|
2343
|
+
onClick: () => { void cancelShutdownOnHost() },
|
|
2344
|
+
}, busy === 'cancel' ? '正在取消…' : '立即取消关机'),
|
|
2345
|
+
),
|
|
2346
|
+
),
|
|
2347
|
+
|
|
2348
|
+
!armed
|
|
2349
|
+
? null
|
|
2350
|
+
: React.createElement('div', {
|
|
2351
|
+
className: 'dsh-powertoys-armed-pill',
|
|
2352
|
+
role: 'status',
|
|
2353
|
+
'data-danger': turnEnd.shutdownArmed ? 'true' : 'false',
|
|
2354
|
+
'data-role': 'turnend-armed-pill',
|
|
2355
|
+
},
|
|
2356
|
+
React.createElement('span', { className: 'dsh-powertoys-armed-dot', 'aria-hidden': 'true' }),
|
|
2357
|
+
React.createElement('span', null, `${armedParts.join(' · ')}(待命)`),
|
|
2358
|
+
React.createElement('button', {
|
|
2359
|
+
type: 'button',
|
|
2360
|
+
className: 'dsh-powertoys-pill-close',
|
|
2361
|
+
title: '取消待命',
|
|
2362
|
+
'aria-label': '取消本轮结束待命',
|
|
2363
|
+
'data-role': 'turnend-armed-cancel',
|
|
2364
|
+
onClick: () => turnEndStore.disarm('all'),
|
|
2365
|
+
}, '×'),
|
|
2366
|
+
),
|
|
2367
|
+
)
|
|
2368
|
+
}
|
|
2369
|
+
|
|
1798
2370
|
/**
|
|
1799
2371
|
* Settings → DSH PowerToys.
|
|
1800
2372
|
*
|
|
@@ -1806,6 +2378,9 @@ window.__ModuleLoader__.load({
|
|
|
1806
2378
|
function PowerToysSettings() {
|
|
1807
2379
|
const features = useFeatures()
|
|
1808
2380
|
const config = useNotifyConfig()
|
|
2381
|
+
const turnEndState = useTurnEnd()
|
|
2382
|
+
const turnEnd = turnEndState.value
|
|
2383
|
+
const notice = turnEndState.notice
|
|
1809
2384
|
const alertEnabled = features.alert !== false && config.enabled
|
|
1810
2385
|
const [clipName, setClipName] = useState('')
|
|
1811
2386
|
const [clipWarning, setClipWarning] = useState('')
|
|
@@ -1863,6 +2438,189 @@ window.__ModuleLoader__.load({
|
|
|
1863
2438
|
|
|
1864
2439
|
const enabledCount = MODULES.filter(mod => features[mod.id] !== false).length
|
|
1865
2440
|
|
|
2441
|
+
const renderTurnEndSubSettings = () => {
|
|
2442
|
+
const armed = turnEnd.alertArmed || turnEnd.shutdownArmed
|
|
2443
|
+
const activeAlarm = turnEndState.alarm
|
|
2444
|
+
const activeShutdown = turnEndState.shutdown
|
|
2445
|
+
const turnEndDisabled = features.turnEnd === false
|
|
2446
|
+
return React.createElement('div', {
|
|
2447
|
+
className: 'dsh-powertoys-module-body',
|
|
2448
|
+
'data-disabled': turnEndDisabled ? 'true' : 'false',
|
|
2449
|
+
},
|
|
2450
|
+
React.createElement('div', { className: 'dsh-powertoys-field' },
|
|
2451
|
+
React.createElement('div', { className: 'dsh-powertoys-field-label' },
|
|
2452
|
+
React.createElement('b', null, '本轮结束后提醒'),
|
|
2453
|
+
React.createElement('small', null,
|
|
2454
|
+
turnEnd.alertArmed
|
|
2455
|
+
? '已待命,所有运行中会话完成后弹出闹铃并自动复位'
|
|
2456
|
+
: '非持久化单次开关:开一次用一次,点击弹窗按钮停铃'),
|
|
2457
|
+
),
|
|
2458
|
+
React.createElement('label', { className: 'dsh-powertoys-check' },
|
|
2459
|
+
React.createElement('input', {
|
|
2460
|
+
type: 'checkbox',
|
|
2461
|
+
'data-role': 'turnend-alert-arm',
|
|
2462
|
+
checked: turnEnd.alertArmed,
|
|
2463
|
+
disabled: turnEndDisabled,
|
|
2464
|
+
onChange: event => turnEndStore.set({ alertArmed: event.target.checked }),
|
|
2465
|
+
}),
|
|
2466
|
+
React.createElement('span', null, turnEnd.alertArmed ? '已待命' : '未开启'),
|
|
2467
|
+
),
|
|
2468
|
+
),
|
|
2469
|
+
|
|
2470
|
+
React.createElement('div', { className: 'dsh-powertoys-field' },
|
|
2471
|
+
React.createElement('div', { className: 'dsh-powertoys-field-label' },
|
|
2472
|
+
React.createElement('b', null, '响过一次后继续重复'),
|
|
2473
|
+
React.createElement('small', null, '像闹铃一样按间隔反复响,点击弹窗后停止;关掉则只响一次'),
|
|
2474
|
+
),
|
|
2475
|
+
React.createElement('label', { className: 'dsh-powertoys-check' },
|
|
2476
|
+
React.createElement('input', {
|
|
2477
|
+
type: 'checkbox',
|
|
2478
|
+
'data-role': 'turnend-alert-repeat',
|
|
2479
|
+
checked: turnEnd.alertRepeat,
|
|
2480
|
+
disabled: turnEndDisabled,
|
|
2481
|
+
onChange: event => turnEndStore.set({ alertRepeat: event.target.checked }),
|
|
2482
|
+
}),
|
|
2483
|
+
React.createElement('span', null, turnEnd.alertRepeat ? '重复提醒' : '只响一次'),
|
|
2484
|
+
),
|
|
2485
|
+
),
|
|
2486
|
+
|
|
2487
|
+
React.createElement('div', { className: 'dsh-powertoys-field' },
|
|
2488
|
+
React.createElement('div', { className: 'dsh-powertoys-field-label' },
|
|
2489
|
+
React.createElement('b', null, '重复间隔'),
|
|
2490
|
+
React.createElement('small', null, '仅在开启重复时生效'),
|
|
2491
|
+
),
|
|
2492
|
+
React.createElement('div', { className: 'dsh-powertoys-field-body' },
|
|
2493
|
+
React.createElement('input', {
|
|
2494
|
+
type: 'number', min: 3, max: 600, step: 1,
|
|
2495
|
+
value: turnEnd.alertIntervalSec,
|
|
2496
|
+
disabled: turnEndDisabled || !turnEnd.alertRepeat,
|
|
2497
|
+
onChange: event => {
|
|
2498
|
+
const value = Number(event.target.value)
|
|
2499
|
+
if (Number.isFinite(value)) turnEndStore.set({ alertIntervalSec: value })
|
|
2500
|
+
},
|
|
2501
|
+
}),
|
|
2502
|
+
React.createElement('span', { className: 'dsh-powertoys-num' }, '秒'),
|
|
2503
|
+
),
|
|
2504
|
+
),
|
|
2505
|
+
|
|
2506
|
+
React.createElement('div', { className: 'dsh-powertoys-field' },
|
|
2507
|
+
React.createElement('div', { className: 'dsh-powertoys-field-label' },
|
|
2508
|
+
React.createElement('b', null, '最长重复'),
|
|
2509
|
+
React.createElement('small', null, '超过就停,0 表示一直响直到手动点停'),
|
|
2510
|
+
),
|
|
2511
|
+
React.createElement('div', { className: 'dsh-powertoys-field-body' },
|
|
2512
|
+
React.createElement('input', {
|
|
2513
|
+
type: 'number', min: 0, max: 7200, step: 30,
|
|
2514
|
+
value: turnEnd.alertMaxSeconds,
|
|
2515
|
+
disabled: turnEndDisabled || !turnEnd.alertRepeat,
|
|
2516
|
+
onChange: event => {
|
|
2517
|
+
const value = Number(event.target.value)
|
|
2518
|
+
if (Number.isFinite(value)) turnEndStore.set({ alertMaxSeconds: value })
|
|
2519
|
+
},
|
|
2520
|
+
}),
|
|
2521
|
+
React.createElement('span', { className: 'dsh-powertoys-num' }, '秒'),
|
|
2522
|
+
),
|
|
2523
|
+
),
|
|
2524
|
+
|
|
2525
|
+
activeAlarm === null
|
|
2526
|
+
? null
|
|
2527
|
+
: React.createElement('div', { className: 'dsh-powertoys-field' },
|
|
2528
|
+
React.createElement('div', { className: 'dsh-powertoys-field-label' },
|
|
2529
|
+
React.createElement('b', null, '当前闹铃状态'),
|
|
2530
|
+
React.createElement('small', null,
|
|
2531
|
+
activeAlarm.repeating ? `正在重复响铃(已响 ${activeAlarm.count} 次)` : `已响铃 ${activeAlarm.count} 次`),
|
|
2532
|
+
),
|
|
2533
|
+
React.createElement('div', { className: 'dsh-powertoys-field-body' },
|
|
2534
|
+
React.createElement('button', {
|
|
2535
|
+
type: 'button',
|
|
2536
|
+
'data-primary': 'true',
|
|
2537
|
+
'data-role': 'turnend-settings-stop-alarm',
|
|
2538
|
+
onClick: () => turnEndStore.stopAlarm(),
|
|
2539
|
+
}, activeAlarm.repeating ? '停止当前响铃' : '关闭提醒弹窗'),
|
|
2540
|
+
),
|
|
2541
|
+
),
|
|
2542
|
+
|
|
2543
|
+
React.createElement('div', { className: 'dsh-powertoys-field' },
|
|
2544
|
+
React.createElement('div', { className: 'dsh-powertoys-field-label' },
|
|
2545
|
+
React.createElement('b', null, '本轮结束后关机'),
|
|
2546
|
+
React.createElement('small', null,
|
|
2547
|
+
turnEnd.shutdownArmed
|
|
2548
|
+
? '已待命,所有运行中会话完成后触发延迟关机并自动复位'
|
|
2549
|
+
: '非持久化单次开关:开一次用一次,触发后弹窗可一键取消'),
|
|
2550
|
+
),
|
|
2551
|
+
React.createElement('label', { className: 'dsh-powertoys-check' },
|
|
2552
|
+
React.createElement('input', {
|
|
2553
|
+
type: 'checkbox',
|
|
2554
|
+
'data-role': 'turnend-shutdown-arm',
|
|
2555
|
+
checked: turnEnd.shutdownArmed,
|
|
2556
|
+
disabled: turnEndDisabled,
|
|
2557
|
+
onChange: event => turnEndStore.set({ shutdownArmed: event.target.checked }),
|
|
2558
|
+
}),
|
|
2559
|
+
React.createElement('span', null, turnEnd.shutdownArmed ? '已待命' : '未开启'),
|
|
2560
|
+
),
|
|
2561
|
+
),
|
|
2562
|
+
|
|
2563
|
+
React.createElement('div', { className: 'dsh-powertoys-field' },
|
|
2564
|
+
React.createElement('div', { className: 'dsh-powertoys-field-label' },
|
|
2565
|
+
React.createElement('b', null, '关机延迟'),
|
|
2566
|
+
React.createElement('small', null, '10–3600 秒,留出反悔倒计时窗口'),
|
|
2567
|
+
),
|
|
2568
|
+
React.createElement('div', { className: 'dsh-powertoys-field-body' },
|
|
2569
|
+
React.createElement('input', {
|
|
2570
|
+
type: 'number', min: 10, max: 3600, step: 10,
|
|
2571
|
+
value: turnEnd.shutdownDelaySec,
|
|
2572
|
+
disabled: turnEndDisabled,
|
|
2573
|
+
onChange: event => {
|
|
2574
|
+
const value = Number(event.target.value)
|
|
2575
|
+
if (Number.isFinite(value)) turnEndStore.set({ shutdownDelaySec: value })
|
|
2576
|
+
},
|
|
2577
|
+
}),
|
|
2578
|
+
React.createElement('span', { className: 'dsh-powertoys-num' }, '秒'),
|
|
2579
|
+
),
|
|
2580
|
+
),
|
|
2581
|
+
|
|
2582
|
+
activeShutdown === null || activeShutdown.dryRun === true
|
|
2583
|
+
? null
|
|
2584
|
+
: React.createElement('div', { className: 'dsh-powertoys-field' },
|
|
2585
|
+
React.createElement('div', { className: 'dsh-powertoys-field-label' },
|
|
2586
|
+
React.createElement('b', null, '已安排关机'),
|
|
2587
|
+
React.createElement('small', null, '点击可立即中止当前 Windows 关机倒计时'),
|
|
2588
|
+
),
|
|
2589
|
+
React.createElement('div', { className: 'dsh-powertoys-field-body' },
|
|
2590
|
+
React.createElement('button', {
|
|
2591
|
+
type: 'button',
|
|
2592
|
+
'data-primary': 'true',
|
|
2593
|
+
'data-role': 'turnend-settings-cancel-shutdown',
|
|
2594
|
+
disabled: turnEndState.busy === 'cancel',
|
|
2595
|
+
onClick: () => { void cancelShutdownOnHost() },
|
|
2596
|
+
}, turnEndState.busy === 'cancel' ? '正在取消…' : '立即取消关机'),
|
|
2597
|
+
),
|
|
2598
|
+
),
|
|
2599
|
+
|
|
2600
|
+
notice.text === ''
|
|
2601
|
+
? null
|
|
2602
|
+
: React.createElement('div', { className: 'dsh-powertoys-field' },
|
|
2603
|
+
React.createElement('div', { className: 'dsh-powertoys-field-label' }, ''),
|
|
2604
|
+
React.createElement('div', { className: 'dsh-powertoys-field-body' },
|
|
2605
|
+
React.createElement('span', {
|
|
2606
|
+
className: notice.tone === 'warn' ? 'dsh-powertoys-warn' : 'dsh-powertoys-file',
|
|
2607
|
+
'data-role': 'turnend-notice',
|
|
2608
|
+
}, notice.text),
|
|
2609
|
+
),
|
|
2610
|
+
),
|
|
2611
|
+
|
|
2612
|
+
armed
|
|
2613
|
+
? null
|
|
2614
|
+
: React.createElement('div', { className: 'dsh-powertoys-field' },
|
|
2615
|
+
React.createElement('div', { className: 'dsh-powertoys-field-label' }, ''),
|
|
2616
|
+
React.createElement('div', { className: 'dsh-powertoys-field-body' },
|
|
2617
|
+
React.createElement('span', { className: 'dsh-powertoys-file' },
|
|
2618
|
+
'两个开关均不持久化:刷新页面或触发一次后即复位,多会话同时运行时会等全部结束再触发。'),
|
|
2619
|
+
),
|
|
2620
|
+
),
|
|
2621
|
+
)
|
|
2622
|
+
}
|
|
2623
|
+
|
|
1866
2624
|
const renderAlertSubSettings = () => React.createElement('div', {
|
|
1867
2625
|
className: 'dsh-powertoys-module-body',
|
|
1868
2626
|
'data-disabled': alertEnabled ? 'false' : 'true',
|
|
@@ -2028,6 +2786,7 @@ window.__ModuleLoader__.load({
|
|
|
2028
2786
|
),
|
|
2029
2787
|
),
|
|
2030
2788
|
mod.id === 'alert' ? renderAlertSubSettings() : null,
|
|
2789
|
+
mod.id === 'turnEnd' ? renderTurnEndSubSettings() : null,
|
|
2031
2790
|
)
|
|
2032
2791
|
}),
|
|
2033
2792
|
),
|
|
@@ -2121,6 +2880,12 @@ window.__ModuleLoader__.load({
|
|
|
2121
2880
|
{ name: 'shell.overlay', id: ALERT_ID },
|
|
2122
2881
|
AlertRuntime,
|
|
2123
2882
|
)
|
|
2883
|
+
// Same reason, different trigger: this one watches every Session's
|
|
2884
|
+
// running flag so a turn ending anywhere rings the reminder.
|
|
2885
|
+
yield ctx.slots.register(
|
|
2886
|
+
{ name: 'shell.overlay', id: TURNEND_ID },
|
|
2887
|
+
TurnEndRuntime,
|
|
2888
|
+
)
|
|
2124
2889
|
})
|
|
2125
2890
|
|
|
2126
2891
|
ctx.slots.inject('settings.section', () => ctx.slots.register(
|
package/lib/index.js
CHANGED
|
@@ -35,11 +35,274 @@
|
|
|
35
35
|
* @module dsh-powertoys
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
|
+
import { spawn } from 'node:child_process'
|
|
39
|
+
|
|
38
40
|
export const name = 'powertoys'
|
|
39
41
|
|
|
40
42
|
/** The projection registry is the whole point; without it this fiber waits. */
|
|
41
43
|
export const inject = ['sessionProjections']
|
|
42
44
|
|
|
45
|
+
/* ------------------------------------------------------------------ *
|
|
46
|
+
* Delayed system shutdown
|
|
47
|
+
*
|
|
48
|
+
* The browser half cannot power off the machine, so the armed "shut down
|
|
49
|
+
* when this turn finishes" switch posts here. Three properties matter:
|
|
50
|
+
*
|
|
51
|
+
* - It is never immediate. A delay (60 s by default) means a wrong click
|
|
52
|
+
* costs a `shutdown /a`, not an unsaved document.
|
|
53
|
+
* - It is cancellable from the same route, and the scheduled instant is
|
|
54
|
+
* readable back so the UI can count down honestly.
|
|
55
|
+
* - It only runs on win32. Writing an untested destructive command for
|
|
56
|
+
* platforms this package cannot exercise would be guessing, so every
|
|
57
|
+
* other platform answers 501 with an explicit message instead.
|
|
58
|
+
* ------------------------------------------------------------------ */
|
|
59
|
+
|
|
60
|
+
const SHUTDOWN_ROUTE = '/powertoys/shutdown'
|
|
61
|
+
const MAX_DELAY_SECONDS = 3600
|
|
62
|
+
/**
|
|
63
|
+
* Floor for the delay. Not a UX nicety: `shutdown /t 0` starts immediately and
|
|
64
|
+
* leaves almost no window to run `shutdown /a`, so a stray request would be
|
|
65
|
+
* indistinguishable from a deliberate one. The floor is enforced here rather
|
|
66
|
+
* than only in the settings input, because this route is reachable on its own.
|
|
67
|
+
*/
|
|
68
|
+
const MIN_DELAY_SECONDS = 10
|
|
69
|
+
const DEFAULT_DELAY_SECONDS = 60
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Master switch for the real thing, read from the environment at request time.
|
|
73
|
+
*
|
|
74
|
+
* Deliberately not a setting in the UI: the point of a kill switch is that it
|
|
75
|
+
* does not depend on the code path it is guarding. Setting
|
|
76
|
+
* `DSH_POWERTOYS_NO_SHUTDOWN=1` before launching DSH leaves every other feature
|
|
77
|
+
* intact and turns this route into a pure preview, which is what verification
|
|
78
|
+
* runs should always use.
|
|
79
|
+
*/
|
|
80
|
+
function shutdownsDisabled() {
|
|
81
|
+
const raw = process.env.DSH_POWERTOYS_NO_SHUTDOWN
|
|
82
|
+
if (raw === undefined) return false
|
|
83
|
+
return !['', '0', 'false', 'no', 'off'].includes(raw.trim().toLowerCase())
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The one pending shutdown, or null.
|
|
88
|
+
*
|
|
89
|
+
* This is a mirror of what we asked Windows to do, not a query — Windows
|
|
90
|
+
* exposes no silent way to ask "is a shutdown pending?". So it is only
|
|
91
|
+
* trustworthy while the deadline is still in the future: someone running
|
|
92
|
+
* `shutdown /a` in another terminal cancels the real thing without telling us,
|
|
93
|
+
* and once the deadline passes the schedule is over either way. `pendingShutdown()`
|
|
94
|
+
* ages the record out on read for exactly that reason, which keeps a cancelled
|
|
95
|
+
* or already-fired schedule from being reported as still armed.
|
|
96
|
+
*/
|
|
97
|
+
let scheduledShutdown = null
|
|
98
|
+
|
|
99
|
+
function pendingShutdown() {
|
|
100
|
+
if (scheduledShutdown === null) return null
|
|
101
|
+
if (Date.now() >= scheduledShutdown.at) {
|
|
102
|
+
scheduledShutdown = null
|
|
103
|
+
return null
|
|
104
|
+
}
|
|
105
|
+
return scheduledShutdown
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function sendJson(res, status, payload) {
|
|
109
|
+
res.statusCode = status
|
|
110
|
+
res.setHeader('content-type', 'application/json; charset=utf-8')
|
|
111
|
+
res.setHeader('cache-control', 'no-store')
|
|
112
|
+
res.end(JSON.stringify(payload))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Collect a bounded request body as UTF-8 text; `undefined` when oversized. */
|
|
116
|
+
function readBoundedBody(req, limit = 64 * 1024) {
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
let size = 0
|
|
119
|
+
const chunks = []
|
|
120
|
+
req.on('data', chunk => {
|
|
121
|
+
size += chunk.length
|
|
122
|
+
if (size > limit) {
|
|
123
|
+
reject(new Error('body too large'))
|
|
124
|
+
req.destroy()
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
chunks.push(chunk)
|
|
128
|
+
})
|
|
129
|
+
req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')))
|
|
130
|
+
req.on('error', reject)
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Run `shutdown` with argv only — never a shell string. */
|
|
135
|
+
function runShutdown(args) {
|
|
136
|
+
return new Promise(resolve => {
|
|
137
|
+
let child
|
|
138
|
+
try {
|
|
139
|
+
child = spawn('shutdown', args, { windowsHide: true, stdio: 'ignore' })
|
|
140
|
+
} catch (error) {
|
|
141
|
+
resolve({ ok: false, message: String(error?.message ?? error) })
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
child.on('error', error => resolve({ ok: false, message: String(error?.message ?? error) }))
|
|
145
|
+
child.on('exit', code => resolve(
|
|
146
|
+
code === 0
|
|
147
|
+
? { ok: true, message: '' }
|
|
148
|
+
: { ok: false, message: `shutdown exited with code ${String(code)}` },
|
|
149
|
+
))
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function scheduleShutdown(delaySeconds) {
|
|
154
|
+
const args = shutdownArgsFor(delaySeconds)
|
|
155
|
+
const result = await runShutdown(args)
|
|
156
|
+
if (!result.ok) return result
|
|
157
|
+
scheduledShutdown = { at: Date.now() + delaySeconds * 1000, delaySeconds }
|
|
158
|
+
return result
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The exact argv a schedule would run.
|
|
163
|
+
*
|
|
164
|
+
* Split out so the dry-run reply can report precisely what it would have done
|
|
165
|
+
* instead of a paraphrase — a preview that cannot be compared against the real
|
|
166
|
+
* call is not a preview.
|
|
167
|
+
*/
|
|
168
|
+
function shutdownArgsFor(delaySeconds) {
|
|
169
|
+
return [
|
|
170
|
+
'/s',
|
|
171
|
+
'/t', String(delaySeconds),
|
|
172
|
+
'/c', 'DSH PowerToys: 本轮输出已完成,即将关机。运行 shutdown /a 可取消。',
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function cancelShutdown() {
|
|
177
|
+
const result = await runShutdown(['/a'])
|
|
178
|
+
scheduledShutdown = null
|
|
179
|
+
return result
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Register the shutdown route.
|
|
184
|
+
*
|
|
185
|
+
* `webServer` and `connection` are requested lazily rather than added to
|
|
186
|
+
* `inject`: if either is missing the timing projection must still register,
|
|
187
|
+
* so a headless host loses the shutdown button and nothing else.
|
|
188
|
+
*
|
|
189
|
+
* @param ctx - registrant context.
|
|
190
|
+
*/
|
|
191
|
+
function registerShutdownRoute(ctx) {
|
|
192
|
+
ctx.inject(['webServer', 'connection'], scope => {
|
|
193
|
+
/** The Host/Origin fence plus login cookie, exactly as shipped routes use it. */
|
|
194
|
+
const rejected = (req, res) => {
|
|
195
|
+
const rejection = scope.connection?.requestRejection?.(req)
|
|
196
|
+
if (rejection === undefined) return false
|
|
197
|
+
res.statusCode = rejection
|
|
198
|
+
res.end()
|
|
199
|
+
return true
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
scope.effect(() => scope.webServer.register({
|
|
203
|
+
kind: 'exact',
|
|
204
|
+
path: SHUTDOWN_ROUTE,
|
|
205
|
+
handler: async (req, res) => {
|
|
206
|
+
if (rejected(req, res)) return
|
|
207
|
+
|
|
208
|
+
if (req.method === 'GET') {
|
|
209
|
+
sendJson(res, 200, {
|
|
210
|
+
platform: process.platform,
|
|
211
|
+
supported: process.platform === 'win32',
|
|
212
|
+
scheduled: pendingShutdown(),
|
|
213
|
+
})
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (req.method !== 'POST') {
|
|
218
|
+
res.statusCode = 405
|
|
219
|
+
res.setHeader('allow', 'GET, POST')
|
|
220
|
+
res.end()
|
|
221
|
+
return
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const contentType = String(req.headers['content-type'] ?? '').split(';', 1)[0].trim().toLowerCase()
|
|
225
|
+
if (contentType !== 'application/json') {
|
|
226
|
+
sendJson(res, 415, { code: 'unsupported-media-type', message: 'content-type must be application/json' })
|
|
227
|
+
return
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
let payload
|
|
231
|
+
try {
|
|
232
|
+
payload = JSON.parse(await readBoundedBody(req))
|
|
233
|
+
} catch {
|
|
234
|
+
sendJson(res, 400, { code: 'bad-request', message: 'body must be a JSON object' })
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) {
|
|
238
|
+
sendJson(res, 400, { code: 'bad-request', message: 'body must be a JSON object' })
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (payload.cancel === true) {
|
|
243
|
+
const result = await cancelShutdown()
|
|
244
|
+
sendJson(res, result.ok ? 200 : 409, {
|
|
245
|
+
cancelled: result.ok,
|
|
246
|
+
message: result.message,
|
|
247
|
+
scheduled: pendingShutdown(),
|
|
248
|
+
})
|
|
249
|
+
return
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (process.platform !== 'win32') {
|
|
253
|
+
sendJson(res, 501, {
|
|
254
|
+
code: 'unsupported-platform',
|
|
255
|
+
message: `auto shutdown is implemented for win32 only; this host is ${process.platform}`,
|
|
256
|
+
})
|
|
257
|
+
return
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const requested = Number(payload.delaySeconds)
|
|
261
|
+
const delaySeconds = Number.isFinite(requested)
|
|
262
|
+
? Math.min(MAX_DELAY_SECONDS, Math.max(MIN_DELAY_SECONDS, Math.round(requested)))
|
|
263
|
+
: DEFAULT_DELAY_SECONDS
|
|
264
|
+
|
|
265
|
+
// Dry run: report the argv without running it.
|
|
266
|
+
//
|
|
267
|
+
// This exists because the honest way to test a shutdown route is to not
|
|
268
|
+
// shut the machine down. Without it, verifying the route means actually
|
|
269
|
+
// arming a real shutdown, and a wrong argument reaches the OS before any
|
|
270
|
+
// assertion can run — which is exactly how this route once powered the
|
|
271
|
+
// machine off during its own verification.
|
|
272
|
+
if (payload.dryRun === true) {
|
|
273
|
+
sendJson(res, 200, {
|
|
274
|
+
dryRun: true,
|
|
275
|
+
delaySeconds,
|
|
276
|
+
argv: shutdownArgsFor(delaySeconds),
|
|
277
|
+
scheduled: pendingShutdown(),
|
|
278
|
+
})
|
|
279
|
+
return
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Re-arm cleanly: a second schedule while one is pending would stack.
|
|
283
|
+
if (shutdownsDisabled()) {
|
|
284
|
+
sendJson(res, 200, {
|
|
285
|
+
dryRun: true,
|
|
286
|
+
disabled: true,
|
|
287
|
+
delaySeconds,
|
|
288
|
+
argv: shutdownArgsFor(delaySeconds),
|
|
289
|
+
scheduled: pendingShutdown(),
|
|
290
|
+
message: 'DSH_POWERTOYS_NO_SHUTDOWN is set; nothing was run.',
|
|
291
|
+
})
|
|
292
|
+
return
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (pendingShutdown() !== null) await cancelShutdown()
|
|
296
|
+
const result = await scheduleShutdown(delaySeconds)
|
|
297
|
+
sendJson(res, result.ok ? 200 : 500, {
|
|
298
|
+
scheduled: pendingShutdown(),
|
|
299
|
+
message: result.message,
|
|
300
|
+
})
|
|
301
|
+
},
|
|
302
|
+
}), `powertoys: ${SHUTDOWN_ROUTE}`)
|
|
303
|
+
})
|
|
304
|
+
}
|
|
305
|
+
|
|
43
306
|
const NUMERIC_FIELDS = [
|
|
44
307
|
'busyMs', 'llmMs', 'toolRawMs', 'approvalMs', 'askMs', 'toolMs',
|
|
45
308
|
'aiWorkingMs',
|
|
@@ -406,6 +669,7 @@ export const powertoysStatsDefinition = {
|
|
|
406
669
|
*/
|
|
407
670
|
export async function apply_(ctx) {
|
|
408
671
|
await ctx.sessionProjections.register(powertoysStatsDefinition)
|
|
672
|
+
registerShutdownRoute(ctx)
|
|
409
673
|
}
|
|
410
674
|
|
|
411
675
|
// Cordis reads `apply` as the plugin body.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-powertoys",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "DSH PowerToys:模块化工作台工具集,支持在设置页独立开关 AI
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "DSH PowerToys:模块化工作台工具集,支持在设置页独立开关 AI 实际工作时长、工作区目录入口、会话内查找、页面刷新、需要确认时的重复提醒音,以及本轮结束提醒与自动关机,即时生效。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "goldenglow",
|