|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const { BrowserWindow } = require('electron'); |
| 4 | + |
| 5 | +// Keep a global reference of the window object, if you don't, the window will |
| 6 | +// be closed automatically when the JavaScript object is garbage collected. |
| 7 | +let mainWindow; |
| 8 | + |
| 9 | +function getMainWindow() { |
| 10 | + return mainWindow; |
| 11 | +} |
| 12 | + |
| 13 | +function createWindow() { |
| 14 | + // Create the browser window. |
| 15 | + mainWindow = new BrowserWindow({ |
| 16 | + width: 1600, |
| 17 | + height: 1200, |
| 18 | + 'min-width': 600, |
| 19 | + 'min-height': 400 |
| 20 | + }); |
| 21 | + |
| 22 | + // and load the index.html of the app. |
| 23 | + if (process.env.NODE_ENV === 'development') { |
| 24 | + mainWindow.loadURL('http://localhost:3001/index.html'); |
| 25 | + mainWindow.webContents.openDevTools(); |
| 26 | + } else { |
| 27 | + mainWindow.loadURL('file://' + __dirname + '/dist/index.html'); |
| 28 | + } |
| 29 | + |
| 30 | + // Emitted when the window is closed. |
| 31 | + mainWindow.on('closed', function() { |
| 32 | + // Dereference the window object, usually you would store windows |
| 33 | + // in an array if your app supports multi windows, this is the time |
| 34 | + // when you should delete the corresponding element. |
| 35 | + mainWindow = null; |
| 36 | + }); |
| 37 | +} |
| 38 | + |
| 39 | +// Create new window instances |
| 40 | +function createNewWindow(event, config) { |
| 41 | + let win = new BrowserWindow({ |
| 42 | + width: config.width || 1000, |
| 43 | + height: config.height || 700, |
| 44 | + show: true |
| 45 | + }); |
| 46 | + |
| 47 | + if (process.env.NODE_ENV === 'development') { |
| 48 | + win.loadURL('http://localhost:3001' + (config.path || '/index.html')); |
| 49 | + win.webContents.openDevTools(); |
| 50 | + } else { |
| 51 | + win.loadURL('file://' + __dirname + '/dist' + (config.path || '/index.html')); |
| 52 | + } |
| 53 | + |
| 54 | + win.on('closed', function() { |
| 55 | + win = null; |
| 56 | + }); |
| 57 | +} |
| 58 | + |
| 59 | +function launchFeedbackPopup() { |
| 60 | + mainWindow.webContents.send('launchFeedbackPopup'); |
| 61 | +} |
| 62 | + |
| 63 | +module.exports = { |
| 64 | + createWindow, |
| 65 | + createNewWindow, |
| 66 | + getMainWindow, |
| 67 | + launchFeedbackPopup |
| 68 | +}; |
0 commit comments