mirror of
https://github.com/atom/atom.git
synced 2026-02-07 21:25:05 -05:00
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.
11 lines
237 B
JavaScript
11 lines
237 B
JavaScript
const {remote} = require('electron')
|
|
|
|
let windowLoadSettings = null
|
|
|
|
module.exports = () => {
|
|
if (!windowLoadSettings) {
|
|
windowLoadSettings = JSON.parse(remote.getCurrentWindow().loadSettingsJSON)
|
|
}
|
|
return windowLoadSettings
|
|
}
|