我正在尝试在自己正在构建的本教程应用程序中实现I / O操作。其他所有东西都正常运行,我唯一的问题是应用程序没有console.log()所需的结果,该结果应该是对话框中所选文件的位置。
这是屏幕截图
答案 0 :(得分:2)
正如r3wt所说,当您看到promise<pending>
时,表示您没有适当地等待异步函数的返回。尝试将getFileFromUser函数更改为异步,例如:
const getFileFromUser = async () => {
// Triggers the OS' Open File Dialog box. We also pass it as a Javascript
// object of different configuration arguments to the function
//This operation is asynchronous and needs to be awaited
const files = await dialog.showOpenDialog(mainWindow, {
// The Configuration object sets different properties on the Open File Dialog
properties: ['openFile']
});
// If we don't have any files, return early from the function
if (!files) {
return;
}
// Pulls the first file out of the array
//const file = files[0];
// Reads from the file and converts the resulting buffer to a string
//const content = fs.readFileSync(file).toString();
// Log the Files to the Console
console.log(files)
}