foldrun 26.3.1 → 26.3.2
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 +20 -11
package/package.json
CHANGED
package/src/browser.mjs
CHANGED
|
@@ -138,19 +138,28 @@ function ourChrome(pid, profileRoot) {
|
|
|
138
138
|
* when it can be, else asked to quit, else killed — and only when it really is
|
|
139
139
|
* ours. True when it no longer runs. */
|
|
140
140
|
async function stopLive(paths, ctx) {
|
|
141
|
-
|
|
141
|
+
const live = liveRecord(paths);
|
|
142
142
|
if (!live?.alive) return true;
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
// The one process checked here is the one signalled: its pid and profile
|
|
144
|
+
// are held, and ownership asked again right before each signal.
|
|
145
|
+
const { pid, root } = live;
|
|
146
|
+
const ours = () => ourChrome(pid, root);
|
|
147
|
+
const first = ours();
|
|
148
|
+
if (first === false) return true; // a stale record: our Chrome is not running, and the pid is left alone
|
|
145
149
|
if (ctx) await runBrowse(ctx, ["--live", "end"], { timeoutMs: 30_000 });
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
150
|
+
const wait = async () => { for (let i = 0; i < 50 && pidAlive(pid); i++) await new Promise((r) => setTimeout(r, 100)); };
|
|
151
|
+
for (const sig of /** @type {const} */ (["SIGTERM", "SIGKILL"])) {
|
|
152
|
+
if (!pidAlive(pid)) break;
|
|
153
|
+
const now = ours();
|
|
154
|
+
if (now === false) break; // it went, and the pid is another program's now
|
|
155
|
+
if (now === null) return false; // cannot tell it is ours: the person closes it
|
|
156
|
+
try { process.kill(pid, sig); } catch {}
|
|
157
|
+
await wait();
|
|
158
|
+
}
|
|
159
|
+
if (pidAlive(pid) && ours() !== false) return false;
|
|
160
|
+
// A window opened on the profile meanwhile (another call) holds it too.
|
|
161
|
+
const after = liveRecord(paths);
|
|
162
|
+
return !(after?.alive && after.pid !== pid && ourChrome(after.pid, after.root) !== false);
|
|
154
163
|
}
|
|
155
164
|
|
|
156
165
|
/**
|