dialog.showMessageBox不返回电子main.js中的按钮索引

问题描述 投票:0回答:1

我有一个消息框,当用户在dashboardWindow上单击关闭时(Windows操作系统右上角的X按钮),该消息框将打开。>

dashboardWindow.on("close", (event) => {
    event.preventDefault();
    console.log("before message box");
    dialog.showMessageBox(
      dashboardWindows,
      {
        message: "Test",
        buttons: ["Default Button", "Cancel Button"],
        defaultId: 0, // bound to buttons array
        cancelId: 1 // bound to buttons array
      },
      (response) => {
        if (response === 0) {
          // bound to buttons array
          console.log("Default button clicked.");
        } else if (response === 1) {
          // bound to buttons array
          console.log("Cancel button clicked.");
        }
      }
    );
    console.log("after message box");
  });
}

当我关闭dashboardWindow但无法获得response === 0时,打开的消息框。即使没有单击按钮,Samehow console.log("after message box");也已运行。如何使响应有效(messageBox上的返回索引按钮)?

log on window close

我有一个消息框,当用户在dashboardWindow上单击关闭时(Windows操作系统右上角的X按钮),dashboxWindow.on(“ close”,(event)=> {event.preventDefault(); console ....

javascript callback dialog electron messagebox
1个回答
0
投票

请参阅有关dialog.showMessageBox的最新API文档:此方法返回Promise对象,并且不再使用回调函数,就像在Electron v5.x.x之前一样。

© www.soinside.com 2019 - 2024. All rights reserved.