keckothedragon
keckothedragon

Reputation: 7

Electron forge Squirrel installer hanging after trying to run

I am using Electron forge to build an app where we have a server that needs to run on install. I am using Squirrel to package and create an installer (Windows). The installer should run a process that will run forever, but I would like to end the installation before that process completes.

The process is run using pythonw to run in the background. I got the idea from this question. The backend process needs user permissions, so it cannot run using a Windows service (sc).

Here is the code that runs the backend server:

run-server.bat

set PYTHONPATH=%PYTHONPATH%; %LocalAppData%\my-app\app-0.9.7\resources\app\src\python\Lib\site-packages
set PYTHONHOME=%LocalAppData%\my-app\app-0.9.7\resources\app\src\python
start "" "%LocalAppData%\my-app\app-0.9.7\resources\app\src\python\pythonw.exe" "%LocalAppData%\my-app\app-0.9.7\resources\app\src\py\server.py" "%1"
exit

windows-setup.bat

copy "%LocalAppData%\my-app\app-0.9.7\resources\app\installers\run-server.bat" "%AppData%\Microsoft\Windows\Start Menu\Programs\Startup\run-server.bat"
start "" "%AppData%\Microsoft\Windows\Start Menu\Programs\Startup\run-server.bat"

Here is the code to run the batch files:

setupEvents.js

case '--squirrel-install':
    async function setup() {
      const setup_windows = spawn('cmd.exe', 
      ['/c', '%LocalAppData%/my-app/app-0.9.7/resources/app/installers/windows-setup.bat'], {
         detached: true,
         stdio: 'ignore'
      }).unref();
      setup_windows.stdout.on('data', (data) => {
         log.info(`bat stdout: ${data}`);
      });
      setup_windows.stderr.on('data', (data) => {
         log.error(`dir stderr: ${data}`);
      });
    }
    setup();
    
    spawnUpdate(['--createShortcut', exeName]);

    setTimeout(app.quit, 1000);
    return true;

Based on my logs, I know that squirrel-install has been running.

I tried adding .unref, making the batch instance detached, adding "/B" to the start command in run-server.bat, and making the server a Windows process with sc.

Upvotes: 1

Views: 352

Answers (0)

Related Questions