2

I'm creating an electron app, which upon start spawns a local Django server child process (to serve as backend processing). In my development environment, the electron app runs properly when I run

npm start

Although, when trying to deploy my application with

electron-packager .

The executable does not start the Django server. When I view the contents of the resources/app directory, created by the electron packager, I see the virtualenv and all the Django dependencies are present. Why doesn't my packaged application start the local server as my development environment does?

My package.json:

{
  "name": "AppName",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "dist": "build"
  },
  "author": "AuthorName",
  "license": "CC0-1.0",
  "devDependencies": {
    "electron-packager": "^14.0.1"
  },
  "dependencies": {
    "electron": "^5.0.6"
  }
}

My main.js:

// Run local Django server
var ChildProcess = require('child_process');
var DjangoServer = ChildProcess.spawn('python', ['run_server.py']);

const {app, BrowserWindow} = require('electron')
const path = require('path')

let mainWindow

function createWindow () {
  mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })

  // Load local host served by Django
  mainWindow.loadFile('https://localhost:8000')

  mainWindow.setMenuBarVisibility(false)

  mainWindow.on('closed', function () {
    mainWindow = null
  })
}

app.on('ready', createWindow)

app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') app.quit()
})

app.on('activate', function () {
  if (mainWindow === null) createWindow()
})

// Kill local Django server
app.on('before-quit', function() {
  DjangoServer.kill('SIGINT')
})
Andrew
  • 21
  • 1
  • In main.js, the line that reads: mainWindow.loadFile('https://localhost:8000') is actually: mainWindow.loadURL('https://localhost:8000') – Andrew Jul 04 '19 at 06:39

0 Answers0