1// Modules to control application life and create native browser window 2const {app, BrowserWindow, dialog, ipcMain } = require('electron'); 3const path = require('path'); 4const {fs} = require('file-system'); 5 6// Open-file dialog 7ipcMain.on('file-request', (event) => { 8 const options = { 9 title: 'Open a file or folder', 10 }; 11 const x = dialog.showOpenDialogSync(options) + ''; // Convert to string 12 event.reply("filename", x); 13}); 14 15function createWindow() { 16 // Create the browser window. 17 const mainWindow = new BrowserWindow({ 18 width: 1440, 19 height: 900, 20 webPreferences: { 21 nodeIntegration: 22 true, // For opening file dialog from the renderer process 23 contextIsolation: false, 24 } 25 }); 26 27 // and load the index.html of the app. 28 mainWindow.loadFile('index.html'); 29 30 // Open the DevTools. 31 // mainWindow.webContents.openDevTools() 32} 33 34// This method will be called when Electron has finished 35// initialization and is ready to create browser windows. 36// Some APIs can only be used after this event occurs. 37app.whenReady().then(createWindow); 38 39// Quit when all windows are closed. 40app.on('window-all-closed', function() { 41 // On macOS it is common for applications and their menu bar 42 // to stay active until the user quits explicitly with Cmd + Q 43 if (process.platform !== 'darwin') app.quit(); 44}) 45 46app.on('activate', function() { 47 // On macOS it's common to re-create a window in the app when the 48 // dock icon is clicked and there are no other windows open. 49 if (BrowserWindow.getAllWindows().length === 0) createWindow(); 50}); 51 52// In this file you can include the rest of your app's specific main process 53// code. You can also put them in separate files and require them here. 54