DaniP
DaniP

Reputation: 1

Electron process keep running after closing

on closing my Electron app process keep running. here's my code:

  label: 'Close', click() {
    app.quit()
  }

  window.on('close', function (e) {
    var choice = require('electron').dialog.showMessageBox(this,
      {
        type: 'question',
        buttons: ['Yes', 'No'],
        title: 'Confirm',
        message: 'Are you sure you want to quit?'
      });
    if (choice == 1) {
      e.preventDefault();
    }
  })

What i'm doing wrong?

Upvotes: 0

Views: 2759

Answers (1)

Imtiyaz Shaikh
Imtiyaz Shaikh

Reputation: 615

You are preventing default behavior of Close event. (e.PreventDefault())

You should not ask for user confirmation on close event. The purpose of window.on('close') event is to perform cleanup tasks such as removing temp files, closing other related processes if window is a parent window.

You can write it in this way:

label: 'Close', click() {
    var choice = require('electron').dialog.showMessageBox({
    type: 'question',
    buttons: ['Yes', 'No'],
    title: 'Confirm',
    message: 'Are you sure you want to quit?'
}, (response) => {
    if (response == '0') {
        app.quit()
    }
})

window.on('close', function (e) {
   window = null // Clean up your window object. 
})

Upvotes: 1

Related Questions