From 41b208fcb7a5ee3a701db2fe306b60b195390088 Mon Sep 17 00:00:00 2001 From: Ben Curtis Date: Wed, 28 Apr 2021 20:18:12 -0400 Subject: [PATCH] Support opening URLs passed as arg to Nativefied application (fix #405) (PR #1154) Co-authored-by: Ronan Jouchet --- app/src/main.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main.ts b/app/src/main.ts index 390af21..7fede7a 100644 --- a/app/src/main.ts +++ b/app/src/main.ts @@ -29,6 +29,21 @@ if (require('electron-squirrel-startup')) { const appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8')); +// Take in a URL on the command line as an override +if (process.argv.length > 1) { + const maybeUrl = process.argv[1]; + try { + new URL(maybeUrl); + appArgs.targetUrl = maybeUrl; + console.info('Loading override URL passed as argument:', maybeUrl); + } catch (err) { + console.error( + 'Not loading override URL passed as argument, because failed to parse:', + maybeUrl, + ); + } +} + // Nativefier is a browser, and an old browser is an insecure / badly-performant one. // Given our builder/app design, we currently don't have an easy way to offer // upgrades from the app themselves (like browsers do).