Support opening URLs passed as arg to Nativefied application (fix #405) (PR #1154)

Co-authored-by: Ronan Jouchet <ronan@jouchet.fr>
This commit is contained in:
Ben Curtis 2021-04-28 20:18:12 -04:00 committed by GitHub
parent 9286fc8086
commit 41b208fcb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -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).