Access localStorage from the main process


#1

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


#2

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


#3

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


#4

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.


#5

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


#6

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