const {app, BrowserWindow, ipcMain, Menu, globalShortcut} = require('electron'); const path = require('path'); const fs = require("fs"); // Handle creating/removing shortcuts on Windows when installing/uninstalling. // eslint-disable-next-line global-require if (require('electron-squirrel-startup')) { app.quit(); } // store the main window to use a file dialog that blocks access to the app if open. let mainWindow; const createWindow = () => { // Create the browser window. mainWindow = new BrowserWindow({ width: 1200, height: 900, webPreferences: { // not a security problem, as no external content is loaded. see official documentation // https://github.com/electron/electron/blob/main/docs/tutorial/security.md#2-do-not-enable-nodejs-integration-for-remote-content nodeIntegration: true, contextIsolation: false }, }); // and load the index.html of the app. mainWindow.loadFile(path.join(__dirname, 'index.html')); // Open the DevTools. // mainWindow.webContents.openDevTools(); Menu.setApplicationMenu(null) }; // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. // Add shortcut for devtools app.whenReady().then(() => { globalShortcut.register('Shift+CommandOrControl+I', () => { mainWindow.webContents.toggleDevTools(); }) }).then(createWindow) // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); app.on('activate', () => { // On OS X it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); // open a file/folder selection dialog on the main process // https://www.tutorialspoint.com/electron/electron_system_dialogs.htm ipcMain.on('openDialog', (event, data) => { const {dialog} = require('electron') const type = data.type === 'file' ? 'openFile' : 'openDirectory' const multiselect = data.multiselect ? "multiSelections" : "" dialog.showOpenDialog(mainWindow, {properties: [type, 'createDirectory', multiselect], filters: data.filters}) .then((result) => { result.subFolder = data.subFolder if (!result.canceled && result.filePaths) { event.sender.send(data.callback, result) } }) });