【发布时间】:2016-08-16 22:20:17
【问题描述】:
我尝试从 json 文件加载并传递 x、y 位置和宽度、高度。这是我的代码
const electron = require('electron')
const {app, BrowserWindow} = electron
var fs = require('fs');
var loadsttngs = JSON.parse(fs.readFileSync('settings.json', 'utf8'));
console.log(loadsttngs.width);
let win
function createWindow () {
win = new BrowserWindow({
x: loadsttngs.x,
y: loadsttngs.y,
width: loadsttngs.width,
height: loadsttngs.height,
frame: false})
win.setMenu(null)
win.loadURL(`file://${__dirname}/index.html`)
win.webContents.openDevTools()
// Emitted when the window is closed.
win.on('closed', () => {
//var bounds = win.getBounds();
win = null
})
}
console.log(loadsttngs.width); 返回正确的值,所以读取文件没有问题但是在new BrowserWindow 中没有使用(比如使用一些默认值)。如果我将值直接写入new BrowserWindow 工作正常。
settings.json { “x”:“50”, “y”:“50”, “宽度”:“1200”, “身高”:“200”, “最大化”:“假” }
【问题讨论】: