1

I'm working on an app using ElectronJS, with a python backend. Electron and Python communicate through python using flask to host a webserver which returns JSON and the like.

Here's my situation - the app works just fine when run by right clicking the .app, then going into Contents/MacOS and running the unix executable inside there. However if I just double-click on the .app, the python backend does not start.

I'm not sure how to view the console output to see what is going wrong with the command to start python, but here is the line that starts the python process -

pythonBackend = require('child_process').spawn('/Library/Frameworks/Python.framework/Versions/3.8/bin/python3', [String(__dirname) + '/main.py'], {stdio: [process.stdin, process.stdout, process.stderr], detached: false});

I use quite a few configuration files stored on the user's machine, so getting rid of Electron and just hosting in the cloud isn't a great option in my opinion, however I could be wrong.

The software isn't signed or validated, so I'm wondering if this could be an issue where MacOS is blocking execution of shell commands/scripts if you aren't signed.

Todd Rylaarsdam
  • 438
  • 6
  • 19
  • 1
    While looking further into this, I see on electron's documentation that you should get an apple developer account and sign your app. However I don't get a pop-up saying this app is unsigned. – Todd Rylaarsdam Aug 01 '20 at 03:17
  • Another update - I've tried running `sudo open [.app]` to try and give it more permissions, but no avail – Todd Rylaarsdam Aug 01 '20 at 14:26

1 Answers1

0

Signing and notarizing didn't make a difference for me, what did was this: Node.Js subprocess doesn't start after clicking on a .app, but does if running from unix executable

Here's what solved this problem for me: https://stackoverflow.com/a/63257384/637173

I had two problems:

I was using a relative path, which worked fine in development, but when the app was bundled the directory structure changed. Using app.getAppPath() or __dirname should resolve this

I was using spawn(["node", "process.js"], which again worked fine in development, but in production there is no node process. The solution was just calling fork("process.js"), which uses Electron's internal node

bradjasper
  • 83
  • 1
  • 6
  • Interesting. No longer using electron or electron-forge for any active projects but if I ever come back to those tools I'll give this a shot. – Todd Rylaarsdam Jun 05 '22 at 00:03