【问题标题】:Electron process keep running after closing关闭后电子进程继续运行
【发布时间】:2019-08-05 02:53:35
【问题描述】:

在关闭我的 Electron 应用程序时继续运行。 这是我的代码:

  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();
    }
  })

我做错了什么?

【问题讨论】:

    标签: node.js process electron


    【解决方案1】:

    您正在阻止关闭事件的默认行为。 (e.PreventDefault())

    您不应要求用户确认关闭事件。 window.on('close') 事件的目的是执行清理任务,例如删除临时文件,如果 window 是父窗口则关闭其他相关进程。

    你可以这样写:

    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. 
    })
    

    【讨论】:

      猜你喜欢
      • 2015-11-09
      • 1970-01-01
      • 2014-09-14
      • 1970-01-01
      • 2015-01-26
      • 1970-01-01
      • 1970-01-01
      • 2018-10-12
      • 2013-12-08
      相关资源
      最近更新 更多