久久久久久久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在线 | 欧美性一级 | 国产精品高潮呻吟久久久久 | 一区在线视频 | 成人在线观看免费 | 九九综合九九 | 美女视频一区 | 99久久精品国产麻豆演员表 | 国产精品久久久久久久久免费樱桃 | 成人午夜视频在线观看 | 在线色网 | 69电影网| 成人一区二区视频 | 国产精品一区二区三区在线 | 美女爽到呻吟久久久久 | 色综合天天天天做夜夜夜夜做 | 欧美一级做性受免费大片免费 | 特级黄一级播放 | 国产一区二区三区亚洲 | 日本成人三级电影 | 91电影在线播放 | 成人精品视频在线观看 | 欧美黄色大片在线观看 | 国产精品久久久久久久久久软件 | www.一区二区三区 | 91一区 | 91精品国产手机 | 黄色网址在线免费观看 | 在线免费看黄 | 天天干天天玩天天操 | a级片在线观看 | 欧美日一区二区 | 久草热8精品视频在线观看 午夜伦4480yy私人影院 | 黄色在线观看国产 | 国产免费观看久久黄av片涩av | 成年人免费在线视频 | www视频在线观看 | 欧美午夜精品久久久久久浪潮 |