1

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!

Ben S
  • 778
  • 1
  • 5
  • 19
  • Have a look in [Pass arguments to packaged electron application](https://stackoverflow.com/questions/34731875/pass-arguments-to-packaged-electron-application) – Alon Adler Jul 16 '17 at 08:13
  • Thanks! Yeah, I have read about the issues with the order of command line arguments being different in packaged and unpackaged versions. But I guess I am asking about supplying default arguments to packaged apps. – Ben S Jul 17 '17 at 16:48

1 Answers1

1

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.

Ali Raza
  • 249
  • 3
  • 6