Regrettably, there is no direct way to retrieve values within the close event. Nevertheless, you can execute a function before the window closes by utilizing window.onbeforeunload
.
Within this function, you can extract the necessary information or data from your BrowserWindow
instance and transmit a synchronous IPC message to your main process to acquire the required variables.
By sending it synchronously and then returning undefined
, you can obtain the required variables while still allowing the BrowserWindow
to close, triggering your desired close
event.
According to their documentation:
Typically, the beforeunload
handler is used to determine if the window should be closed, which is also triggered when the window is reloaded. In Electron, returning any value other than undefined
would prevent the window from closing.
Refer to the close event for additional details.