1

When I run app.quit() or app.exit(), the main app window gets closed, but 4 other electron processes keep running.

I thought it might be caused by a silent error, tried wrapping functions with try / catch, but nothing showed up.

I'd appreciate if someone helped me find the problem / explain what's wrong with the code

Code of the main Electron process:

https://github.com/aleksey-hoffman/sigma-file-manager/blob/main/src/electronMain.js

If you wanna run it, here's the instruction:

https://github.com/aleksey-hoffman/sigma-file-manager/blob/main/CONTRIBUTING.md

AlekseyHoffman
  • 2,438
  • 1
  • 8
  • 31
  • a lot of code to go through. Do you know what these processes are based on the command line args? Are they like Electron renderer/GPU/network processes? The main process? Third party processes launched by your app? – pushkin Feb 06 '23 at 19:49
  • All 4 processes are electron.exe processes (GPU, hidden renderer, main), only the main renderer window gets closed and then I get Tray and other listener errors because the main window doesn't exist anymore but the app is still opened. I also tried removing listeners from the window before closing – AlekseyHoffman Feb 07 '23 at 04:50
  • I found that the problem is caused by `initWindowListeners()` if I delete everything inside it, the problem is gone. So it seems that the problems is with windows eventListeners preventing the app existing. Now I need to figure out how to remove all those listeners – AlekseyHoffman Feb 07 '23 at 05:25
  • In particular, the problem is with this listener: `windows.quickViewWindow.once('closed', () => {createQuickViewWindow()})` – AlekseyHoffman Feb 07 '23 at 05:45

1 Answers1

1

Found the problem - you have to remove some created window listeners such as closed, for Electron to quit properly.

Make sure you pass the same callback to removeListener

// Create window listeners
windows.quickViewWindow.once('closed', () => createQuickViewWindow)


// Remove window listeners
function removeWindowListeners () {
  windows.quickViewWindow.removeListener('closed', () => createQuickViewWindow)
}

electron.app.on('before-quit', () => {
  removeWindowListeners()
})
AlekseyHoffman
  • 2,438
  • 1
  • 8
  • 31
  • I don't know if it's that you have to remove closed listeners perse, but I guess your handler is creating a new window, which is keeping the app alive, so in your particular case, maybe it's necessary – pushkin Feb 07 '23 at 15:27