#Command line arguments ignored on packaged app (MacOS)

24 messages · Page 1 of 1 (latest)

uncut kraken
#

My main process looks at the command line to see if there is an argument. This works great while doing development, but after packaging with electron-forge, it always acts as if none are specified. open -a <app-name> <argument> should pass the arguments to the app. The app starts, but behavior (and logging) indicates no argument was received.

Any help appreciated. If I can't pass arguments through, I'll have to abandon electron.

uncut kraken
#

It's easy to recreate this problem. Create an app foo using electron-forge as documented.
yarn add electron-log. Then add a log statement to the main process log(process.argv.join(' ')).
yarn start . -- -- package.json and you will see it logs package.json.
Then yarn package and open -a <app> package.json and it does not log the argument.

abstract lily
#

Do you package the thing you want to call arguments on inside the app.asar archive? If yes, this usually does not work. You have to tell the packager to create a extra directory outside app.asar or tell it to not use asar at all. The latter is an easy test to see if that is the issue

#

No idea what this electron log does but sounds like relative path issue again?

uncut kraken
#

I am not familiar with ".asar". yarn package makes a "foo.app" folder with apropriate things under it.

#

The packaging is being done with electron-forge.

#

My .app folder has no .asar files under it.

#

electron-log is the only way I've found to get logged output from within a packaged app. If there's a better way, I'm sure that would show the problem too

abstract lily
#

ah okay. it does not log the package.json content, it just logs the string "package.json"..

I am surprised mac has no asar file though.
https://www.electronjs.org/docs/latest/tutorial/asar-archives
In windows the folder structure is like that:
electron-app-folder/resources/app.asar -> app.asar contains the whole source code created by you. it can be extracted to a folder, then you can look into it.

#

but maybe that doesnt matter for your problem

gentle plinth
#

mac does have asar

uncut kraken
abstract lily
#

there are 2 scenarios:

  1. you see an app.asar or whatever the .asar is called
  2. you dont see it, but you see a folder which contains your (bundled?) source code
#

if electron-forge creates an app.asar depends on the settings applied to electron-packager in the forge config. you can add asar: true/false somewhere there.

#

hm, and I see that i added "asar: true" to my project, which may mean the default for electron-forge typescript webpack template is "asar: false". It is too long ago that i set that stuff up.

#

If that is the case, .asar is not the reason for your issues.

gentle plinth
#

.app is macos bundle

uncut kraken
#

Not having the .asar is minor to me

gentle plinth
#

like archive with files in it

uncut kraken
gentle plinth
uncut kraken
#

https://apple.stackexchange.com/questions/370427/what-does-macos-actually-do-when-open-a-file. This says the "filename" arguments are not passed as command line arguments. This is consistent with what I have seen, but it does suggestion a "hole" in the electron functionality. It's possible that there is already Node support for this and is something I should do in my main.js. I'll dig in a bit more, but being able to use "--args" is adequate for my needs.

Thanks for the help.