I want to create two seperate electron dialogs in the same renderer process for the following things...
- file selection
- Directory selection
I thought I could use one dialog for both File Selection and Directory Selection, but unfortunately that can't be done on both Linux & Windows, unlike how it can on MacOS.
So after some time talking with the devs over at github.com/electron/electron, they have told me that it is possible to use 2 seperate dialogs in the same renderer process of my Linux desktop app, as a workaround to this for Linux & Windows.
The devs pointed me to this page here at electronjs.org, but unfortunately I am having trouble understanding some of it, so I've ended up here at stackoverflow.
The code I've managed to produce so far is below, any help on this would be appreciated.
// First dialog for File Selection | This works fine
$appCtrl.BrowseFile = () => {
dialog.showOpenDialog({'File browser'}, {
properties: ['openFile']
}).then(result => {
if(result.canceled) {
$appCtrl.Log("No file selected");
} else {
$appCtrl.Log("File selected" + result.filePaths[0]);
readFile(result.filePaths[0]);
}
}).catch(() => {
$appCtrl.Log("No file selected");
})
function readFile(filepath) {
$appCtrl.filePath = filepath;
$appCtrl.$apply();
})
// Second Dialog for Folder Selection | This stops my electron UI from working
$appCtrl.BrowseFolder = () => {
dialog.showOpenDialog({'Folder browser'}, {
properties: ['openDirectory']
}).then(result => {
if(result.canceled) {
$appCtrl.Log("No directory selected");
} else {
$appCtrl.Log("Directory selected" + result.filePaths);
readFile(result.filePaths);
}
}).catch(() => {
$appCtrl.Log("No directory selected");
})
function readFile(filepath) {
$appCtrl.filePath = filepath;
$appCtrl.$apply();
})