@leiyi-works/dsh-auto-restart 0.1.6 → 0.1.7
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 +4 -2
- package/lib/restart-supervisor.ps1 +30 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
1. 等所有会话空闲(`api-session/status` + `agent/status`),**一直等、没有上限**;
|
|
22
22
|
2. 最后一次会话活动(发消息、回合开始/结束)之后再安静 10 秒,避免刚发出、回合还没起来的消息被重启吞掉、文字回到输入框;
|
|
23
23
|
3. 等插件管理器安静 3 秒(不打断进行中的安装/更新);
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
4. 由 WMI 起一个**脱离进程树、隐藏控制台**的 PowerShell 守护进程;
|
|
25
|
+
5. 守护进程等 `restartDelayMs`(默认 2 秒)→ **先杀 Electron 主进程**(否则 Host 先退出会让主进程弹「DeepSeek Harness 无法使用」并响一声)→ 清掉残留应用进程 → **再用 WMI 拉起应用**(新 DSH 的父进程是 WmiPrvSE,不是本插件的脚本,安全软件不会把新进程树里的文件写入归因到 `dsh-auto-restart`)→ 等主窗口出现 → 按 `maximizeOnRestart` 把窗口最大化 → 写回执。WMI 拉起失败时退回 `Start-Process`。
|
|
26
|
+
|
|
27
|
+
> 少数安全软件(如 360 的「文件防护」)仍可能按进程树把重启后其它会话写图片/文档的行为提示出来;把 DSH 安装目录和 `~/.dsh` 加入信任区即可。
|
|
26
28
|
|
|
27
29
|
会话记录在磁盘上,重启后回到同一个会话。**没有每小时次数上限**,只有 60 秒冷却防止连环重启。
|
|
28
30
|
|
|
@@ -172,22 +172,39 @@ try {
|
|
|
172
172
|
Write-Result 'stopped' ''
|
|
173
173
|
Write-Log 'app stopped; relaunching'
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
175
|
+
# Launch the app through WMI so its parent is WmiPrvSE.exe, not this PowerShell
|
|
176
|
+
# script: security software attributes the new tree's file writes to the closest
|
|
177
|
+
# script in the chain, which kept naming dsh-auto-restart. SW_SHOWMAXIMIZED asks
|
|
178
|
+
# for a maximized window at creation; the ShowWindow call below still guarantees it.
|
|
179
|
+
$workDir = Split-Path -Parent $exe
|
|
180
|
+
$cmdLine = '"' + $exe + '"'
|
|
180
181
|
$argsList = @($spec.launchArgs)
|
|
181
182
|
if ($argsList.Count -gt 0) {
|
|
182
|
-
$
|
|
183
|
+
$quoted = @()
|
|
184
|
+
foreach ($item in $argsList) { $quoted += ('"' + ([string]$item) + '"') }
|
|
185
|
+
$cmdLine = $cmdLine + ' ' + ($quoted -join ' ')
|
|
186
|
+
}
|
|
187
|
+
$newPid = 0
|
|
188
|
+
try {
|
|
189
|
+
$startup = ([wmiclass]'Win32_ProcessStartup').CreateInstance()
|
|
190
|
+
$startup.ShowWindow = 3
|
|
191
|
+
$created = ([wmiclass]'Win32_Process').Create($cmdLine, $workDir, $startup)
|
|
192
|
+
if ($created.ReturnValue -ne 0) { throw ('WMI Win32_Process.Create returned ' + $created.ReturnValue) }
|
|
193
|
+
$newPid = [int]$created.ProcessId
|
|
194
|
+
Write-Log ('relaunched via WMI, pid=' + $newPid)
|
|
195
|
+
} catch {
|
|
196
|
+
Write-Log ('WMI relaunch failed (' + $_.Exception.Message + '); falling back to Start-Process')
|
|
197
|
+
$startArgs = @{ FilePath = $exe; WorkingDirectory = $workDir; PassThru = $true }
|
|
198
|
+
if ($argsList.Count -gt 0) { $startArgs['ArgumentList'] = $argsList }
|
|
199
|
+
$started = Start-Process @startArgs
|
|
200
|
+
$newPid = [int]$started.Id
|
|
201
|
+
Write-Log ('relaunched via Start-Process, pid=' + $newPid)
|
|
183
202
|
}
|
|
184
|
-
$newProcess = Start-Process @startArgs
|
|
185
|
-
Write-Log ('relaunched pid=' + $newProcess.Id)
|
|
186
203
|
|
|
187
204
|
$windowDeadline = (Get-Date).AddSeconds(60)
|
|
188
205
|
$windowUp = $false
|
|
189
206
|
while ((Get-Date) -lt $windowDeadline) {
|
|
190
|
-
$alive = Get-Process -Id $
|
|
207
|
+
$alive = Get-Process -Id $newPid -ErrorAction SilentlyContinue
|
|
191
208
|
if ($alive -eq $null) { break }
|
|
192
209
|
if ($alive.MainWindowHandle -ne 0) { $windowUp = $true; break }
|
|
193
210
|
Start-Sleep -Milliseconds 500
|
|
@@ -197,22 +214,22 @@ try {
|
|
|
197
214
|
Write-Log 'window is up'
|
|
198
215
|
if ($Maximize) {
|
|
199
216
|
$handle = [IntPtr]::Zero
|
|
200
|
-
$current = Get-Process -Id $
|
|
217
|
+
$current = Get-Process -Id $newPid -ErrorAction SilentlyContinue
|
|
201
218
|
if ($current -ne $null) { $handle = $current.MainWindowHandle }
|
|
202
219
|
$maximized = Set-WindowMaximized $handle
|
|
203
220
|
if ($maximized) {
|
|
204
221
|
# The shell may apply its own placement right after showing; do it once more.
|
|
205
222
|
Start-Sleep -Milliseconds 700
|
|
206
|
-
$again = Get-Process -Id $
|
|
223
|
+
$again = Get-Process -Id $newPid -ErrorAction SilentlyContinue
|
|
207
224
|
if ($again -ne $null) { [void](Set-WindowMaximized $again.MainWindowHandle) }
|
|
208
225
|
Write-Log 'window maximized'
|
|
209
226
|
}
|
|
210
227
|
}
|
|
211
|
-
$detail = 'window up, pid=' + $
|
|
228
|
+
$detail = 'window up, pid=' + $newPid
|
|
212
229
|
if ($maximized) { $detail = $detail + ', maximized' }
|
|
213
230
|
Write-Result 'relaunched' $detail
|
|
214
231
|
} else {
|
|
215
|
-
Write-Result 'relaunched-no-window' ('pid=' + $
|
|
232
|
+
Write-Result 'relaunched-no-window' ('pid=' + $newPid + ' no window within 60s')
|
|
216
233
|
Write-Log 'relaunched without a window within 60s'
|
|
217
234
|
}
|
|
218
235
|
exit 0
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leiyi-works/dsh-auto-restart",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"title": "自动重启",
|
|
6
|
-
"description": "装/更插件后自动重启 DSH 并回到原会话:检测 profile
|
|
6
|
+
"description": "装/更插件后自动重启 DSH 并回到原会话:检测 profile 插件文件变化,一直等所有会话空闲且最近活动安静,由脱离进程树的守护者先杀主进程、再用 WMI 拉起(父进程不是插件脚本,减少安全软件误报;可最大化窗口),带冷却、试运行、日志和右侧原生侧边栏面板。",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./index.js",
|