1 回答

TA貢獻1799條經驗 獲得超9個贊
我在某種幫助下弄明白了。因此,如果有人需要相同的程序,我會嘗試解釋我做了什么。
所以,總的來說,我不得不添加一個 then,因為 showDialog 返回一個承諾
if (os.platform() === "linux" || os.platform() === "win32") {
dialog
.showOpenDialog({
properties: ["openFile", "openDirectory"],
})
.then((result) => {
if (result) win.webContents.send("path:selected", result.filePaths);
})
.catch((err) => {
console.log(err);
});
} else {
dialog
.showOpenDialog({
properties: ["openFile", "openDirectory"],
})
.then((result) => {
console.log(result.filePaths);
if (result) win.webContents.send("path:selected", result.filePaths);
})
.catch((err) => {
console.log(err);
});
}
});
這將發回一個路徑為 [0] 的數組
在渲染器中,我忘記將事件添加為參數。
ipc.on("path:selected", (event, path) => {
chosenPath = path;
console.log("Full path: ", chosenPath[0]);
});
添加回答
舉報