I've got some data i need to save to a file. On a button click i need to save it and then close the window. However when i call a save() function and a close() function the window will close without having saved anything.
I have tried calling two functions on an event. I have tried creating one function where the data is saved and then window is closed.
const button = document.getElementById('done');
button.addEventListener('click', () => {
closeWin();
});
function closeWin(){
saveData();
const remote = require('electron').remote;
var window = remote.getCurrentWindow();
window.close();
}
function saveData(){
const fs = require('fs');
fs.writeFile('data.txt', 'Test Data Output', function (err) {
if (err) throw err;
});
}
Expected: Data saved to file (txt in this case) Output: Window closed and blank file created with no data