gpt4 book ai didi

javascript - Electron 设备:dialog.showMessageBox()无法与父窗口一起使用(模式失败)

转载 作者:行者123 更新时间:2023-12-03 12:22:17 31 4
gpt4 key购买 nike

我正在学习Electron并尝试非常基础的东西……没有成功。
无论我使用哪种技术使对话框模态化,它都会失败。对话框不是模态的,或者对话框是空的(...仍然不是模态的)。

const {BrowserWindow, dialog} = require('electron')

dialog.showMessageBoxSync(BrowserWindow.getFocusedWindow(), {message: "FooBar"});
// Not modal: BrowserWindow.getFocusedWindow() returns null.

dialog.showMessageBoxSync(BrowserWindow.getAllWindows()[0], {message: "FooBar"});
// Not modal: BrowserWindow.getAllWindows() returns an empty array.

dialog.showMessageBoxSync(parentWindow, {message: "FooBar"});
// "parentWindow" comes from the "click" handler of the menu item launching the message box: it is not null.
// Error: the message box is not modal, and does not display "FooBar" (i.e. it is empty).
从主过程中调用此代码,并且在终端或开发工具中未显示任何错误。如果我使用 dialog.showMessageBox()而不是 showMessageBoxSync(),结果是相同的。
Electron 版:Windows 10(x64)上的v9.0.5。

最佳答案

好的,错误是我的主窗口是BrowserWindow的子类。 Electron不允许对 native 类进行子类化。查看问题:
https://github.com/electron/electron/issues/23
https://github.com/electron/electron/issues/8898
https://github.com/electron/electron/issues/10019
https://github.com/electron/electron/issues/15456
遗憾的是,官方文档仍然没有提到这一重要限制。

关于javascript - Electron 设备:dialog.showMessageBox()无法与父窗口一起使用(模式失败),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62625919/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com