theaveragedev
theaveragedev

Reputation: 23

Electron dialog.showOpenDialog not running callback

I have been trying to make a simple program to create and read files with Electron. So far I have tried a lot and it seems the callback function I provide with the dialog.showOpenDialog is not being called.

    dialog.showOpenDialog( (filePaths) => {
        console.log('this callback is called');
        console.log(filePaths);
    });

    //Directly read a test file
    fs.readFile('readtest.txt', 'utf-8', (err, data) => {
        if (err) throw err;
        console.log(data);
    });

This is the code inside my read button handler. The dialog opens and I choose a file and it simply does nothing. However the same file which I selected is read by the fs.readFile and displayed in the console.

It seems the callback is not getting called after I choose the file.

Upvotes: 2

Views: 665

Answers (1)

user13019232
user13019232

Reputation:

It returns a promise, so you can chain it with .then:

    dialog.showOpenDialog(null, options).then((filePaths) => {
    console.log('this callback is called');
    console.log(filePaths);
});

Upvotes: 4

Related Questions