Electron BrowserWindow return 关闭
Electron BrowserWindow return on close
在 electron 中关闭 BrowserWindow 时有没有办法 return 值?
充其量我希望有一种方法可以从关闭事件中获取变量:
win.on('closed', function(variables received here) {
console.log(variables + ' ' + received + ' ' + here);
win = null;
});
遗憾的是,无法在关闭事件中获取 return 值。但是,您可以 运行 在 window 关闭之前使用 window.onbeforeunload
的函数。
在此函数中,您可以从 BrowserWindow
实例中获取所需的信息或数据,并向主进程发送同步 IPC 消息以获取所需的变量。
如果你同步发送它,然后 return 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 了解更多信息。
在 electron 中关闭 BrowserWindow 时有没有办法 return 值?
充其量我希望有一种方法可以从关闭事件中获取变量:
win.on('closed', function(variables received here) {
console.log(variables + ' ' + received + ' ' + here);
win = null;
});
遗憾的是,无法在关闭事件中获取 return 值。但是,您可以 运行 在 window 关闭之前使用 window.onbeforeunload
的函数。
在此函数中,您可以从 BrowserWindow
实例中获取所需的信息或数据,并向主进程发送同步 IPC 消息以获取所需的变量。
如果你同步发送它,然后 return 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 thanundefined
would cancel the close.
查看 close event 了解更多信息。