Javascript 如何防止电子商务中出现多个对话框

Javascript 如何防止电子商务中出现多个对话框,javascript,electron,Javascript,Electron,我正在用electron的对话框打开一些消息框。showMessageBox 但它目前正在打开多个盒子。我想一次只打开一个消息框 fetch(payload.url) .then(res => res.json()) .then(data => { download(BrowserWindow.getFocusedWindow(), data.presigned_url, { saveAs: true, // openFolderWhenDon

我正在用electron的
对话框打开一些消息框。showMessageBox

但它目前正在打开多个盒子。我想一次只打开一个消息框

fetch(payload.url)
  .then(res => res.json())
  .then(data => {
    download(BrowserWindow.getFocusedWindow(), data.presigned_url, {
      saveAs: true,
      // openFolderWhenDone: true,
      showBadge: false,
      filename: payload.filename
    }).then(item => {
      const filePath = item.getSavePath();
      dialog.showMessageBox(
        BrowserWindow.getFocusedWindow(),
        {
          type: 'info',
          title: 'Download Status',
          message: 'Download Complete',
          buttons: ['Close', 'Open Folder', 'Open'],
        },
        dialogId => {
          switch (dialogId) {
            case 0:
              break;
            case 1:
              shell.showItemInFolder(filePath);
              break;
            case 2:
              shell.openItem(filePath);
            default:
              break;
          }
        },
      );
    });
  });
例如,我希望在新消息框打开时关闭上一个消息框,或者如果已经打开了下一个消息框,则不允许打开下一个消息框

任何形式的帮助都将不胜感激。

在我的项目中, 我给出了一个state属性,例如isOpenBrowseFileDialog,并将其用作标志。如果启动该对话框,该标志将设置为true,这将有助于防止打开多个对话框

browseFiles = async (e) => {
    e.preventDefault();
    const ref = this;
    const { isOpenBrowseFileDialog } = this.state;
    if(isOpenBrowseFileDialog === false) {
      this.setState({
        isOpenBrowseFileDialog: true
      });
      remote.dialog.showOpenDialog({
        properties: ['openFile', 'multiSelections']
      }, async (files) => {
        if (files !== undefined) {
          await ref.handleFilesAfterAdding(files);
        }
        ref.setState({
          isOpenBrowseFileDialog: false
        });
      });
    }
  }

代码是什么样子的?我添加了代码@0.sh根据electron文档,似乎我无法通过编程关闭消息框。为什么不自己维护一个标志?我想知道在消息框关闭时如何关闭标志。是否可以捕获模式关闭事件@pergy@emil对于任何传入的
对话框id
,您可以确保对话框正在关闭,以便可以在回调中切换标志。你所说的“模式关闭事件”是什么意思?如果对话框中出现
X
on,则也会使用
dialogId:0