I keep getting this error:
TypeError: Cannot read properties of undefined (reading 'showOpenDialog')
How to call showOpenDialog()
with minimal changes?
I'm using the new Quasar/Electron with Webpack 5.
This is the openFile() method in my vue file:
openFile () { window.electronApi.dialog.showOpenDialog({ title: 'Load File', properties: ['openFile'] }).then(result => { const filename = result.filePaths[0] if (filename) { const extension = getExtensionName(filename) console.log(extension) } else { console.log('No file selected') } }).catch(err => { console.log(FILE + 'Error: ' + err) }) },
This is what is declared in electro-preload.js:
import { contextBridge} from 'electron' contextBridge.exposeInMainWorld('electronApi', { dialog: require('electron').dialog, showOpenDialog: require('electron').showOpenDialog })
Thanks to @creative learner for the idea! This works!