| |
| |
| |
| |
| |
|
|
| import { runExitCleanup } from './cleanup.js'; |
| import { waitForUpdateCompletion } from './handleAutoUpdate.js'; |
|
|
| |
| |
| |
| export const RELAUNCH_EXIT_CODE = 199; |
|
|
| |
| |
| |
| let isRelaunching = false; |
|
|
| |
| export function _resetRelaunchStateForTesting(): void { |
| isRelaunching = false; |
| } |
|
|
| export async function relaunchApp(): Promise<void> { |
| if (isRelaunching) return; |
| isRelaunching = true; |
| await waitForUpdateCompletion(); |
| await runExitCleanup(); |
| process.exit(RELAUNCH_EXIT_CODE); |
| } |
|
|
| export interface ProcessWithSea extends NodeJS.Process { |
| isSea?: () => boolean; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export function isStandardSea(): boolean { |
| return ( |
| process.argv[0] !== process.argv[1] && |
| (process.env['IS_BINARY'] === 'true' || |
| (process as ProcessWithSea).isSea?.() === true) |
| ); |
| } |
|
|
| |
| |
| |
| |
| export function getScriptArgs(): string[] { |
| return process.argv.slice(isStandardSea() ? 1 : 2); |
| } |
|
|
| |
| |
| |
| |
| export function isSeaEnvironment(): boolean { |
| return ( |
| process.env['IS_BINARY'] === 'true' || |
| (process as ProcessWithSea).isSea?.() === true || |
| process.argv[0] === process.argv[1] |
| ); |
| } |
|
|
| |
| |
| |
| |
| export function getSpawnConfig( |
| nodeArgs: string[], |
| scriptArgs: string[], |
| ): { |
| spawnArgs: string[]; |
| env: NodeJS.ProcessEnv; |
| } { |
| const isBinary = isSeaEnvironment(); |
| const newEnv: NodeJS.ProcessEnv = { |
| ...process.env, |
| GEMINI_CLI_NO_RELAUNCH: 'true', |
| }; |
|
|
| const finalSpawnArgs: string[] = []; |
|
|
| if (isBinary) { |
| |
| |
| |
| |
| if (nodeArgs.length > 0) { |
| for (const arg of nodeArgs) { |
| if (/[\s"'\\]/.test(arg)) { |
| throw new Error( |
| `Unsupported node argument for SEA relaunch: ${arg}. Complex escaping is not supported.`, |
| ); |
| } |
| } |
| const existingNodeOptions = process.env['NODE_OPTIONS'] || ''; |
| |
| |
| newEnv['NODE_OPTIONS'] = |
| `${existingNodeOptions} ${nodeArgs.join(' ')}`.trim(); |
| } |
| |
| |
| |
| |
| |
| finalSpawnArgs.push(process.execPath, ...scriptArgs); |
| } else { |
| |
| finalSpawnArgs.push( |
| ...process.execArgv, |
| ...nodeArgs, |
| process.argv[1], |
| ...scriptArgs, |
| ); |
| } |
|
|
| return { |
| spawnArgs: finalSpawnArgs, |
| env: newEnv, |
| }; |
| } |
|
|