electron-userland / electron-webpack

Scripts and configurations to compile Electron applications using webpack
https://webpack.electron.build/
903 stars 170 forks source link

Not shutting down correctly on Windows #87

Open bradharms opened 6 years ago

bradharms commented 6 years ago

I have a project that is (mostly) based on the quick start repo, but when I run it on Windows and close the main window, my command prompt leaves me with a stylized "Terminate batch job (Y/N)?" which keeps the process running. Eventually it will shut down on its own but it's not obvious that it will do that since it seems to be waiting for confirmation. This problem was not present when I was using Electron by itself.

This is my src/main/index.js:

// @ts-check

import { app, BrowserWindow } from 'electron'
import url from 'url'
import path from 'path'

const isDevelopment = process.env.NODE_ENV !== 'production'

let mainWindow

function createMainWindow() {
  mainWindow = new BrowserWindow({
    width: 800,
    height: 550,
    autoHideMenuBar: true,
  })

  const url_ = isDevelopment ?
    `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}` :
    url.format({
      pathname: path.join(__dirname, 'index.html'),
      protocol: 'file:',
      slashes: true
    })

  if (isDevelopment) {
    mainWindow.webContents.openDevTools({ mode: "detach" })
  }

  mainWindow.loadURL(url_)

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

  mainWindow.webContents.on('devtools-opened', () => {
    mainWindow.focus()
    setImmediate(() => {
      mainWindow.focus()
    })
  })
}

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

app.on('activate', () => {
  if (mainWindow === null) {
    createMainWindow()
  }
})

app.on('ready', createMainWindow)
loopmode commented 6 years ago

Yes I have noticed this too. I got used to it as I have a good workaround: I just kill all node processes..

Basically, it's the wmic command: wmic process where name like "node" delete (see https://www.cs.cmu.edu/~tgp/scsadmins/winadmin/WMIC_Queries.txt)

Since I use bash anyways, I keep this one in my .bashrc:

kill() {
    echo ">> Enter a process name and press [ENTER] (partial matching)"
    read name
    wmic process where "name like '%$name%'" delete
}

So.. I just launch a new console and go "kill, enter, node, enter" and it's gone right away. On my other computer, I even have a shortcut to a batch file pinned to the start menu, that's handy too.

But, of course these are just workarounds, and the actual issue remains.

awesson commented 6 years ago

I see this as well. Not ideal.

If I need to use that same cmd promt right away, CTRL+C will kill it. Otherwise, like you said, if you wait a few seconds it will eventually end.

loopmode commented 6 years ago

I noticed that - at least for me - the issue does not occur if I launched manually, from a git bash, via yarn dev. Whenever I launch differently, e.g. via shortcuts, batchfiles, from a bash script, via custom "yarn dev" folder context menu entry, via other consoles (I use ConEmu) - I do have the issue.

So for me, this "issue" is solved: No more tricky shortcuts for launching. I just launch the git bash and run yarn dev, then after Ctrl+C everything quits right away, without delay.

When I quit the app itself, the CLI command still takes time, but I can Ctrl-C it and it immediatly quits as well - when I had the issue, that didn't help.

praschl commented 5 years ago

I am experiencing that, too. After working a while, i see my computers performance degrade, and when investigating, I see some electron processes running.

I am working on Windows 10 with VS Code. It's annoying, but I can live with it as long as I remember to kill the processes every now and then :-)