1 | function getProcessArgvBinIndex () {
|
2 | // The binary name is the first command line argument for:
|
3 | // - bundled Electron apps: bin argv1 argv2 ... argvn
|
4 | if (isBundledElectronApp()) return 0
|
5 | // or the second one (default) for:
|
6 | // - standard node apps: node bin.js argv1 argv2 ... argvn
|
7 | // - unbundled Electron apps: electron bin.js argv1 arg2 ... argvn
|
8 | return 1
|
9 | }
|
10 |
|
11 | function isBundledElectronApp () {
|
12 | // process.defaultApp is either set by electron in an electron unbundled app, or undefined
|
13 | // see https://github.com/electron/electron/blob/master/docs/api/process.md#processdefaultapp-readonly
|
14 | return isElectronApp() && !process.defaultApp
|
15 | }
|
16 |
|
17 | function isElectronApp () {
|
18 | // process.versions.electron is either set by electron, or undefined
|
19 | // see https://github.com/electron/electron/blob/master/docs/api/process.md#processversionselectron-readonly
|
20 | return !!process.versions.electron
|
21 | }
|
22 |
|
23 | function getProcessArgvWithoutBin () {
|
24 | return process.argv.slice(getProcessArgvBinIndex() + 1)
|
25 | }
|
26 |
|
27 | function getProcessArgvBin () {
|
28 | return process.argv[getProcessArgvBinIndex()]
|
29 | }
|
30 |
|
31 | module.exports = {
|
32 | getProcessArgvBin,
|
33 | getProcessArgvWithoutBin
|
34 | }
|