pi-ext
bugabingas pi extensions
owned by bugabinga
Avoid cmd flash for mockup browser open
43a2b234635679c797902408c7d9fbc2fe13b8e6
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
Browse filesCompare with HEAD
Changed files (2)
extensions/super/__tests__/mockup.test.ts
Modified 3 3 import assert
from "node:assert";
4 4 import { describe, it }
from "vitest";
6 6 MOCKUP_FULL_DOCUMENT_ERROR,
10 11 validateMockupRequest,
153 +describe(
"mockup browser opener", ()
=> {
154 + it(
"uses explorer directly on win32 to avoid cmd flashes", ()
=> {
155 + assert.
deepStrictEqual(
156 + openerCandidates(
"http://127.0.0.1:1", {
161 + command:
"explorer.exe",
162 + args: [
"http://127.0.0.1:1"],
152 169 describe(
"mockup server", ()
=> {
153 170 it(
"rejects multiple submitted selections unless multi is enabled",
async ()
=> {
154 171 const server
= await startMockupServer(
extensions/super/mockup.ts
Modified446 -function openerCandidates(
446 +export type OpenerCandidate = {
449 + windowsHide
?: boolean;
452 +export function openerCandidates(
448 -)
: Array<{ command
: string; args
: string[] }> {
449 - if (
process.
env.TERMUX_VERSION)
450 - return [{ command:
"termux-open-url", args: [url] }];
451 - if (
process.
platform === "darwin")
return [{ command:
"open", args: [url] }];
452 - if (
process.
platform === "win32")
453 - return [{ command:
"cmd.exe", args: [
"/c",
"start",
"", url] }];
454 + options
: { platform
?: NodeJS.
Platform; env
?: NodeJS.
ProcessEnv }
= {},
455 +)
: OpenerCandidate[] {
456 + const platform
= options.
platform ?? process.
platform;
457 + const env
= options.env
?? process.
env;
458 + if (env.TERMUX_VERSION)
return [{ command:
"termux-open-url", args: [url] }];
459 + if (platform
=== "darwin")
return [{ command:
"open", args: [url] }];
460 + if (platform
=== "win32")
461 + return [{ command:
"explorer.exe", args: [url], windowsHide:
true }];
455 463 { command:
"xdg-open", args: [url] },
456 464 { command:
"wslview", args: [url] },
461 469 function trySpawn(command
: string, args
: string[])
: Promise<
boolean> {
462 470 return new Promise((resolve)
=> {
463 - const child
= spawn(command, args, { detached:
true, stdio:
"ignore" });
471 + const child
= spawn(command, args, {
464 476 let settled
= false;
465 477 const done = (ok
: boolean)
=> {
466 478 if (settled)
return;