Access localStorage from the main process

Hi !

I know there’s a difference between the render process and the main process, anyway, I’m looking for a way to access localStorage from my main process: I found that the best way to integrate a config file in my app was to use localStorage -> I’d like to register my window dimensions and positionning to my config so I can redraw the windows nicely on startup.

something like:

var config = JSON.parse(localStorage.getItem('config'));

// Browser Window options
var mainWindowOption = {
    'width'      : config.width,
    'height'     : config.height,
    'min-width'  : 1000,
    'min-height' : 600,
    'frame'      : false
};

// Create the browser window
mainWindow = new BrowserWindow(mainWindowOption);

is it simply impossible or is there still hope ?

best,
Pierre

Maybe you could have the browser window be hidden initially then use IPC to send the config to the main process.

That’s an nice idea indeed, But this will “increase” startup time. I’ll use it if I don’t find something else.

The main process does not have access to web APIs. I guess you could read the localStorage database directly from disk (it’s a SQLite database) but that seems worse than adding ~1ms to startup.

Perhaps you’ll be interested in this https://github.com/yeoman/configstore

I finally built my own package, it’s available over there: https://github.com/KeitIG/teeny-conf :slight_smile: