Reputation: 828
I have a couple scripts set up in package.json to switch between command line options for my electron app
"scripts": {
"start": "cross-env NODE_ENV=development electron . kira",
"kira": "cross-env NODE_ENV=development electron . kira",
"mia": "cross-env NODE_ENV=development electron . mia",
"cybertech": "cross-env NODE_ENV=development electron . cybertech",
"package": "node ./scripts/package.js",
},
However after packaging I am not sure how to use these command line switches. Ideally I would like to set up a command like npm run package-cybertech
that would set up My_App.exe to execute with the "cybertech" flag added.
Thanks for the help!
Upvotes: 1
Views: 1460
Reputation: 289
In case of packaged source of electron app, command line arguments can be accessed using following function. Let's say if we have passed the command line argument as --arg=value
. It can be retrieved like this in the main.js:
import { app } from "electron";
app.commandLine.getSwitchValue("arg");
To check if default argument is present (without any value):
app.commandLine.hasSwitch("arg")
This works for development mode as well.
Upvotes: 1