Electron dialog.showOpenDialog() 过滤器不工作



我正在GitHub上开发IDE的一个分支,主要问题之一是它将文件保存到cookie中,而不是普通计算机。因此,我需要一种保存和打开文件的方法。我已经通过使用 blob 关闭了保存文件系统。但是,根据控制台的说法,打开文件提供了一个"意外字符串",即使它很普通。

下面是函数:

function openFileCMD() {
console.log('Opening File...');
dialog.showOpenDialog( (fileName), {
filters: [{ 
name: 'Text Files', 
extensions: ['txt'] 
}, { 
name: 'HTML Files',
extensions: ['html', 'htm']
}, {
name: 'Rich Text File',
extensions: ['rtf'] 
}, { 
name: 'XML/YAMLFile', 
extensions: ['xml', 'yml', 'yaml'] 
}, { 
name: 'JSON File', 
extensions: ['json'] }
]} => {
if(fileName === undefined) {
console.log("Ouch. That wall hurt. Can you pick a file this time? Please?");
// document.getElementsByClassName('alert')[0].style.display = "block";
return;
}
fs.readFile(fileName[0], 'utf-8', (err, data) => {
if(err){
alert("Woah. Something went wrong. Check the console for more info.");
console.log("An error occured reading the file : " + err.message);
return;
} else {
document.getElementById("code-editor").value = "<pre><code>" + data + "</code></pre>";
}
});
closeSidebar();
}

提前感谢任何可以帮助解决此问题或为我指出解决此问题的正确方向的人! :)

编辑:我已经尝试了dialog.showOpenDialog都在一行上:仍然无济于事。

您收到的"意外字符串"错误消息与过滤器无关,而是与dialog.showOpenDialog未正确调用的事实有关...

dialog.showOpenDialog (filename, options => { ... });

应该改为:

dialog.showOpenDialog (options, filename => { ... });

最新更新