foldrun 26.3.0 → 26.3.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/package.json +1 -1
- package/src/browser.mjs +37 -1
package/package.json
CHANGED
package/src/browser.mjs
CHANGED
|
@@ -87,6 +87,7 @@ export function callEnv(paths, from = process.env) {
|
|
|
87
87
|
out.FOLDRUN_BROWSER_HEADLESS = "0"; // a window on this screen, so a person can take over
|
|
88
88
|
out.FOLDRUN_BROWSER_LIVE_ROOT = paths.chrome; // one profile that outlives sessions and reboots
|
|
89
89
|
out.FOLDRUN_BROWSER_LIVE_IDLE_MS = "0"; // never closed for idleness: the person may be away
|
|
90
|
+
out.FOLDRUN_BROWSER_MODULES = paths.home; // the Playwright setup installed, ahead of any global one
|
|
90
91
|
return out;
|
|
91
92
|
}
|
|
92
93
|
|
|
@@ -122,6 +123,36 @@ function liveRecord(paths) {
|
|
|
122
123
|
}
|
|
123
124
|
const pidAlive = (pid) => { if (!pid) return false; try { process.kill(pid, 0); return true; } catch { return false; } };
|
|
124
125
|
|
|
126
|
+
/** Whether a running process is the foldrun window's Chrome — its command line
|
|
127
|
+
* names this profile — false when it is something else (a pid in an old
|
|
128
|
+
* live.json may since be anything's), null when that cannot be told. */
|
|
129
|
+
function ourChrome(pid, profileRoot) {
|
|
130
|
+
const r = process.platform === "win32"
|
|
131
|
+
? spawnSync("powershell", ["-NoProfile", "-NonInteractive", "-Command", `(Get-CimInstance Win32_Process -Filter 'ProcessId=${Number(pid)}').CommandLine`], { encoding: "utf8", timeout: 15_000 })
|
|
132
|
+
: spawnSync("ps", ["-o", "args=", "-p", String(pid)], { encoding: "utf8", timeout: 5_000 });
|
|
133
|
+
if (r.status !== 0 || r.error) return null;
|
|
134
|
+
return r.stdout.includes(`--user-data-dir=${profileRoot}`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Stop the window's Chrome before its profile goes: closed through the program
|
|
138
|
+
* when it can be, else asked to quit, else killed — and only when it really is
|
|
139
|
+
* ours. True when it no longer runs. */
|
|
140
|
+
async function stopLive(paths, ctx) {
|
|
141
|
+
let live = liveRecord(paths);
|
|
142
|
+
if (!live?.alive) return true;
|
|
143
|
+
const ours = ourChrome(live.pid, live.root);
|
|
144
|
+
if (ours === false) return true; // a stale record: our Chrome is not running, and the pid is left alone
|
|
145
|
+
if (ctx) await runBrowse(ctx, ["--live", "end"], { timeoutMs: 30_000 });
|
|
146
|
+
live = liveRecord(paths);
|
|
147
|
+
if (!live?.alive) return true;
|
|
148
|
+
if (ours === null) return false; // cannot tell it is ours: the person closes it
|
|
149
|
+
const wait = async () => { for (let i = 0; i < 50 && pidAlive(live.pid); i++) await new Promise((r) => setTimeout(r, 100)); };
|
|
150
|
+
try { process.kill(live.pid, "SIGTERM"); } catch {}
|
|
151
|
+
await wait();
|
|
152
|
+
if (pidAlive(live.pid)) { try { process.kill(live.pid, "SIGKILL"); } catch {} await wait(); }
|
|
153
|
+
return !pidAlive(live.pid);
|
|
154
|
+
}
|
|
155
|
+
|
|
125
156
|
/**
|
|
126
157
|
* One call of browse.mjs. Never throws: the answer says what happened.
|
|
127
158
|
* @param {{ browse: string, paths: ReturnType<typeof browserPaths> }} ctx
|
|
@@ -521,8 +552,13 @@ export async function browserCmd(positional, flags, deps) {
|
|
|
521
552
|
case "reset": {
|
|
522
553
|
if (!(await deps.sureToDelete(flags, "browser reset", `the foldrun browser's profile at ${paths.chrome} — every site signed in there is signed out`))) return 1;
|
|
523
554
|
const ctx = await ready({ refresh: false });
|
|
524
|
-
if (!("error" in ctx)) await runBrowse(ctx, ["--live", "end"], { timeoutMs: 30_000 });
|
|
525
555
|
const live = liveRecord(paths);
|
|
556
|
+
// A Chrome still running on the profile keeps its sign-ins and writes
|
|
557
|
+
// them back: it stops first, or nothing is removed.
|
|
558
|
+
if (!(await stopLive(paths, "error" in ctx ? null : ctx))) {
|
|
559
|
+
console.log(`\n ${c.red("✗")} the foldrun Chrome window is still open${live?.pid ? ` (pid ${live.pid})` : ""} — close it, then run \`foldrun browser reset\` again; nothing was removed\n`);
|
|
560
|
+
return 1;
|
|
561
|
+
}
|
|
526
562
|
fs.rmSync(paths.chrome, { recursive: true, force: true });
|
|
527
563
|
if (live && live.root !== paths.chrome) fs.rmSync(live.root, { recursive: true, force: true });
|
|
528
564
|
console.log(`\n ${c.green("✓")} profile removed — the next window starts signed out\n`);
|