我希望用户能够从文件夹对话框中选择一个文件夹。
到目前为止,我试过下面的this教程没有成功。
我就死在的电子 - 打开文件夹对话框
exports.selectDirectory = function() {
// dialog.showOpenDialog as before
}
的一部分,我需要以检索所选文件夹的完整路径,怎么办?
谢谢!
我希望用户能够从文件夹对话框中选择一个文件夹。
到目前为止,我试过下面的this教程没有成功。
我就死在的电子 - 打开文件夹对话框
exports.selectDirectory = function() {
// dialog.showOpenDialog as before
}
的一部分,我需要以检索所选文件夹的完整路径,怎么办?
谢谢!
Dialog api在主进程中可用(https://electron.atom.io/docs/)。
要创建一个对话框,您必须通过从渲染器进程发送消息来告诉主进程。这里主窗口,它的父browserWindow将举行对话框:
试试这个代码:
// in your renderer process:-
const ipcRenderer = require('electron').ipcRenderer;
ipcRenderer.send('selectDirectory');
//in you main process:-
const electron = require('electron');
const ipcMain = electron.ipcMain;
const dailog = electron.dialog;
//hold the array of directory paths selected by user
let dir;
ipcMain.on('selectDirectory', function() {
dir = dialog.showOpenDialog(mainWindow, {
properties: ['openDirectory']
});
});
注意。
有人可以帮助我吗?谢谢! – avi12
好吧,我解决了这个问题,使用了我在主要文章中提到的文章帖子和[this](https://stackoverflow.com/questions/35711134/electron-call-renderer-function-from-main)回答。 – avi12