gpt4 book ai didi

electron - 如何获取调用事件的BrowserWindow实例?

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

示例

您已打开多个BrowserWindows并将其存储在BrowserWindows数组中,您想知道哪个窗口称为close事件,以便可以从数组中删除该特定的BrowserWindow。

window.on('close', () => {
// Get the instance of the window that called this event
})

怎么样?

最佳答案

由于event.sender的类型为WebContents,因此,仅当您将BrowserWindowevent.sender属性进行比较时,您才能将它与BrowserWindow.webContents进行比较,但我想这不会提供唯一的标识。一种解决方法是将event.sender.idwindow.id进行比较

window.on ('close', (event) => {
// Use event.sender to get the instance of the window that called this event
console.log (event.sender.id === window.id); // -> true
});

关于electron - 如何获取调用事件的BrowserWindow实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55408514/

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