|
| 1 | +// Modules to control application life and create native browser window |
| 2 | +const { app, BrowserWindow } = require('electron'); |
| 3 | + |
| 4 | +const { NODE_ENV } = process.env; |
| 5 | + |
| 6 | +// Keep a global reference of the window object, if you don't, the window will |
| 7 | +// be closed automatically when the JavaScript object is garbage collected. |
| 8 | +let mainWindow; |
| 9 | + |
| 10 | +function createWindow() { |
| 11 | + // Create the browser window. |
| 12 | + mainWindow = new BrowserWindow({ |
| 13 | + webPreferences: { |
| 14 | + webSecurity: false, |
| 15 | + allowDisplayingInsecureContent: true, |
| 16 | + }, |
| 17 | + title: 'Wavy X', |
| 18 | + transparent: true, |
| 19 | + width: 1024, |
| 20 | + height: 768, |
| 21 | + center: true, |
| 22 | + enableLargerThanScreen: false, |
| 23 | + resizable: true, |
| 24 | + frame: true, |
| 25 | + titleBarStyle: 'hidden', |
| 26 | + }); |
| 27 | + |
| 28 | + console.log({ NODE_ENV }); |
| 29 | + // and load the index.html of the app. |
| 30 | + if (NODE_ENV === 'development') { |
| 31 | + mainWindow.loadURL('http://localhost:9000/'); |
| 32 | + } else { |
| 33 | + mainWindow.loadURL('https://app.wavy.fr'); |
| 34 | + } |
| 35 | + |
| 36 | + // Open the DevTools. |
| 37 | + // mainWindow.webContents.openDevTools() |
| 38 | + |
| 39 | + // Emitted when the window is closed. |
| 40 | + mainWindow.on('closed', () => { |
| 41 | + // Dereference the window object, usually you would store windows |
| 42 | + // in an array if your app supports multi windows, this is the time |
| 43 | + // when you should delete the corresponding element. |
| 44 | + mainWindow = null; |
| 45 | + }); |
| 46 | +} |
| 47 | + |
| 48 | +// This method will be called when Electron has finished |
| 49 | +// initialization and is ready to create browser windows. |
| 50 | +// Some APIs can only be used after this event occurs. |
| 51 | +app.on('ready', createWindow); |
| 52 | + |
| 53 | +// Quit when all windows are closed. |
| 54 | +app.on('window-all-closed', () => { |
| 55 | + // On OS X it is common for applications and their menu bar |
| 56 | + // to stay active until the user quits explicitly with Cmd + Q |
| 57 | + if (process.platform !== 'darwin') { |
| 58 | + app.quit(); |
| 59 | + } |
| 60 | +}); |
| 61 | + |
| 62 | +app.on('activate', () => { |
| 63 | + // On OS X it's common to re-create a window in the app when the |
| 64 | + // dock icon is clicked and there are no other windows open. |
| 65 | + if (mainWindow === null) { |
| 66 | + createWindow(); |
| 67 | + } |
| 68 | +}); |
| 69 | + |
| 70 | +// In this file you can include the rest of your app's specific main process |
| 71 | +// code. You can also put them in separate files and require them here. |
0 commit comments