ARGV in electron render process
Reading ARGV in electron is as simple as parsing
the
process.argv
array from node, as long as reading the CLI arguments will be done only inside
the main process of your electron app. Sometimes though you want to flip some
switches inside the
render process
too, based on what's passed in the main process's argv. Maybe change some UI
based on the passed in API environment or even use different endpoints and
whatnot.
That's the problem definition, which turns out is even longer than the solution itself.
Solution: use
electron.remote.process
import electron from 'electron';
// ARGV from main process
console.log(electron.remote.process.argv);
So this is it. Nice and simple.
Andrei Glingeanu's notes and thoughts. You should follow him on Twitter, Instagram or contact via email. The stuff he loves to read can be found here on this site or on goodreads. Wanna vent or buy me a coffee?