Bootstrap

Electron 窗口关闭提示

Electron 窗口关闭提示

/***
   * 关闭窗口前提示确认信息
   */
  win.on('close', (e) => {
    e.preventDefault()//阻止默认行为,一定要有
    dialog.showMessageBox({
      type: 'info',
      title: 'Information',
      cancelId:2,
      defaultId: 0,
      message: '确定要关闭吗?',
      buttons: ['最小化','直接退出']
    }).then(result => {
      if (result.response == 0) {
        e.preventDefault();		//阻止默认行为,一定要有
        win.minimize();	//调用 最小化实例方法
      } else if(result.response == 1) {
        win = null;
        //app.quit();	//不要用quit();试了会弹两次
        app.exit();		//exit()直接关闭客户端,不会执行quit();
      }
    }).catch(err => {
      console.log(err)
    })
  });

具体参考electron文档

;