I'm opening the Electron open dialog:
var electron = require('electron');
const {dialog} = electron.remote;
var browsedFile = dialog.showOpenDialog({properties: ['openFile' ], filters: [{name: 'Scripts', extensions: ['sh']}]} );
I have the Electron function declared like
function readFileAsString(filePath, functionCallback) {
var fs = require('fs');
fs.readFile(filePath, 'utf8', function (err, data) {
functionCallback(err, data);
});
}
exports.readFileAsString = readFileAsString;
Then I'm calling the Electron function, passing in a callback function
var openScriptFile = electron.remote.require('./main.desktop').readFileAsString;
openScriptFile(filePath, this.afterOpenScriptFileCallback);
Inside the callback function, I'm trying to access variables in the component via this.myVar
, but they're undefined, presumably out of scope?
afterOpenScriptFileCallback(err, data) {
if(err){
console.log('error opening file: ', err);
} else {
this.myVar = data;
}
}
How do I access this.myVar
variables from inside the callback from Electron?