久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

dialog.showMessageBox 不返回電子 main.js 中的按鈕索引

dialog.showMessageBox not returning button index in electron main.js(dialog.showMessageBox 不返回電子 main.js 中的按鈕索引)
本文介紹了dialog.showMessageBox 不返回電子 main.js 中的按鈕索引的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個消息框,當(dāng)用戶單擊dashboardWindow 上的關(guān)閉時會打開一個消息框(Windows 操作系統(tǒng)右上角的X 按鈕)

I have a messagebox that will open when the user click close on dashboardWindow (X button top right on windows os)

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

當(dāng)我關(guān)閉 dashboardWindow 時消息框打開,但我無法讓 response === 0 工作.即使沒有點擊按鈕,console.log("after message box"); 也已經(jīng)運行.我怎樣才能做出響應(yīng)(messageBox 上的返回索引按鈕)?

The messagebox opened when i close the dashboardWindow but i can't get response === 0 to work. Samehow console.log("after message box"); already run even when there is no click on the buttons. How I can make the response work (return index button on messageBox)?

登錄窗口關(guān)閉

推薦答案

請參考最新的 API 文檔關(guān)于 dialog.showMessageBox:此方法返回一個 Promise 對象并且不再使用回調(diào)函數(shù),就像在 Electron v5.xx 之前一樣

Please refer to the most recent API doc about dialog.showMessageBox: this method returns a Promise object and doesn't make use of a callback function any more, like it used to until Electron v5.x.x.

Returns Promise - 使用包含以下屬性:

Returns Promise<Object> - resolves with a promise containing the following properties:

  • response Number - 點擊按鈕的索引.
  • checkboxChecked 布爾值 - 如果設(shè)置了 checkboxLabel,則復(fù)選框的選中狀態(tài).否則 false.
  • response Number - The index of the clicked button.
  • checkboxChecked Boolean - The checked state of the checkbox if checkboxLabel was set. Otherwise false.

這應(yīng)該可以工作(盡管在您的上下文中未經(jīng)測試):

This should work then (untested in your context though):

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
      })
      .then(result => {
        if (result.response === 0) {
          // bound to buttons array
          console.log("Default button clicked.");
        } else if (result.response === 1) {
          // bound to buttons array
          console.log("Cancel button clicked.");
        }
      }
    );
    console.log("after message box");
  });

這篇關(guān)于dialog.showMessageBox 不返回電子 main.js 中的按鈕索引的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進(jìn)程中創(chuàng)建子窗口時如何修復(fù) BrowserWindow 不是構(gòu)造函數(shù)錯誤) - IT屋-程序員軟件開發(fā)技術(shù)
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應(yīng)用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執(zhí)行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內(nèi)使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應(yīng)用程序中訪問相機(jī)/網(wǎng)絡(luò)攝像頭?)
主站蜘蛛池模板: 一级黄色网页 | 久在线精品视频 | 国产乱码精品一区二区三区av | 日韩av在线不卡 | 国产精品视频一区二区三区不卡 | 日韩一区不卡 | 色秀网站 | 欧美综合一区二区三区 | 99av成人精品国语自产拍 | 日韩欧美国产精品一区 | 欧美自拍一区 | 高清国产午夜精品久久久久久 | 亚洲高清在线 | 精品乱子伦一区二区三区 | 免费黄色网址视频 | 国产精品久久久久aaaa | 91中文 | 国产 欧美 日韩 一区 | 一级片av | 九色91视频| 91久久北条麻妃一区二区三区 | 四虎在线观看 | 成人免费视频网站在线观看 | 欧美一区二区三区在线 | 日韩at| 久久精品视频在线观看 | av在线免费网站 | 一区二区三区四区免费视频 | 91就要激情 | 国产在线麻豆精品入口 | 国产欧美精品一区二区色综合朱莉 | 国产成人免费视频网站视频社区 | 九九久久免费视频 | h片在线看 | 久久区二区 | 草樱av| 热久色| 奇米av | 人人干人人干人人 | 日韩中文字幕免费在线观看 | 99精品热视频 |