const { app, BrowserWindow, dialog } = require('electron');
const fs = require('fs');
const path = require('path')
let mainWindow = null;
app.on('ready', () => {
mainWindow = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
mainWindow.loadFile(path.join(__dirname, 'index.html'));
mainWindow.once('ready-to-show', () => {
mainWindow.show();
//mainWindow.webContents.openDevTools();
getFileFromUser();
});
mainWindow.on('closed', () => {
mainWindow = null;
});
});
const getFileFromUser = async () => {
// Triggers the OS' Open File Dialog box. We also pass it as a Javascript
// object of different configuration arguments to the function
const files = await dialog.showOpenDialog(mainWindow, {
// The Configuration object sets different properties on the Open File Dialog
properties: ['openFile']
}).catch((err)=> {
return callback(err)
})
if (!files) {
return;
}
const file = files[0];
const content = fs.readFileSync(file).toString();
console.log(content)
}