@leiyi-works/dsh-auto-restart 0.0.0-stage → 0.1.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 +95 -2
- package/client.js +427 -0
- package/cordis.patch.yml +17 -0
- package/icon.svg +12 -0
- package/index.js +851 -0
- package/lib/launch-supervisor.ps1 +47 -0
- package/lib/restart-supervisor.ps1 +224 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +54 -3
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-auto-restart · 自动重启
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
装完/更新完插件后,不用再自己关掉 DSH 再打开:它会发现插件文件变了,等所有会话空闲,然后把整个桌面应用重启一次,回到原来的会话,**窗口默认最大化**。
|
|
4
|
+
|
|
5
|
+
只支持 **Windows 桌面端**(Electron 外壳 + Host 子进程的形态)。`dsh web` / headless 不会重启(插件会写日志说明不支持)。
|
|
6
|
+
|
|
7
|
+
左侧菜单有一个「自动重启」面板:状态、上次重启回执、开关与参数都在那里改,改完即时生效。
|
|
8
|
+
|
|
9
|
+
## 它怎么判断"插件变了"
|
|
10
|
+
|
|
11
|
+
盯着当前 profile 的这几处,每 2 秒取一次指纹:
|
|
12
|
+
|
|
13
|
+
- `node_modules/` 顶层条目,以及 `@scope/` 下面的条目(时间、大小、增删)
|
|
14
|
+
- `node_modules-link/`(如果存在)
|
|
15
|
+
- `package.json` 里的 `dependencies` 与 `dsh.profile.bundles`(内容签名)
|
|
16
|
+
|
|
17
|
+
指纹变了并且**稳定 10 秒**没再变,才算一次安装/更新结束。这样 dshmarket、官方插件管理器、手动 `pnpm add`、改自己插件的文件都能覆盖到,而云同步恢复同样的内容(内容签名不变)不会误触发。
|
|
18
|
+
|
|
19
|
+
## 它怎么重启
|
|
20
|
+
|
|
21
|
+
1. 等所有会话空闲(`api-session/status` + `agent/status`),默认最多等 2 分钟;
|
|
22
|
+
2. 等插件管理器安静 3 秒(不打断进行中的安装/更新);
|
|
23
|
+
3. 由 WMI 起一个**脱离进程树、隐藏控制台**的 PowerShell 守护进程;
|
|
24
|
+
4. 守护进程等 `restartDelayMs`(默认 2 秒)→ **先杀 Electron 主进程**(否则 Host 先退出会让主进程弹「DeepSeek Harness 无法使用」并响一声)→ 清掉残留应用进程 → `Start-Process` 拉起应用 → 等主窗口出现 → 按 `maximizeOnRestart` 把窗口最大化 → 写回执。
|
|
25
|
+
|
|
26
|
+
会话记录在磁盘上,重启后回到同一个会话。**没有每小时次数上限**,只有 60 秒冷却防止连环重启。
|
|
27
|
+
|
|
28
|
+
## 安装后第一次
|
|
29
|
+
|
|
30
|
+
第一次安装需要手动重启一次 DSH(托盘「退出」再打开),让 Host 半边的代码加载。之后就不用再管了。
|
|
31
|
+
|
|
32
|
+
**首次默认 `dryRun: true`**:只写日志、不真重启。确认日志里看到「检测到插件文件变化」和「[dry-run] 本应重启」之后,在左侧「自动重启」面板里关掉试运行即可(也可以在 `config.json` 里把 `dryRun` 改成 `false`,改完即时生效,不用重启)。
|
|
33
|
+
|
|
34
|
+
配置文件:`%USERPROFILE%\.dsh\dsh-auto-restart\config.json`(也可以放 `~/...` 形式的可移植路径)。
|
|
35
|
+
|
|
36
|
+
## 左侧面板
|
|
37
|
+
|
|
38
|
+
| 控件 | 说明 |
|
|
39
|
+
|---|---|
|
|
40
|
+
| 启用自动重启 | 总开关 |
|
|
41
|
+
| 试运行(dryRun) | 只记日志不重启 |
|
|
42
|
+
| 重启后最大化窗口 | 守护进程拉起应用后把主窗口最大化 |
|
|
43
|
+
| 等所有会话空闲再重启 | 有回答在跑时先等 |
|
|
44
|
+
| 文件稳定判定 | 默认 10 秒 |
|
|
45
|
+
| 两次重启冷却 | 默认 60 秒 |
|
|
46
|
+
| 等空闲上限 | 默认 120 秒,超时放弃本次 |
|
|
47
|
+
| 立即重启 | 手动触发一次(有会话在跑时会被拒绝) |
|
|
48
|
+
|
|
49
|
+
## 配置
|
|
50
|
+
|
|
51
|
+
| 键 | 默认 | 说明 |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| `enabled` | `true` | 总开关 |
|
|
54
|
+
| `dryRun` | `true` | 只记日志不重启;验证后改 `false` |
|
|
55
|
+
| `stableMs` | `10000` | 文件停止变化多久算安装完成 |
|
|
56
|
+
| `pollIntervalMs` | `2000` | 轮询间隔 |
|
|
57
|
+
| `managerQuietMs` | `3000` | 插件管理器最后一次活动后至少安静多久 |
|
|
58
|
+
| `cooldownMs` | `60000` | 两次重启最小间隔(跨重启持久化) |
|
|
59
|
+
| `maxPerHour` | `0` | 每小时上限;`0` = 不限制 |
|
|
60
|
+
| `waitForIdle` | `true` | 等会话空闲再重启 |
|
|
61
|
+
| `maxIdleWaitMs` | `120000` | 等空闲上限,超时放弃本次 |
|
|
62
|
+
| `forceWhenBusy` | `false` | 超时后是否强重启 |
|
|
63
|
+
| `restartDelayMs` | `2000` | 守护进程收到请求后等多久动手 |
|
|
64
|
+
| `maximizeOnRestart` | `true` | 重启后最大化主窗口 |
|
|
65
|
+
| `exePath` | `''` | 应用可执行文件,留空自动推导 |
|
|
66
|
+
| `launchArgs` | `[]` | 拉起应用时的附加参数 |
|
|
67
|
+
| `supervisorScript` | `''` | 自定义守护脚本路径 |
|
|
68
|
+
| `powershellPath` | `''` | 自定义 powershell.exe |
|
|
69
|
+
| `profileDir` | `''` | 自定义 profile 目录 |
|
|
70
|
+
| `logMaxBytes` | `1048576` | 日志滚动阈值 |
|
|
71
|
+
|
|
72
|
+
## 急停
|
|
73
|
+
|
|
74
|
+
在 `%USERPROFILE%\.dsh\dsh-auto-restart\` 下新建一个空文件 `disabled`,它立刻什么都不做(每 2 秒检查一次)。删掉就恢复。
|
|
75
|
+
|
|
76
|
+
## 状态与日志
|
|
77
|
+
|
|
78
|
+
- 日志:`%USERPROFILE%\.dsh\dsh-auto-restart\auto-restart.log`
|
|
79
|
+
- 上次重启回执:`restart-result.json`;上次请求:`last-restart.json`
|
|
80
|
+
- 状态:`GET http://127.0.0.1:<Host 端口>/auto-restart/status`(只接受本机回环)
|
|
81
|
+
- 配置:`GET/POST /auto-restart/config`
|
|
82
|
+
|
|
83
|
+
## 卸载
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
dsh plugin --profile desktop remove @leiyi-works/dsh-auto-restart
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`%USERPROFILE%\.dsh\dsh-auto-restart\` 里的日志和配置可以留也可以删。
|
|
90
|
+
|
|
91
|
+
## 边界
|
|
92
|
+
|
|
93
|
+
- 只重启应用,不动其它进程。
|
|
94
|
+
- 正在跑的任务会被重启打断——所以先等空闲;`maxIdleWaitMs` 超时默认放弃本次。
|
|
95
|
+
- 不碰 `app.asar`,DSH 升级不受影响。
|
|
96
|
+
- 桌面端正式构建没有可用重启入口(官方菜单项只在 development 构建出现),所以只能用外部守护进程的方式;这也是为什么需要一次引导重启。
|
package/client.js
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-auto-restart — Client half.
|
|
3
|
+
*
|
|
4
|
+
* 左侧菜单一个「自动重启」入口,打开全页面板;面板读写 Host 的
|
|
5
|
+
* /auto-restart 路由:
|
|
6
|
+
* GET /auto-restart/status 运行状态、基线、上次重启回执
|
|
7
|
+
* GET /auto-restart/config 当前生效配置
|
|
8
|
+
* POST /auto-restart/config 保存配置(只提交改动的键)
|
|
9
|
+
* POST /auto-restart/restart 立即重启(有会话在跑时由 Host 拒绝)
|
|
10
|
+
*
|
|
11
|
+
* 面板只做展示与改配置,真正的重启由 Host + 守护进程完成。
|
|
12
|
+
*/
|
|
13
|
+
window.__ModuleLoader__.load({
|
|
14
|
+
id: '@leiyi-works/dsh-auto-restart',
|
|
15
|
+
factory(require) {
|
|
16
|
+
const React = require('react')
|
|
17
|
+
const h = React.createElement
|
|
18
|
+
const { useCallback, useEffect, useRef, useState } = React
|
|
19
|
+
|
|
20
|
+
/** Global panel id shared by the sidebar row and the main page. */
|
|
21
|
+
const PANEL_ID = 'auto-restart'
|
|
22
|
+
const API = '/auto-restart'
|
|
23
|
+
const REFRESH_MS = 5000
|
|
24
|
+
|
|
25
|
+
const styles = {
|
|
26
|
+
root: {
|
|
27
|
+
height: '100%',
|
|
28
|
+
overflow: 'auto',
|
|
29
|
+
boxSizing: 'border-box',
|
|
30
|
+
padding: '14px 16px 28px',
|
|
31
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
32
|
+
fontSize: 13,
|
|
33
|
+
lineHeight: 1.55,
|
|
34
|
+
},
|
|
35
|
+
inner: { display: 'flex', flexDirection: 'column', gap: 14, maxWidth: 760 },
|
|
36
|
+
header: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' },
|
|
37
|
+
title: { margin: 0, fontSize: 16, fontWeight: 600 },
|
|
38
|
+
badge: {
|
|
39
|
+
fontSize: 11,
|
|
40
|
+
lineHeight: '18px',
|
|
41
|
+
padding: '0 8px',
|
|
42
|
+
borderRadius: 999,
|
|
43
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.10))',
|
|
44
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
45
|
+
},
|
|
46
|
+
badgeGood: {
|
|
47
|
+
fontSize: 11,
|
|
48
|
+
lineHeight: '18px',
|
|
49
|
+
padding: '0 8px',
|
|
50
|
+
borderRadius: 999,
|
|
51
|
+
background: 'rgba(46,160,67,.16)',
|
|
52
|
+
color: 'var(--dsw-alias-state-success-primary, #2ea043)',
|
|
53
|
+
},
|
|
54
|
+
badgeWarn: {
|
|
55
|
+
fontSize: 11,
|
|
56
|
+
lineHeight: '18px',
|
|
57
|
+
padding: '0 8px',
|
|
58
|
+
borderRadius: 999,
|
|
59
|
+
background: 'rgba(210,120,0,.16)',
|
|
60
|
+
color: 'var(--dsw-alias-state-warning-primary, #c27c00)',
|
|
61
|
+
},
|
|
62
|
+
subtitle: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-label-secondary)' },
|
|
63
|
+
card: {
|
|
64
|
+
display: 'flex',
|
|
65
|
+
flexDirection: 'column',
|
|
66
|
+
gap: 10,
|
|
67
|
+
border: '1px solid var(--dsw-alias-border-l1, rgba(127,127,127,.22))',
|
|
68
|
+
borderRadius: 10,
|
|
69
|
+
padding: '12px 14px',
|
|
70
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.04))',
|
|
71
|
+
},
|
|
72
|
+
cardTitle: { margin: 0, fontSize: 13, fontWeight: 600 },
|
|
73
|
+
row: { display: 'flex', alignItems: 'center', gap: 10, justifyContent: 'space-between' },
|
|
74
|
+
rowMain: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 },
|
|
75
|
+
rowLabel: { fontSize: 13 },
|
|
76
|
+
rowHint: { fontSize: 11.5, color: 'var(--dsw-alias-label-secondary)' },
|
|
77
|
+
kvs: { display: 'grid', gridTemplateColumns: 'auto 1fr', columnGap: 12, rowGap: 4, fontSize: 12 },
|
|
78
|
+
key: { color: 'var(--dsw-alias-label-secondary)' },
|
|
79
|
+
val: { fontFamily: 'ui-monospace, Consolas, monospace', fontSize: 11.5, wordBreak: 'break-all' },
|
|
80
|
+
switch: { width: 16, height: 16, accentColor: 'var(--dsw-alias-accent-primary, #4f7cff)', cursor: 'pointer' },
|
|
81
|
+
num: {
|
|
82
|
+
width: 92,
|
|
83
|
+
padding: '3px 8px',
|
|
84
|
+
borderRadius: 7,
|
|
85
|
+
border: '1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))',
|
|
86
|
+
background: 'transparent',
|
|
87
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
88
|
+
fontSize: 12,
|
|
89
|
+
},
|
|
90
|
+
btn: {
|
|
91
|
+
appearance: 'none',
|
|
92
|
+
cursor: 'pointer',
|
|
93
|
+
borderRadius: 7,
|
|
94
|
+
padding: '5px 14px',
|
|
95
|
+
fontSize: 12,
|
|
96
|
+
lineHeight: '18px',
|
|
97
|
+
border: '1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))',
|
|
98
|
+
background: 'transparent',
|
|
99
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
100
|
+
},
|
|
101
|
+
btnPrimary: {
|
|
102
|
+
appearance: 'none',
|
|
103
|
+
cursor: 'pointer',
|
|
104
|
+
borderRadius: 7,
|
|
105
|
+
padding: '5px 14px',
|
|
106
|
+
fontSize: 12,
|
|
107
|
+
lineHeight: '18px',
|
|
108
|
+
border: '1px solid var(--dsw-alias-accent-primary, #4f7cff)',
|
|
109
|
+
background: 'var(--dsw-alias-accent-primary, #4f7cff)',
|
|
110
|
+
color: '#fff',
|
|
111
|
+
},
|
|
112
|
+
bar: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' },
|
|
113
|
+
note: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-label-secondary)' },
|
|
114
|
+
ok: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-state-success-primary, #2ea043)' },
|
|
115
|
+
err: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-state-error-primary, #d14a4a)' },
|
|
116
|
+
loading: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-label-secondary)' },
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function fmtTime(iso) {
|
|
120
|
+
if (typeof iso !== 'string' || iso === '') return '—'
|
|
121
|
+
try {
|
|
122
|
+
const date = new Date(iso)
|
|
123
|
+
if (Number.isNaN(date.getTime())) return iso
|
|
124
|
+
const two = (n) => String(n).padStart(2, '0')
|
|
125
|
+
return `${date.getFullYear()}-${two(date.getMonth() + 1)}-${two(date.getDate())} ${two(date.getHours())}:${two(date.getMinutes())}:${two(date.getSeconds())}`
|
|
126
|
+
} catch {
|
|
127
|
+
return iso
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function phaseLabel(phase) {
|
|
132
|
+
if (phase === 'relaunched') return '成功(窗口已出现)'
|
|
133
|
+
if (phase === 'relaunched-no-window') return '已拉起,但没等到窗口'
|
|
134
|
+
if (phase === 'stopped') return '进行中(旧进程已停)'
|
|
135
|
+
if (phase === 'aborted') return '已中止'
|
|
136
|
+
if (phase === 'failed') return '失败'
|
|
137
|
+
return phase === undefined || phase === null ? '—' : String(phase)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function getJson(url) {
|
|
141
|
+
const response = await fetch(url, { headers: { accept: 'application/json' } })
|
|
142
|
+
const body = await response.json().catch(() => ({}))
|
|
143
|
+
if (!response.ok || body.ok === false) throw new Error(body.error ?? `HTTP ${response.status}`)
|
|
144
|
+
return body
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function postJson(url, payload) {
|
|
148
|
+
const response = await fetch(url, {
|
|
149
|
+
method: 'POST',
|
|
150
|
+
headers: { 'content-type': 'application/json', 'x-dsh-auto-restart': '1' },
|
|
151
|
+
body: JSON.stringify(payload ?? {}),
|
|
152
|
+
})
|
|
153
|
+
const body = await response.json().catch(() => ({}))
|
|
154
|
+
if (!response.ok || body.ok === false) throw new Error(body.error ?? `HTTP ${response.status}`)
|
|
155
|
+
return body
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function SwitchRow({ label, hint, checked, onChange, disabled }) {
|
|
159
|
+
return h(
|
|
160
|
+
'div',
|
|
161
|
+
{ style: styles.row },
|
|
162
|
+
h('div', { style: styles.rowMain }, h('div', { style: styles.rowLabel }, label), hint ? h('div', { style: styles.rowHint }, hint) : null),
|
|
163
|
+
h('input', {
|
|
164
|
+
type: 'checkbox',
|
|
165
|
+
style: styles.switch,
|
|
166
|
+
checked: checked === true,
|
|
167
|
+
disabled: disabled === true,
|
|
168
|
+
onChange: (event) => onChange(event.target.checked),
|
|
169
|
+
}),
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function NumberRow({ label, hint, value, min, max, step, suffix, onChange, disabled }) {
|
|
174
|
+
return h(
|
|
175
|
+
'div',
|
|
176
|
+
{ style: styles.row },
|
|
177
|
+
h('div', { style: styles.rowMain }, h('div', { style: styles.rowLabel }, label), hint ? h('div', { style: styles.rowHint }, hint) : null),
|
|
178
|
+
h(
|
|
179
|
+
'span',
|
|
180
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6 } },
|
|
181
|
+
h('input', {
|
|
182
|
+
type: 'number',
|
|
183
|
+
style: styles.num,
|
|
184
|
+
value: Number.isFinite(value) ? Math.round(value) : 0,
|
|
185
|
+
min,
|
|
186
|
+
max,
|
|
187
|
+
step: step ?? 1,
|
|
188
|
+
disabled: disabled === true,
|
|
189
|
+
onChange: (event) => onChange(Number(event.target.value)),
|
|
190
|
+
}),
|
|
191
|
+
h('span', { style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } }, suffix ?? ''),
|
|
192
|
+
),
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function AutoRestartPanel() {
|
|
197
|
+
const [state, setState] = useState({ loading: true, error: '', status: null, config: null })
|
|
198
|
+
const [save, setSave] = useState({ busy: false, error: '', ok: '' })
|
|
199
|
+
const [restarting, setRestarting] = useState(false)
|
|
200
|
+
const dirty = useRef(false)
|
|
201
|
+
|
|
202
|
+
const load = useCallback(async () => {
|
|
203
|
+
try {
|
|
204
|
+
const [status, config] = await Promise.all([getJson(`${API}/status`), getJson(`${API}/config`)])
|
|
205
|
+
setState({ loading: false, error: '', status, config: config.config })
|
|
206
|
+
} catch (error) {
|
|
207
|
+
setState((current) => ({ ...current, loading: false, error: String(error?.message ?? error) }))
|
|
208
|
+
}
|
|
209
|
+
}, [])
|
|
210
|
+
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
load()
|
|
213
|
+
const timer = setInterval(() => {
|
|
214
|
+
if (!dirty.current) load()
|
|
215
|
+
}, REFRESH_MS)
|
|
216
|
+
return () => clearInterval(timer)
|
|
217
|
+
}, [load])
|
|
218
|
+
|
|
219
|
+
const saveConfig = useCallback(async (patch) => {
|
|
220
|
+
dirty.current = false
|
|
221
|
+
setSave({ busy: true, error: '', ok: '' })
|
|
222
|
+
try {
|
|
223
|
+
const body = await postJson(`${API}/config`, patch)
|
|
224
|
+
setState((current) => ({ ...current, config: body.config }))
|
|
225
|
+
setSave({ busy: false, error: '', ok: '已保存' })
|
|
226
|
+
setTimeout(() => setSave((current) => (current.ok === '已保存' ? { busy: false, error: '', ok: '' } : current)), 2500)
|
|
227
|
+
} catch (error) {
|
|
228
|
+
setSave({ busy: false, error: String(error?.message ?? error), ok: '' })
|
|
229
|
+
}
|
|
230
|
+
}, [])
|
|
231
|
+
|
|
232
|
+
const change = useCallback((patch) => {
|
|
233
|
+
dirty.current = true
|
|
234
|
+
setState((current) => (current.config === null ? current : { ...current, config: { ...current.config, ...patch } }))
|
|
235
|
+
saveConfig(patch)
|
|
236
|
+
}, [saveConfig])
|
|
237
|
+
|
|
238
|
+
const restartNow = useCallback(async () => {
|
|
239
|
+
setRestarting(true)
|
|
240
|
+
setSave({ busy: false, error: '', ok: '' })
|
|
241
|
+
try {
|
|
242
|
+
const body = await postJson(`${API}/restart`, {})
|
|
243
|
+
setSave({
|
|
244
|
+
busy: false,
|
|
245
|
+
error: '',
|
|
246
|
+
ok: body.dryRun === true ? '当前是试运行模式,只记录了日志,没有真的重启' : '已派发重启,DSH 会在这条消息送达后关闭并重新打开',
|
|
247
|
+
})
|
|
248
|
+
} catch (error) {
|
|
249
|
+
setSave({ busy: false, error: String(error?.message ?? error), ok: '' })
|
|
250
|
+
} finally {
|
|
251
|
+
setRestarting(false)
|
|
252
|
+
}
|
|
253
|
+
}, [])
|
|
254
|
+
|
|
255
|
+
const status = state.status
|
|
256
|
+
const config = state.config
|
|
257
|
+
const badge = config === null
|
|
258
|
+
? h('span', { style: styles.badge }, '读取中')
|
|
259
|
+
: config.enabled === false
|
|
260
|
+
? h('span', { style: styles.badgeWarn }, '已停用')
|
|
261
|
+
: config.dryRun === true
|
|
262
|
+
? h('span', { style: styles.badgeWarn }, '试运行(只记日志)')
|
|
263
|
+
: h('span', { style: styles.badgeGood }, '运行中')
|
|
264
|
+
|
|
265
|
+
const statusCard = h(
|
|
266
|
+
'section',
|
|
267
|
+
{ style: styles.card },
|
|
268
|
+
h('h2', { style: styles.cardTitle }, '运行状态'),
|
|
269
|
+
state.loading
|
|
270
|
+
? h('p', { style: styles.loading }, '正在读取…')
|
|
271
|
+
: status === null
|
|
272
|
+
? h('p', { style: styles.err }, state.error || '读取失败')
|
|
273
|
+
: h(
|
|
274
|
+
'div',
|
|
275
|
+
{ style: styles.kvs },
|
|
276
|
+
h('span', { style: styles.key }, '上次重启'),
|
|
277
|
+
h('span', { style: styles.val }, status.lastResult === null ? '—' : `${phaseLabel(status.lastResult.phase)} · ${fmtTime(status.lastResult.at)}`),
|
|
278
|
+
h('span', { style: styles.key }, '上次原因'),
|
|
279
|
+
h('span', { style: styles.val }, status.lastResult?.detail ?? '—'),
|
|
280
|
+
h('span', { style: styles.key }, '待重启'),
|
|
281
|
+
h('span', { style: styles.val }, status.pending ? '是(等条件满足就重启)' : '否'),
|
|
282
|
+
h('span', { style: styles.key }, '会话忙闲'),
|
|
283
|
+
h('span', { style: styles.val }, (status.busySessions ?? []).length === 0 ? '空闲' : `${status.busySessions.length} 个在跑`),
|
|
284
|
+
h('span', { style: styles.key }, '插件基线'),
|
|
285
|
+
h('span', { style: styles.val }, `${status.baseline ?? '—'} / 当前 ${status.current ?? '—'}`),
|
|
286
|
+
h('span', { style: styles.key }, '日志'),
|
|
287
|
+
h('span', { style: styles.val }, status.logPath ?? '—'),
|
|
288
|
+
status.disabled
|
|
289
|
+
? [h('span', { key: 'k', style: styles.key }, '急停'), h('span', { key: 'v', style: styles.err }, 'disabled 文件存在:插件不会做任何事')]
|
|
290
|
+
: null,
|
|
291
|
+
),
|
|
292
|
+
h(
|
|
293
|
+
'div',
|
|
294
|
+
{ style: styles.bar },
|
|
295
|
+
h('button', { type: 'button', style: styles.btnPrimary, onClick: restartNow, disabled: restarting || config === null }, restarting ? '正在派发…' : '立即重启'),
|
|
296
|
+
h('button', { type: 'button', style: styles.btn, onClick: load }, '刷新'),
|
|
297
|
+
status?.desktopHost === false ? h('span', { style: styles.err }, '当前宿主不是 Windows 桌面端,重启不可用') : null,
|
|
298
|
+
),
|
|
299
|
+
save.error ? h('p', { style: styles.err }, `操作失败:${save.error}`) : null,
|
|
300
|
+
save.ok ? h('p', { style: styles.ok }, save.ok) : null,
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
const settingsCard = config === null
|
|
304
|
+
? null
|
|
305
|
+
: h(
|
|
306
|
+
'section',
|
|
307
|
+
{ style: styles.card },
|
|
308
|
+
h('h2', { style: styles.cardTitle }, '设置'),
|
|
309
|
+
h(SwitchRow, {
|
|
310
|
+
label: '启用自动重启',
|
|
311
|
+
hint: '关闭后不会因为插件变化而重启;状态接口和这个面板仍然可用。',
|
|
312
|
+
checked: config.enabled !== false,
|
|
313
|
+
onChange: (value) => change({ enabled: value }),
|
|
314
|
+
}),
|
|
315
|
+
h(SwitchRow, {
|
|
316
|
+
label: '试运行(dryRun)',
|
|
317
|
+
hint: '只写日志、不真的重启。用来确认它会在什么时候动手。',
|
|
318
|
+
checked: config.dryRun === true,
|
|
319
|
+
onChange: (value) => change({ dryRun: value }),
|
|
320
|
+
}),
|
|
321
|
+
h(SwitchRow, {
|
|
322
|
+
label: '重启后最大化窗口',
|
|
323
|
+
hint: '守护进程拉起应用后,把主窗口最大化。',
|
|
324
|
+
checked: config.maximizeOnRestart !== false,
|
|
325
|
+
onChange: (value) => change({ maximizeOnRestart: value }),
|
|
326
|
+
}),
|
|
327
|
+
h(SwitchRow, {
|
|
328
|
+
label: '等所有会话空闲再重启',
|
|
329
|
+
hint: '有回答或任务在跑时先等它们结束,避免截断。',
|
|
330
|
+
checked: config.waitForIdle !== false,
|
|
331
|
+
onChange: (value) => change({ waitForIdle: value }),
|
|
332
|
+
}),
|
|
333
|
+
h(NumberRow, {
|
|
334
|
+
label: '文件稳定判定',
|
|
335
|
+
hint: '插件文件停止变化多久才算安装完成。',
|
|
336
|
+
value: Math.round((config.stableMs ?? 10000) / 1000),
|
|
337
|
+
min: 1,
|
|
338
|
+
max: 600,
|
|
339
|
+
suffix: '秒',
|
|
340
|
+
onChange: (value) => change({ stableMs: Math.max(0, Math.round(value)) * 1000 }),
|
|
341
|
+
}),
|
|
342
|
+
h(NumberRow, {
|
|
343
|
+
label: '两次重启冷却',
|
|
344
|
+
hint: '两次自动重启之间至少间隔这么久。',
|
|
345
|
+
value: Math.round((config.cooldownMs ?? 60000) / 1000),
|
|
346
|
+
min: 0,
|
|
347
|
+
max: 3600,
|
|
348
|
+
suffix: '秒',
|
|
349
|
+
onChange: (value) => change({ cooldownMs: Math.max(0, Math.round(value)) * 1000 }),
|
|
350
|
+
}),
|
|
351
|
+
h(NumberRow, {
|
|
352
|
+
label: '等空闲上限',
|
|
353
|
+
hint: '超时还没有空闲就按「放弃本次」处理(除非另开了强制重启)。',
|
|
354
|
+
value: Math.round((config.maxIdleWaitMs ?? 120000) / 1000),
|
|
355
|
+
min: 10,
|
|
356
|
+
max: 3600,
|
|
357
|
+
suffix: '秒',
|
|
358
|
+
onChange: (value) => change({ maxIdleWaitMs: Math.max(0, Math.round(value)) * 1000 }),
|
|
359
|
+
}),
|
|
360
|
+
h('p', { style: styles.note }, '改动即时保存、即时生效,不需要重启 DSH。'),
|
|
361
|
+
)
|
|
362
|
+
|
|
363
|
+
return h(
|
|
364
|
+
'div',
|
|
365
|
+
{ style: styles.root },
|
|
366
|
+
h(
|
|
367
|
+
'div',
|
|
368
|
+
{ style: styles.inner },
|
|
369
|
+
h('header', { style: styles.header }, h('h1', { style: styles.title }, '自动重启'), badge),
|
|
370
|
+
h('p', { style: styles.subtitle }, '装完或更新完插件后,等所有会话空闲,自动重启 DSH 并回到原会话;重启后默认最大化窗口。'),
|
|
371
|
+
save.busy ? h('p', { style: styles.note }, '正在保存…') : null,
|
|
372
|
+
statusCard,
|
|
373
|
+
settingsCard,
|
|
374
|
+
h('p', { style: styles.note }, '配置文件:' + (status?.configPath ?? '—') + ' 急停:在同目录新建空文件 disabled'),
|
|
375
|
+
),
|
|
376
|
+
)
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function AutoRestartIcon(props) {
|
|
380
|
+
const size = typeof props?.size === 'number' && props.size > 0 ? props.size : 18
|
|
381
|
+
return h(
|
|
382
|
+
'svg',
|
|
383
|
+
{
|
|
384
|
+
width: size,
|
|
385
|
+
height: size,
|
|
386
|
+
viewBox: '0 0 24 24',
|
|
387
|
+
fill: 'none',
|
|
388
|
+
'aria-hidden': true,
|
|
389
|
+
style: { display: 'block' },
|
|
390
|
+
},
|
|
391
|
+
h('path', {
|
|
392
|
+
d: 'M19.5 12a7.5 7.5 0 1 1-2.6-5.7',
|
|
393
|
+
stroke: 'currentColor',
|
|
394
|
+
strokeWidth: 1.7,
|
|
395
|
+
strokeLinecap: 'round',
|
|
396
|
+
}),
|
|
397
|
+
h('path', {
|
|
398
|
+
d: 'M18.6 3.6v5h-5',
|
|
399
|
+
stroke: 'currentColor',
|
|
400
|
+
strokeWidth: 1.7,
|
|
401
|
+
strokeLinecap: 'round',
|
|
402
|
+
strokeLinejoin: 'round',
|
|
403
|
+
}),
|
|
404
|
+
)
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return {
|
|
408
|
+
name: '@leiyi-works/dsh-auto-restart',
|
|
409
|
+
inject: ['slots', 'layout'],
|
|
410
|
+
apply(ctx) {
|
|
411
|
+
// 左侧菜单入口。
|
|
412
|
+
ctx.effect(
|
|
413
|
+
() =>
|
|
414
|
+
ctx.slots.inject('sidebar.panellist', () =>
|
|
415
|
+
ctx.slots.register({ name: 'sidebar.panellist', id: PANEL_ID, order: 48, label: '自动重启' }, AutoRestartIcon),
|
|
416
|
+
),
|
|
417
|
+
'dsh-auto-restart: sidebar entry',
|
|
418
|
+
)
|
|
419
|
+
// 点入口打开全页面板。
|
|
420
|
+
ctx.effect(
|
|
421
|
+
() => ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL_ID }, AutoRestartPanel)),
|
|
422
|
+
'dsh-auto-restart: panel page',
|
|
423
|
+
)
|
|
424
|
+
},
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
})
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# dsh-auto-restart — 自动重启(bundle 补丁)
|
|
2
|
+
#
|
|
3
|
+
# 定位:装完/更新完插件(或改了自己插件的文件)之后,不必再手动退出再打开。
|
|
4
|
+
# 本 bundle 插入一行 Host 插件;它监听 profile 的插件文件变化,等所有会话空闲,
|
|
5
|
+
# 再由一个脱离 DSH 进程树的守护进程:先杀 Electron 主进程(避免官方「无法使用」
|
|
6
|
+
# 弹框),清掉残留进程,重新拉起应用。
|
|
7
|
+
#
|
|
8
|
+
# 为什么需要这一行:DSH 的插件管理器只在"需要重启"时提示,桌面端正式构建里
|
|
9
|
+
# 没有可用的重启入口(官方菜单里的「重启应用与 Host」只在 development 构建出现);
|
|
10
|
+
# 而 Host 是 Electron 主进程的子进程,Host 自己无法让父进程 relaunch。
|
|
11
|
+
#
|
|
12
|
+
# 运行参数默认从 <DSH_HOME>/dsh-auto-restart/config.json 读,改文件即时生效
|
|
13
|
+
# (不需要重启)。首次安装默认 dryRun=true:只写日志、不真重启,确认无误后把
|
|
14
|
+
# config.json 里的 dryRun 改成 false。
|
|
15
|
+
- insert:
|
|
16
|
+
- id: auto-restart
|
|
17
|
+
name: '@leiyi-works/dsh-auto-restart'
|
package/icon.svg
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" role="img" aria-label="Auto restart">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
|
|
4
|
+
<stop offset="0" stop-color="#4f7cff"/>
|
|
5
|
+
<stop offset="1" stop-color="#7b5cff"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<rect x="2" y="2" width="60" height="60" rx="16" fill="url(#g)"/>
|
|
9
|
+
<path d="M44 32a12 12 0 1 1-4.2-9.2" fill="none" stroke="#ffffff" stroke-width="5" stroke-linecap="round"/>
|
|
10
|
+
<path d="M42 14v11H31" fill="none" stroke="#ffffff" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
11
|
+
<circle cx="32" cy="32" r="3.2" fill="#ffffff" opacity="0.9"/>
|
|
12
|
+
</svg>
|