electron 显示对话框 showMessageBoxSync showMessageBox

 

7.3.2的文档:https://github.com/electron/electron/blob/v7.3.2/docs/api/dialog.md 不同版本可以切换

一个是同步对话框,另外一个是异步。

同步:

复制代码
//will-prevent-unload这个事件只会在弹出框关闭时触发,比如alert,confirm
win.webContents.on('will-prevent-unload', (event) => {
    console.log(" ==cust_event_notify_dialog_confirm==");
    const options = {
        type: 'question',
        buttons: ['Cancel', 'Yes, please', 'No, thanks'],
        defaultId: 2,
        cancelId: 0,
        title: 'Question',
        message: 'my window?',
        detail: 'It does not really matter',
        checkboxLabel: 'remember',
        checkboxChecked: true,
    }; 
  
  const choice= dialog.showMessageBoxSync(win, options);
   const isCancel = (choice === 0)
   
  if (!isCancel) {
    event.preventDefault()//确认
  }  
})
复制代码

异步:

复制代码
// 窗口关闭
win.on('close', (e) => {
        e.preventDefault();
        dialog.showMessageBox(win, {
            type: 'warning',
            title: '关闭',
            message: '是否退出?',
            buttons: ['取消', '确定']
        }).then((index) => {
            if (index.response === 1) {
                win = null;
                app.exit();
            }
        });
});
复制代码

 

posted @   Bigben  阅读(2803)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2018-08-06 为什么每次app访问服务器都建立新连接 导致服务器大量连接疯涨
2015-08-06 udp内网穿透 两个内网互联
2015-08-06 UDP 内网穿透 心跳
2013-08-06 Ubuntu 13.04下构建Qt5开发环境
点击右上角即可分享
微信分享提示