Currently, I am utilizing the Electron open dialog function:
var electron = require('electron');
const {dialog} = electron.remote;
var selectedFile = dialog.showOpenDialog({properties: ['openFile' ], filters: [{name: 'Scripts', extensions: ['sh']}]} );
I defined an Electron function as follows
function fetchFileContent(filePath, callbackFunction) {
var fs = require('fs');
fs.readFile(filePath, 'utf8', function (err, data) {
callbackFunction(err, data);
});
}
exports.fetchFileContent = fetchFileContent;
Afterwards, I am invoking the Electron function and passing a callback function along
var readScriptFromFile = electron.remote.require('./main.desktop').fetchFileContent;
readScriptFromFile(filePath, this.afterReadingScriptCallback);
When trying to access component variables using this.myVar
within the callback function, they are undefined due to possibly being out of scope?
afterReadingScriptCallback(err, data) {
if(err){
console.log('error reading file: ', err);
} else {
this.myVar = data;
}
}
Is there a way to retrieve this.myVar
variables from inside the Electron callback function?