mirinjs 0.1.0-alpha.7 → 0.1.0-alpha.8
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/package.json +1 -1
- package/src/updater.ts +32 -19
package/package.json
CHANGED
package/src/updater.ts
CHANGED
|
@@ -15,7 +15,15 @@
|
|
|
15
15
|
|
|
16
16
|
import { homedir, tmpdir } from "node:os";
|
|
17
17
|
import { join } from "node:path";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
existsSync,
|
|
20
|
+
mkdirSync,
|
|
21
|
+
readFileSync,
|
|
22
|
+
readdirSync,
|
|
23
|
+
renameSync,
|
|
24
|
+
rmSync,
|
|
25
|
+
writeFileSync,
|
|
26
|
+
} from "node:fs";
|
|
19
27
|
import { $ } from "bun";
|
|
20
28
|
import { runtime } from "./runtime.ts";
|
|
21
29
|
import { loadCodec } from "./codec.ts";
|
|
@@ -214,31 +222,36 @@ export class Updater {
|
|
|
214
222
|
if (IS_WINDOWS) {
|
|
215
223
|
const runningApp = join(this.#resourcesDir()!, "..");
|
|
216
224
|
const exe = join(runningApp, `${this.#version()!.name}.exe`);
|
|
225
|
+
const script = join(tmpdir(), `mirin-apply-${this.#version()!.name}.ps1`);
|
|
217
226
|
const ps = [
|
|
218
227
|
`$ErrorActionPreference='SilentlyContinue'`,
|
|
219
|
-
//
|
|
228
|
+
// Never let the app dir be this process's cwd (Windows can't delete a cwd).
|
|
229
|
+
`Set-Location $env:TEMP`,
|
|
230
|
+
// Wait for the host to exit (it locks the exe), then a beat for CEF's
|
|
231
|
+
// helper subprocesses to release their file locks (libcef.dll etc.).
|
|
220
232
|
`while (Get-Process -Id ${process.pid} -ErrorAction SilentlyContinue) { Start-Sleep -Milliseconds 200 }`,
|
|
221
|
-
// Give CEF's helper subprocesses a beat to exit and release their file
|
|
222
|
-
// locks (libcef.dll etc.) — they go just after the host.
|
|
223
233
|
`Start-Sleep -Milliseconds 700`,
|
|
224
|
-
// Replace the app folder, retrying while any lingering lock clears
|
|
225
|
-
// (~10s max). Unlike Unix, Windows can't delete a dir that's still a
|
|
226
|
-
// process's cwd or holds an open handle — hence the neutral cwd below.
|
|
234
|
+
// Replace the app folder, retrying ~10s while any lingering lock clears.
|
|
227
235
|
`for ($i=0; $i -lt 50; $i++) { Remove-Item -Recurse -Force ${psq(runningApp)}; if (-not (Test-Path ${psq(runningApp)})) { break }; Start-Sleep -Milliseconds 200 }`,
|
|
228
236
|
`Move-Item -Force ${psq(this.#staged)} ${psq(runningApp)}`,
|
|
229
237
|
`Start-Process -FilePath ${psq(exe)} -WorkingDirectory ${psq(runningApp)}`,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
238
|
+
`Remove-Item -Force ${psq(script)}`, // self-clean
|
|
239
|
+
].join("\n");
|
|
240
|
+
writeFileSync(script, ps, "utf8");
|
|
241
|
+
// The swap MUST outlive this process. A Bun.spawn child is in our job object
|
|
242
|
+
// and is killed when we quit — even with unref/detached (verified). So spawn
|
|
243
|
+
// the swap via WMI Win32_Process.Create: the WMI service launches it, outside
|
|
244
|
+
// our job, so it survives. `await` the short launcher so the swap process
|
|
245
|
+
// exists before core.quit() (no race), then quit.
|
|
246
|
+
const wmiPath = script.replace(/'/g, "''");
|
|
247
|
+
const wmi =
|
|
248
|
+
`([wmiclass]'Win32_Process').Create('powershell -NoProfile -NonInteractive ` +
|
|
249
|
+
`-WindowStyle Hidden -ExecutionPolicy Bypass -File "${wmiPath}"') | Out-Null`;
|
|
250
|
+
const launcher = Bun.spawn(
|
|
251
|
+
["powershell", "-NoProfile", "-NonInteractive", "-Command", wmi],
|
|
252
|
+
{ stdin: "ignore", stdout: "ignore", stderr: "ignore" },
|
|
253
|
+
);
|
|
254
|
+
await launcher.exited;
|
|
242
255
|
} else {
|
|
243
256
|
const runningApp = join(this.#resourcesDir()!, "..", "..");
|
|
244
257
|
const script = [
|