dsh-mcviseron-plugin 0.8.3 → 0.8.4

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 CHANGED
@@ -1,17 +1,12 @@
1
- ## [0.8.3] - 2026-11-22
1
+ ## [0.8.4] - 2026-12-06
2
2
 
3
3
  ### Fixed
4
4
 
5
- - **任务列表 todo 不翻译**:`translateTodoContent` 之前只构造 notice,官方任务面板仍显示英文。现在通过 `session.append('todo/write', { todos })` 写入「中文(English)」的新快照;未来 `todo_write` 在 `todo/write` 事件后迁移,已有列表在下一次 `agent/pre-step` / turn 边界迁移,状态不变。
6
- - 注意:DSH 在 `tools/pre-execute` 前会 deepFreeze 工具参数,不能直接改写 `todo_write` arguments;因此采用 session 快照迁移,而不是修改执行参数。
7
-
8
- ### Docs
9
-
10
- - README / SECURITY / 设置项文案说明:`translateTodoContent` 会写入并显示中文标题,已有列表下次 turn 迁移。
5
+ - **Windows 重启偶发只关闭不拉起**:Task Scheduler 在旧 Electron/Host 尚未完全退出时就启动新实例,单实例锁会让新进程直接退出。现在任务 action 改为隐藏的 PowerShell helper,先等待旧 main/host PID 消失(最多 30 秒),再启动应用;设置页和侧边栏共用同一路由,二者都修复。
11
6
 
12
7
  ### Tests
13
8
 
14
- - 合计 **130 项测试**;typecheck、build 全绿。
9
+ - 合计 **131 项测试**;typecheck、build 全绿。
15
10
 
16
11
  ## [0.8.3] - 2026-11-22
17
12
 
@@ -19,11 +14,20 @@
19
14
 
20
15
  - **侧边栏底部重启快捷入口**:注册 `sidebar.footer.action`,在设置菜单上方增加「重启 DSH」按钮;宽栏显示图标+文字,窄栏只显示图标。点击复用现有重启路由,设置页的重启/关闭按钮保持不变。路由不可用时按钮自动隐藏。
21
16
 
17
+ ### Fixed
18
+
19
+ - **任务列表 todo 不翻译**:`translateTodoContent` 之前只构造 notice,官方任务面板仍显示英文。现在通过 `session.append('todo/write', { todos })` 写入「中文(English)」的新快照;未来 `todo_write` 在 `todo/write` 事件后迁移,已有列表在下一次 `agent/pre-step` / turn 边界迁移,状态不变。
20
+ - 注意:DSH 在 `tools/pre-execute` 前会 deepFreeze 工具参数,不能直接改写 `todo_write` arguments;因此采用 session 快照迁移,而不是修改执行参数。
21
+
22
+ ### Docs
23
+
24
+ - README / SECURITY / 设置项文案说明:`translateTodoContent` 会写入并显示中文标题,已有列表下次 turn 迁移。
25
+
22
26
  ### Tests
23
27
 
24
28
  - 合计 **130 项测试**;typecheck、build 全绿。
25
29
 
26
- ## [0.8.2] - 2026-11-22
30
+ ## [0.8.2] - 2026-11-22(未发布,由 0.8.3 取代)
27
31
 
28
32
  ### Fixed
29
33
 
@@ -43,7 +47,7 @@
43
47
 
44
48
  - 129 项测试;typecheck、build 全绿。
45
49
 
46
- ## [0.8.0] - 2026-11-22
50
+ ## [0.8.0] - 2026-11-22(未发布,由 0.8.1 取代)
47
51
 
48
52
  ### Added
49
53
 
@@ -55,20 +59,6 @@
55
59
 
56
60
  - 合计 **129 项测试**;typecheck、build 全绿。
57
61
 
58
- ## [Unreleased]
59
-
60
- ### 计划中
61
-
62
- - 将「按时间切换」扩展为多时段表(例如白天的多个浅色窗口)。
63
- - 设置行支持「立即测试」预览按钮。
64
- - Restart 组件支持 macOS/Linux(当前仅 Windows 桌面版)。
65
-
66
- ## [Unreleased]
67
-
68
- ### Docs
69
-
70
- - 在 `docs/automation-tasks.md` 补充 Host Schedule 管理 API:0.2.2 的 `list({}) -> { items }`、`create(request, sessionId, signal)`、`edit({ id, action, patch }, sessionId, signal)`,以及旧版 `list({ sessionId })` / `create(sessionId, request)` / `update` / `delete` 的兼容层与 timing 映射;README 组件表加入文档链接。
71
-
72
62
  ## [0.7.8] - 2026-11-22
73
63
 
74
64
  ### Fixed
package/README.en.md CHANGED
@@ -155,12 +155,12 @@ Defaults: appearance off / `08:00–23:00`; auto-review both guards on, 6 s, 400
155
155
 
156
156
  | DSH version | Status |
157
157
  | --- | --- |
158
- | `0.2.2-rc.5` | ✅ pre-adapted (0.2.2-rc.5 types/deps + 130 tests; current desktop still rc.3) |
159
- | `0.2.2-rc.3` | ✅ current desktop (rc.3 types/deps + 130 tests; real runtime verified) |
160
- | `0.2.2-rc.1` | ✅ compatible (0.2.2-rc.1 types/deps + 130 tests) |
161
- | `0.2.1-rc.5` | ✅ compatible (rc.5 types/deps + 130 tests) |
162
- | `0.2.1-rc.3` | ✅ compatible (rc.3 types/deps + 130 tests) |
163
- | `0.2.1-rc.2` | ✅ current desktop runtime (130 tests + real Cordis contexts) |
158
+ | `0.2.2-rc.5` | ✅ pre-adapted (0.2.2-rc.5 types/deps + 131 tests; current desktop still rc.3) |
159
+ | `0.2.2-rc.3` | ✅ current desktop (rc.3 types/deps + 131 tests; real runtime verified) |
160
+ | `0.2.2-rc.1` | ✅ compatible (0.2.2-rc.1 types/deps + 131 tests) |
161
+ | `0.2.1-rc.5` | ✅ compatible (rc.5 types/deps + 131 tests) |
162
+ | `0.2.1-rc.3` | ✅ compatible (rc.3 types/deps + 131 tests) |
163
+ | `0.2.1-rc.2` | ✅ current desktop runtime (131 tests + real Cordis contexts) |
164
164
  | `0.2.0-rc.x` | ✅ covered by the peer range |
165
165
  | `0.1.x` | ❌ unsupported (different settings-namespace model) |
166
166
 
package/README.md CHANGED
@@ -52,7 +52,7 @@ MCviseron 的 **DeepSeek Harness(DSH)总插件**:一个 npm 包、一个 `
52
52
 
53
53
  - Windows 桌面版:「设置 → MCviseron 插件 → 重启 / 关闭」子页提供重启与关闭按钮,点击后确认并重启/关闭桌面应用。
54
54
  - Linux / Web / 云服务器:普通 `dsh web` 使用 detached reexec;systemd / Docker / Kubernetes / PID 1 使用 supervisor-exit(退出码 75);关闭使用 exit 0,保持停止还是被托管器拉起由部署策略决定。详见 [docs/linux-restart.md](docs/linux-restart.md)。
55
- - 重启方式:Host 写一个临时 PowerShell 助手(detached),先关闭 Electron 主进程;Host 在 IPC 断开后按官方流程优雅关闭所有插件与会话;助手等待主进程与 Host 退出后,清除 `ELECTRON_RUN_AS_NODE` 并重新启动应用。
55
+ - 重启方式:Host 注册一个隐藏的 Task Scheduler PowerShell helper;helper 先等待旧 Electron 主进程与 Host PID 退出(最多 30 秒),再启动应用,避免单实例锁导致新进程直接退出。
56
56
  - 会中断正在运行的任务(与托盘「退出」的提示一致),不会修改插件、配置或会话记录。
57
57
  - 只在桌面版可用;`dsh web` 下状态接口返回不可用,设置行自动隐藏。
58
58
  - **为什么不做成托盘菜单项**:DSH 的托盘菜单由 Electron 主进程的 `lib/main.js` 直接构建(`DesktopTray`),插件运行在独立的 Host 子进程里,官方没有提供托盘扩展点;因此本组件只能在设置页提供等价入口。
@@ -250,12 +250,12 @@ DSH 0.2 的官方设置 apiproxy 不向浏览器暴露第三方命名空间,
250
250
 
251
251
  | DSH 版本 | 状态 |
252
252
  | --- | --- |
253
- | `0.2.2-rc.5` | ✅ 预适配(0.2.2-rc.5 类型/依赖 + 130 项测试;当前桌面仍为 rc.3) |
254
- | `0.2.2-rc.3` | ✅ 当前桌面安装(rc.3 类型/依赖 + 130 项测试;真实运行时验证) |
255
- | `0.2.2-rc.1` | ✅ 兼容(0.2.2-rc.1 类型/依赖 + 130 项测试) |
256
- | `0.2.1-rc.5` | ✅ 兼容(rc.5 类型/依赖 + 130 项测试) |
257
- | `0.2.1-rc.3` | ✅ 兼容(rc.3 类型/依赖 + 130 项测试) |
258
- | `0.2.1-rc.2` | ✅ 当前桌面运行版本(130 项测试 + 真实 Cordis 上下文) |
253
+ | `0.2.2-rc.5` | ✅ 预适配(0.2.2-rc.5 类型/依赖 + 131 项测试;当前桌面仍为 rc.3) |
254
+ | `0.2.2-rc.3` | ✅ 当前桌面安装(rc.3 类型/依赖 + 131 项测试;真实运行时验证) |
255
+ | `0.2.2-rc.1` | ✅ 兼容(0.2.2-rc.1 类型/依赖 + 131 项测试) |
256
+ | `0.2.1-rc.5` | ✅ 兼容(rc.5 类型/依赖 + 131 项测试) |
257
+ | `0.2.1-rc.3` | ✅ 兼容(rc.3 类型/依赖 + 131 项测试) |
258
+ | `0.2.1-rc.2` | ✅ 当前桌面运行版本(131 项测试 + 真实 Cordis 上下文) |
259
259
  | `0.2.0-rc.x` | ✅ peer 范围覆盖(同一套设置、审批与 hook 接缝) |
260
260
  | `0.1.x` | ❌ 不支持:0.1 的插件自行注册设置命名空间,与本插件的条目 id 命名空间模型不同 |
261
261
 
@@ -321,7 +321,7 @@ test/
321
321
 
322
322
  ```bash
323
323
  pnpm install
324
- pnpm check # typecheck + 130 项测试 + 构建
324
+ pnpm check # typecheck + 131 项测试 + 构建
325
325
  ```
326
326
 
327
327
  构建产物:`lib/index.js`(master ESM)、`lib/appearance.js`、`lib/auto-review-fix.js`、`lib/task-guard.js`、`lib/restart.js` 与 `lib/client.js`(浏览器模块)。`lib/` 不入库。
package/docs/release.md CHANGED
@@ -1,12 +1,18 @@
1
1
  # 发布 dsh-mcviseron-plugin 到 npm
2
2
 
3
- ## 当前状态(2026-10-23)
3
+ ## 当前状态(2026-12-06)
4
4
 
5
- - 包名 **`dsh-mcviseron-plugin` 当前发布 0.7.3**;v0.6.3 的 host bundle 导入缺陷由 v0.6.4 修复,v0.6.5 修复会话后动作工具注册与 turn/end 监听。
5
+ - 包名 **`dsh-mcviseron-plugin` 当前发布 0.8.4**;0.8.0、0.8.2 未发布,分别由 0.8.1、0.8.3 取代。0.8.4 修复 Windows 重启时旧进程未退出导致新实例不拉起的问题。
6
6
  - npm 账号 `mcviseron` 已恢复正常,可执行首次手动发布。
7
7
  - 本机全局 registry 指向 npmmirror,发布时必须显式指定 `--registry=https://registry.npmjs.org/`。
8
- - 首次发布 **v0.6.1 已手动完成**;从 **v0.6.2** 起由 `.github/workflows/publish.yml` 通过 OIDC Trusted Publishing 发布,tag 推送即发布。
9
- - **不要安装 0.6.3**:该版本的 host bundle 在启动时触发 `Dynamic require of "events"`,插件会被 DSH 判为加载失败。
8
+ - 首次发布 **v0.6.1 已手动完成**;此后由 `.github/workflows/publish.yml` 通过 OIDC Trusted Publishing 发布,tag 推送即发布。
9
+ - **0.8.0、0.8.2 跳过**:0.8.0 的 tag workflow 在 CI 阶段失败,0.8.2 只完成代码/文档准备;两者都未发布,npm 历史中不会出现。
10
+
11
+ ## 版本节奏
12
+
13
+ - **bug 修复、兼容性、CI、文档**:直接递增 patch(例如 0.8.3 → 0.8.4),修完即打 tag 并发布,不等待用户再次要求。
14
+ - **新增功能、破坏性变更**:由用户明确要求后使用 minor/major(例如 0.9.0)。
15
+ - 已跳过的版本不在 npm 补发;用下一个版本直接取代。
10
16
 
11
17
  ## 首次发布(账号解冻后)
12
18
 
@@ -49,7 +55,7 @@
49
55
 
50
56
  ```powershell
51
57
  npm view dsh-mcviseron-plugin version dist-tags.latest --registry=https://registry.npmjs.org/
52
- curl.exe -sI https://registry.npmjs.org/dsh-mcviseron-plugin/-/dsh-mcviseron-plugin-0.7.3.tgz | Select-Object -First 1
58
+ curl.exe -sI https://registry.npmjs.org/dsh-mcviseron-plugin/-/dsh-mcviseron-plugin-0.8.4.tgz | Select-Object -First 1
53
59
  curl.exe -X PUT "https://registry.npmmirror.com/-/package/dsh-mcviseron-plugin/syncs"
54
60
  ```
55
61
 
@@ -77,7 +83,7 @@ Trusted Publisher 绑定后,**推送 `v*` tag 即直接发布**,不再需要
77
83
 
78
84
  > `workflow_dispatch` 默认只做 `npm pack --dry-run`;要发布当前 `main` 的版本,取消勾选 `dry-run` 再运行。
79
85
  >
80
- > 从 v0.6.3 起 tag 推送直接发布;v0.6.4 覆盖 v0.6.3 的启动导入缺陷;v0.6.5 修复会话后动作;v0.6.6 加入 Auto review 上下文裁剪、认证 cookie 清理和全局 AI 提示。
86
+ > 最近版本:0.7.8 修复 Linux CI 临时目录;0.8.0/0.8.1 加入 Linux/Web/云重启与关闭并修复 CI;0.8.2 跳过;0.8.3 加入侧边栏重启快捷入口;0.8.4 修复 Windows 重启等待旧进程退出。
81
87
 
82
88
  ## 回滚与故障
83
89
 
package/lib/index.js CHANGED
@@ -12940,6 +12940,7 @@ __export(restart_exports, {
12940
12940
  deriveDesktopAppPath: () => deriveDesktopAppPath,
12941
12941
  inject: () => inject4,
12942
12942
  launchRestart: () => launchRestart,
12943
+ makeRestartHelper: () => makeRestartHelper,
12943
12944
  makeRestartRoutes: () => makeRestartRoutes,
12944
12945
  makeTaskScript: () => makeTaskScript,
12945
12946
  resolveProcessRestartTarget: () => resolveProcessRestartTarget,
@@ -13008,11 +13009,11 @@ var RESTART_DELAY_SECONDS = 6;
13008
13009
  function restartLogPath() {
13009
13010
  return join5(tmpdir4(), "dsh-mcviseron-restart.log");
13010
13011
  }
13011
- function makeTaskScript(target, taskName, delaySeconds) {
13012
+ function makeTaskScript(target, taskName, delaySeconds, helperPath = "") {
13012
13013
  const quote = (value) => "'" + value.replace(/'/g, "''") + "'";
13013
13014
  return [
13014
13015
  "$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name",
13015
- `$action = New-ScheduledTaskAction -Execute ${quote(target.exePath)} -WorkingDirectory ${quote(dirname(target.exePath))}`,
13016
+ helperPath === "" ? `$action = New-ScheduledTaskAction -Execute ${quote(target.exePath)} -WorkingDirectory ${quote(dirname(target.exePath))}` : `$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument ${quote('-NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File "' + helperPath + '"')} -WorkingDirectory ${quote(dirname(target.exePath))}`,
13016
13017
  `$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddSeconds(${delaySeconds})`,
13017
13018
  "$principal = New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Limited",
13018
13019
  `Register-ScheduledTask -TaskName ${quote(taskName)} -Action $action -Trigger $trigger -Principal $principal -Force | Out-Null`,
@@ -13084,16 +13085,35 @@ function closeDesktop(target) {
13084
13085
  }
13085
13086
  }, 300);
13086
13087
  }
13088
+ function makeRestartHelper(target, logPath = restartLogPath()) {
13089
+ const quote = (value) => "'" + value.replace(/'/g, "''") + "'";
13090
+ return [
13091
+ '$ErrorActionPreference = "SilentlyContinue"',
13092
+ "$mainPid = " + String(target.mainPid ?? 0),
13093
+ "$hostPid = " + String(target.hostPid),
13094
+ "$deadline = (Get-Date).AddSeconds(30)",
13095
+ "while ((Get-Date) -lt $deadline) {",
13096
+ " if (-not (Get-Process -Id $mainPid -ErrorAction SilentlyContinue) -and -not (Get-Process -Id $hostPid -ErrorAction SilentlyContinue)) { break }",
13097
+ " Start-Sleep -Milliseconds 200",
13098
+ "}",
13099
+ "Start-Sleep -Milliseconds 700",
13100
+ "Start-Process -FilePath " + quote(target.exePath) + " -WorkingDirectory " + quote(dirname(target.exePath)) + " | Out-Null",
13101
+ "Add-Content -LiteralPath " + quote(logPath) + ' -Value ((Get-Date).ToString("o") + " helper: launched " + ' + quote(target.exePath.replace(/'/g, "''")) + ") -Encoding UTF8"
13102
+ ].join("\n");
13103
+ }
13087
13104
  function launchHelper(target) {
13088
13105
  const logFile = restartLogPath();
13106
+ let helperPath = "";
13089
13107
  try {
13108
+ helperPath = join5(tmpdir4(), "dsh-mcviseron-restart-helper.ps1");
13109
+ writeFileSync(helperPath, makeRestartHelper(target), "utf8");
13090
13110
  execFileSync("powershell.exe", [
13091
13111
  "-NoProfile",
13092
13112
  "-NonInteractive",
13093
13113
  "-WindowStyle",
13094
13114
  "Hidden",
13095
13115
  "-Command",
13096
- makeTaskScript(target, RESTART_TASK_NAME, RESTART_DELAY_SECONDS)
13116
+ makeTaskScript(target, RESTART_TASK_NAME, RESTART_DELAY_SECONDS, helperPath)
13097
13117
  ], { windowsHide: true, timeout: 2e4, encoding: "utf8" });
13098
13118
  appendFileSync4(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: scheduled ${target.exePath} in ${RESTART_DELAY_SECONDS}s
13099
13119
  `, "utf8");
package/lib/restart.js CHANGED
@@ -120,11 +120,11 @@ var RESTART_DELAY_SECONDS = 6;
120
120
  function restartLogPath() {
121
121
  return join(tmpdir(), "dsh-mcviseron-restart.log");
122
122
  }
123
- function makeTaskScript(target, taskName, delaySeconds) {
123
+ function makeTaskScript(target, taskName, delaySeconds, helperPath = "") {
124
124
  const quote = (value) => "'" + value.replace(/'/g, "''") + "'";
125
125
  return [
126
126
  "$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name",
127
- `$action = New-ScheduledTaskAction -Execute ${quote(target.exePath)} -WorkingDirectory ${quote(dirname(target.exePath))}`,
127
+ helperPath === "" ? `$action = New-ScheduledTaskAction -Execute ${quote(target.exePath)} -WorkingDirectory ${quote(dirname(target.exePath))}` : `$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument ${quote('-NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File "' + helperPath + '"')} -WorkingDirectory ${quote(dirname(target.exePath))}`,
128
128
  `$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddSeconds(${delaySeconds})`,
129
129
  "$principal = New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Limited",
130
130
  `Register-ScheduledTask -TaskName ${quote(taskName)} -Action $action -Trigger $trigger -Principal $principal -Force | Out-Null`,
@@ -196,16 +196,35 @@ function closeDesktop(target) {
196
196
  }
197
197
  }, 300);
198
198
  }
199
+ function makeRestartHelper(target, logPath = restartLogPath()) {
200
+ const quote = (value) => "'" + value.replace(/'/g, "''") + "'";
201
+ return [
202
+ '$ErrorActionPreference = "SilentlyContinue"',
203
+ "$mainPid = " + String(target.mainPid ?? 0),
204
+ "$hostPid = " + String(target.hostPid),
205
+ "$deadline = (Get-Date).AddSeconds(30)",
206
+ "while ((Get-Date) -lt $deadline) {",
207
+ " if (-not (Get-Process -Id $mainPid -ErrorAction SilentlyContinue) -and -not (Get-Process -Id $hostPid -ErrorAction SilentlyContinue)) { break }",
208
+ " Start-Sleep -Milliseconds 200",
209
+ "}",
210
+ "Start-Sleep -Milliseconds 700",
211
+ "Start-Process -FilePath " + quote(target.exePath) + " -WorkingDirectory " + quote(dirname(target.exePath)) + " | Out-Null",
212
+ "Add-Content -LiteralPath " + quote(logPath) + ' -Value ((Get-Date).ToString("o") + " helper: launched " + ' + quote(target.exePath.replace(/'/g, "''")) + ") -Encoding UTF8"
213
+ ].join("\n");
214
+ }
199
215
  function launchHelper(target) {
200
216
  const logFile = restartLogPath();
217
+ let helperPath = "";
201
218
  try {
219
+ helperPath = join(tmpdir(), "dsh-mcviseron-restart-helper.ps1");
220
+ writeFileSync(helperPath, makeRestartHelper(target), "utf8");
202
221
  execFileSync("powershell.exe", [
203
222
  "-NoProfile",
204
223
  "-NonInteractive",
205
224
  "-WindowStyle",
206
225
  "Hidden",
207
226
  "-Command",
208
- makeTaskScript(target, RESTART_TASK_NAME, RESTART_DELAY_SECONDS)
227
+ makeTaskScript(target, RESTART_TASK_NAME, RESTART_DELAY_SECONDS, helperPath)
209
228
  ], { windowsHide: true, timeout: 2e4, encoding: "utf8" });
210
229
  appendFileSync(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: scheduled ${target.exePath} in ${RESTART_DELAY_SECONDS}s
211
230
  `, "utf8");
@@ -318,6 +337,7 @@ export {
318
337
  deriveDesktopAppPath,
319
338
  inject,
320
339
  launchRestart,
340
+ makeRestartHelper,
321
341
  makeRestartRoutes,
322
342
  makeTaskScript,
323
343
  resolveProcessRestartTarget,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mcviseron-plugin",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "DeepSeek Harness (DSH) master plugin — one package hosting MCviseron's DSH components as separate bundle entries: a time-based light/dark Appearance schedule, an Auto-review fix (shutdown preset guard + Chinese approval-reason translation), and a todo plan guard that keeps multi-stage work advancing, one-shot after-session restart/close actions with task-aware waiting, and automatic auth-cookie hygiene for repeated desktop restarts, and model-editable official automation tasks.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -182,11 +182,13 @@ function restartLogPath(): string {
182
182
  * @param delaySeconds - how long the task waits before starting the application.
183
183
  * @returns PowerShell registration script text.
184
184
  */
185
- export function makeTaskScript(target: RestartTarget, taskName: string, delaySeconds: number): string {
185
+ export function makeTaskScript(target: RestartTarget, taskName: string, delaySeconds: number, helperPath = ""): string {
186
186
  const quote = (value: string): string => "'" + value.replace(/'/g, "''") + "'"
187
187
  return [
188
188
  '$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name',
189
- `$action = New-ScheduledTaskAction -Execute ${quote(target.exePath)} -WorkingDirectory ${quote(dirname(target.exePath))}`,
189
+ helperPath === ""
190
+ ? `$action = New-ScheduledTaskAction -Execute ${quote(target.exePath)} -WorkingDirectory ${quote(dirname(target.exePath))}`
191
+ : `$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument ${quote('-NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File "' + helperPath + '"')} -WorkingDirectory ${quote(dirname(target.exePath))}`,
190
192
  `$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddSeconds(${delaySeconds})`,
191
193
  '$principal = New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Limited',
192
194
  `Register-ScheduledTask -TaskName ${quote(taskName)} -Action $action -Trigger $trigger -Principal $principal -Force | Out-Null`,
@@ -266,17 +268,38 @@ export function closeDesktop(target?: RestartTarget): void {
266
268
  }, 300)
267
269
  }
268
270
 
271
+ /** Build a Task Scheduler helper that waits for old processes before starting the app. */
272
+ export function makeRestartHelper(target: RestartTarget, logPath = restartLogPath()): string {
273
+ const quote = (value: string): string => "'" + value.replace(/'/g, "''") + "'"
274
+ return [
275
+ '$ErrorActionPreference = "SilentlyContinue"',
276
+ '$mainPid = ' + String(target.mainPid ?? 0),
277
+ '$hostPid = ' + String(target.hostPid),
278
+ '$deadline = (Get-Date).AddSeconds(30)',
279
+ 'while ((Get-Date) -lt $deadline) {',
280
+ ' if (-not (Get-Process -Id $mainPid -ErrorAction SilentlyContinue) -and -not (Get-Process -Id $hostPid -ErrorAction SilentlyContinue)) { break }',
281
+ ' Start-Sleep -Milliseconds 200',
282
+ '}',
283
+ 'Start-Sleep -Milliseconds 700',
284
+ 'Start-Process -FilePath ' + quote(target.exePath) + ' -WorkingDirectory ' + quote(dirname(target.exePath)) + ' | Out-Null',
285
+ 'Add-Content -LiteralPath ' + quote(logPath) + ' -Value ((Get-Date).ToString("o") + " helper: launched " + ' + quote(target.exePath.replace(/'/g, "''")) + ') -Encoding UTF8',
286
+ ].join('\n')
287
+ }
288
+
269
289
  /** Register the direct-launch task, then close the Electron main process. */
270
290
  function launchHelper(target: RestartTarget): void {
271
291
  const logFile = restartLogPath()
292
+ let helperPath = ''
272
293
  try {
294
+ helperPath = join(tmpdir(), 'dsh-mcviseron-restart-helper.ps1')
295
+ writeFileSync(helperPath, makeRestartHelper(target), 'utf8')
273
296
  execFileSync('powershell.exe', [
274
297
  '-NoProfile',
275
298
  '-NonInteractive',
276
299
  '-WindowStyle',
277
300
  'Hidden',
278
301
  '-Command',
279
- makeTaskScript(target, RESTART_TASK_NAME, RESTART_DELAY_SECONDS),
302
+ makeTaskScript(target, RESTART_TASK_NAME, RESTART_DELAY_SECONDS, helperPath),
280
303
  ], { windowsHide: true, timeout: 20_000, encoding: 'utf8' })
281
304
  appendFileSync(logFile, `${new Date().toISOString()} host: scheduled ${target.exePath} in ${RESTART_DELAY_SECONDS}s\n`, 'utf8')
282
305
  } catch (error) {