gpt4 book ai didi

javascript - 我无法使用变量设置 Electron 窗口的大小

转载 作者:行者123 更新时间:2023-12-03 12:36:51 25 4
gpt4 key购买 nike

我正在尝试从config.ini文件中读取高度和宽度数据,以将它们设置为BrowserWindow。但是,即使我检查变量是否正确,我的 Electron 窗口也将其设置为800x600。这是我的代码:

app.on("ready", () => {
//Reading the config.ini file
//config.ini file uses in main process, preferences.json uses in renderer process
function readConfig(callback) {
fs.readFile('./config.ini', 'utf-8', function(err, data) {
if (err) data = undefined;
callback(data);
});
}

//I use callback because I wanted to be sure file be readen before initilazing the window.
readConfig(function(data) {
if (data !== undefined && data !== null) {
let config = ini.parse(data);
windowH = config.height;
windowW = config.width;
}
startApp(windowW, windowH);
});
});
startApp()函数:
function startApp(w,h) {
//Electron Window
mainWindow = new BrowserWindow({
frame: false,
width: w,
height: h,
minWidth: 800,
minHeight: 600,
backgroundColor: '#1f2646',
icon: __dirname + '/icon.ico',
webPreferences: {
nodeIntegration: true,
devTools: process.env.NODE_ENV === "development",
enableRemoteModule: true
}
});

console.log(mainWindow.getSize()); //Prints [800, 600]
console.log("Width:"+w.toString()); //1800
console.log("Height:"+h.toString()); //1200
}

最佳答案

我立即想通了,我从config.ini中读取的数据是一个字符串。我不敢相信我如何错过那部分。

关于javascript - 我无法使用变量设置 Electron 窗口的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66618988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com