From 39cce5e3eaad773ef56f707659966d1f49cd7f69 Mon Sep 17 00:00:00 2001 From: Aaron Meriwether Date: Mon, 8 Aug 2022 01:12:06 -0700 Subject: [PATCH] fix: app.relaunch loses args when execPath specified (#35108) --- shell/browser/api/electron_api_app.cc | 4 +++- spec-main/api-app-spec.ts | 8 +++++--- spec/fixtures/api/relaunch/main.js | 10 +++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/shell/browser/api/electron_api_app.cc b/shell/browser/api/electron_api_app.cc index 975cb94a33d57..6efbc1655f37e 100644 --- a/shell/browser/api/electron_api_app.cc +++ b/shell/browser/api/electron_api_app.cc @@ -1152,7 +1152,9 @@ bool App::Relaunch(gin::Arguments* js_args) { gin_helper::Dictionary options; if (js_args->GetNext(&options)) { - if (options.Get("execPath", &exec_path) || options.Get("args", &args)) + bool has_exec_path = options.Get("execPath", &exec_path); + bool has_args = options.Get("args", &args); + if (has_exec_path || has_args) override_argv = true; } diff --git a/spec-main/api-app-spec.ts b/spec-main/api-app-spec.ts index 51c202366a51f..5c4befc6195bc 100644 --- a/spec-main/api-app-spec.ts +++ b/spec-main/api-app-spec.ts @@ -370,9 +370,11 @@ describe('app module', () => { server!.once('error', error => done(error)); server!.on('connection', client => { client.once('data', data => { - if (String(data) === 'false' && state === 'none') { + if (String(data) === '--first' && state === 'none') { state = 'first-launch'; - } else if (String(data) === 'true' && state === 'first-launch') { + } else if (String(data) === '--second' && state === 'first-launch') { + state = 'second-launch'; + } else if (String(data) === '--third' && state === 'second-launch') { done(); } else { done(`Unexpected state: "${state}", data: "${data}"`); @@ -381,7 +383,7 @@ describe('app module', () => { }); const appPath = path.join(fixturesPath, 'api', 'relaunch'); - const child = cp.spawn(process.execPath, [appPath]); + const child = cp.spawn(process.execPath, [appPath, '--first']); child.stdout.on('data', (c) => console.log(c.toString())); child.stderr.on('data', (c) => console.log(c.toString())); child.on('exit', (code, signal) => { diff --git a/spec/fixtures/api/relaunch/main.js b/spec/fixtures/api/relaunch/main.js index 272c41f4421aa..94898f6059d65 100644 --- a/spec/fixtures/api/relaunch/main.js +++ b/spec/fixtures/api/relaunch/main.js @@ -11,11 +11,15 @@ app.whenReady().then(() => { const lastArg = process.argv[process.argv.length - 1]; const client = net.connect(socketPath); client.once('connect', () => { - client.end(String(lastArg === '--second')); + client.end(lastArg); }); client.once('end', () => { - if (lastArg !== '--second') { - app.relaunch({ args: process.argv.slice(1).concat('--second') }); + if (lastArg === '--first') { + // Once without execPath specified + app.relaunch({ args: process.argv.slice(1, -1).concat('--second') }); + } else if (lastArg === '--second') { + // And once with execPath specified + app.relaunch({ execPath: process.argv[0], args: process.argv.slice(1, -1).concat('--third') }); } app.exit(0); });