blob: 860fc31e25a17beb7f0d669a178bd28b5c959fce [file] [log] [blame]
Sui Chenb65280f2020-06-30 18:14:03 -07001// Modules to control application life and create native browser window
Sui Chenb53fa1b2022-05-26 00:16:42 -07002const {app, BrowserWindow, dialog, ipcMain } = require('electron');
Sui Chenb65280f2020-06-30 18:14:03 -07003const path = require('path');
Sui Chenb53fa1b2022-05-26 00:16:42 -07004const {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});
Sui Chenb65280f2020-06-30 18:14:03 -070014
15function createWindow() {
16 // Create the browser window.
17 const mainWindow = new BrowserWindow({
18 width: 1440,
19 height: 900,
20 webPreferences: {
Sui Chenb65280f2020-06-30 18:14:03 -070021 nodeIntegration:
Sui Chen27cf9332021-11-03 16:20:28 -070022 true, // For opening file dialog from the renderer process
Sui Chenb53fa1b2022-05-26 00:16:42 -070023 contextIsolation: false,
Sui Chenb65280f2020-06-30 18:14:03 -070024 }
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.