Files
atom/src/get-window-load-settings.js
Antonio Scandurra 051e27dbcb Expose load settings to BrowserWindows as JSON
When accessing objects in the main process via the `remote` module,
Electron returns proxy objects that are references to the original ones.
This means that trying to access a remote object's property or function
results in a synchronous message exchange with the main process.

In Atom core we frequently access the load settings coming from the main
process, especially during startup. This caused a lot of synchronous I/O
which was blocking the renderer process for several milliseconds.

With this commit, instead of exposing load settings as a JavaScript
object, we serialize them to JSON in the main process and parse them
back to a JavaScript object in the renderer processes. This allows us to
get a full copy of the object locally and pay for I/O just once when
retrieving load settings from the main process for the first time.
2017-03-07 10:54:42 +01:00

11 lines
237 B
JavaScript

const {remote} = require('electron')
let windowLoadSettings = null
module.exports = () => {
if (!windowLoadSettings) {
windowLoadSettings = JSON.parse(remote.getCurrentWindow().loadSettingsJSON)
}
return windowLoadSettings
}