ditsikts ditsikts - 1 year ago 194
JSON Question

Electron, new BrowserWindow load values

I try load and pass from a json file the x,y position and width, height. Here is my code

const electron = require('electron')
const {app, BrowserWindow} = electron
var fs = require('fs');
var loadsttngs = JSON.parse(fs.readFileSync('settings.json', 'utf8'));
let win

function createWindow () {
win = new BrowserWindow({
x: loadsttngs.x,
y: loadsttngs.y,
width: loadsttngs.width,
height: loadsttngs.height,
frame: false})



// Emitted when the window is closed.
win.on('closed', () => {
//var bounds = win.getBounds();
win = null

return the right value, so there is no problem with reading the file but in the
new BrowserWindow
does not be used(like using some defaults values). If I write the values directly to
new BrowserWindow
works fine.

"x" : "50",
"y" : "50",
"width" : "1200",
"height" : "200",
"maximized": "false"

Answer Source

Your x and y values are strings not numbers.

Should be:


Maximized is also a string not a Boolean.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download