gpt4 book ai didi

javascript - Electron BrowserWindow 关闭时返回

转载 作者:行者123 更新时间:2023-11-29 14:40:04 27 4
gpt4 key购买 nike

有没有办法在 electron 中关闭 BrowserWindow 时返回值?

充其量我希望有一种方法可以从关闭事件中获取变量:

win.on('closed', function(variables received here) {
console.log(variables + ' ' + received + ' ' + here);
win = null;
});

最佳答案

不幸的是,没有办法在关闭事件中返回值。但是,您可以使用 window.onbeforeunload 在窗口关闭之前运行函数。

在这个函数中,您可以从您的 BrowserWindow 实例中获取您需要的信息或数据,并向您的主进程发送同步 IPC 消息以获取您需要的变量。
如果您同步发送它,然后返回 undefined 您将获得所需的变量,并且 BrowserWindow 仍将关闭,触发您的 close 事件随心所欲。

来自他们的文档:

Usually you would want to use the beforeunload handler to decide whether the window should be closed, which will also be called when the window is reloaded. In Electron, returning any value other than undefined would cancel the close.

查看close event获取更多信息。

关于javascript - Electron BrowserWindow 关闭时返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39573311/

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