| 40 | } |
| 41 | |
| 42 | function createWindow() { |
| 43 | // get last win stage |
| 44 | const lastWinStage = winState.getLastState(); |
| 45 | |
| 46 | // Create the browser window. |
| 47 | mainWindow = new BrowserWindow({ |
| 48 | x: lastWinStage.x, |
| 49 | y: lastWinStage.y, |
| 50 | width: lastWinStage.width, |
| 51 | height: lastWinStage.height, |
| 52 | icon: `${__dirname}/icons/icon.png`, |
| 53 | autoHideMenuBar: true, |
| 54 | webPreferences: { |
| 55 | nodeIntegration: true, |
| 56 | // add this to keep 'remote' module avaiable. Tips: it will be removed in electron 14 |
| 57 | enableRemoteModule: true, |
| 58 | contextIsolation: false, |
| 59 | }, |
| 60 | }); |
| 61 | |
| 62 | if (lastWinStage.maximized) { |
| 63 | mainWindow.maximize(); |
| 64 | } |
| 65 | |
| 66 | winState.watchClose(mainWindow); |
| 67 | |
| 68 | // and load the index.html of the app. |
| 69 | if (APP_ENV === 'production') { |
| 70 | // mainWindow.loadFile('index.html'); |
| 71 | mainWindow.loadURL(url.format({ |
| 72 | protocol: 'file', |
| 73 | pathname: path.join(__dirname, 'index.html'), |
| 74 | query: {version: app.getVersion(), dark: nativeTheme.shouldUseDarkColors}, |
| 75 | })); |
| 76 | } else { |
| 77 | mainWindow.loadURL(url.format({ |
| 78 | protocol: 'http', |
| 79 | host: 'localhost:9988', |
| 80 | query: {version: app.getVersion(), dark: nativeTheme.shouldUseDarkColors}, |
| 81 | })); |
| 82 | } |
| 83 | |
| 84 | // Open the DevTools. |
| 85 | // mainWindow.webContents.openDevTools(); |
| 86 | |
| 87 | mainWindow.on('close', () => { |
| 88 | mainWindow.webContents.send('closingWindow'); |
| 89 | }); |
| 90 | |
| 91 | // Emitted when the window is closed. |
| 92 | mainWindow.on('closed', () => { |
| 93 | // Dereference the window object, usually you would store windows |
| 94 | // in an array if your app supports multi windows, this is the time |
| 95 | // when you should delete the corresponding element. |
| 96 | mainWindow = null; |
| 97 | }); |
| 98 | |
| 99 | // const contents = mainWindow.webContents; |