mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-11 10:57:07 +00:00
The Linux wrapper injects --no-sandbox for Electron sandboxing, but the CLI parser was treating it as an unknown Paseo option. Filter it out alongside the existing macOS -psn_ prefix.
79 lines
1.9 KiB
TypeScript
79 lines
1.9 KiB
TypeScript
const IGNORED_ARG_PREFIXES = ["-psn_", "--no-sandbox"];
|
|
|
|
export const DESKTOP_CLI_ENV = "PASEO_DESKTOP_CLI";
|
|
|
|
export type NodeEntrypointSpec = {
|
|
entryPath: string;
|
|
execArgv: string[];
|
|
};
|
|
|
|
export type NodeEntrypointInvocation = {
|
|
command: string;
|
|
args: string[];
|
|
env: NodeJS.ProcessEnv;
|
|
};
|
|
|
|
export type NodeEntrypointArgvMode = "bare" | "node-script";
|
|
|
|
type CreateNodeEntrypointInvocationInput = {
|
|
execPath: string;
|
|
isPackaged: boolean;
|
|
packagedRunnerPath: string | null;
|
|
entrypoint: NodeEntrypointSpec;
|
|
argvMode: NodeEntrypointArgvMode;
|
|
args: string[];
|
|
baseEnv: NodeJS.ProcessEnv;
|
|
};
|
|
|
|
type ParseCliPassthroughArgsFromArgvInput = {
|
|
argv: string[];
|
|
isDefaultApp: boolean;
|
|
forceCli: boolean;
|
|
};
|
|
|
|
export function createElectronNodeEnv(baseEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
|
return {
|
|
...baseEnv,
|
|
ELECTRON_RUN_AS_NODE: "1",
|
|
};
|
|
}
|
|
|
|
export function parseCliPassthroughArgsFromArgv(
|
|
input: ParseCliPassthroughArgsFromArgvInput,
|
|
): string[] | null {
|
|
const startIndex = input.isDefaultApp ? 2 : 1;
|
|
const effective = input.argv
|
|
.slice(startIndex)
|
|
.filter((arg) => !IGNORED_ARG_PREFIXES.some((p) => arg.startsWith(p)));
|
|
|
|
if (input.forceCli) {
|
|
return effective;
|
|
}
|
|
|
|
return effective.length > 0 ? effective : null;
|
|
}
|
|
|
|
export function createNodeEntrypointInvocation(
|
|
input: CreateNodeEntrypointInvocationInput,
|
|
): NodeEntrypointInvocation {
|
|
const env = createElectronNodeEnv(input.baseEnv);
|
|
|
|
if (input.isPackaged) {
|
|
if (!input.packagedRunnerPath) {
|
|
throw new Error("Packaged node entrypoint runner is required for desktop launches.");
|
|
}
|
|
|
|
return {
|
|
command: input.execPath,
|
|
args: [input.packagedRunnerPath, input.argvMode, input.entrypoint.entryPath, ...input.args],
|
|
env,
|
|
};
|
|
}
|
|
|
|
return {
|
|
command: input.execPath,
|
|
args: [...input.entrypoint.execArgv, input.entrypoint.entryPath, ...input.args],
|
|
env,
|
|
};
|
|
}
|