()
| 442 | } |
| 443 | |
| 444 | function createMainWindow(): BrowserWindow { |
| 445 | if (!state.preferences) { throw new Error('Preferences must be set before you can open a window.'); } |
| 446 | if (!state.config) { throw new Error('Configs must be set before you can open a window.'); } |
| 447 | const mw = state.preferences.mainWindow; |
| 448 | // Create the browser window. |
| 449 | let width: number = mw.width ? mw.width : 1000; |
| 450 | let height: number = mw.height ? mw.height : 650; |
| 451 | if (mw.width && mw.height && !state.config.useCustomTitlebar) { |
| 452 | width += 8; // Add the width of the window-grab-things, |
| 453 | height += 8; // they are 4 pixels wide each (at least for me @TBubba) |
| 454 | } |
| 455 | const window = new BrowserWindow({ |
| 456 | title: APP_TITLE, |
| 457 | x: mw.x, |
| 458 | y: mw.y, |
| 459 | width: width, |
| 460 | height: height, |
| 461 | frame: !state.config.useCustomTitlebar, |
| 462 | icon: path.join(__dirname, '../window/images/icon.png'), |
| 463 | webPreferences: { |
| 464 | preload: path.resolve(__dirname, './MainWindowPreload.js'), |
| 465 | nodeIntegration: true, |
| 466 | contextIsolation: false |
| 467 | }, |
| 468 | }); |
| 469 | remoteMain.enable(window.webContents); |
| 470 | // Enable crash reporter |
| 471 | ipcMain.on(WindowIPC.MAIN_OUTPUT, () => { |
| 472 | window.webContents.send(WindowIPC.MAIN_OUTPUT, state.output); |
| 473 | }); |
| 474 | // Add protocol report func |
| 475 | ipcMain.on(WindowIPC.PROTOCOL, () => { |
| 476 | if (init.protocol) { |
| 477 | window.webContents.send(WindowIPC.PROTOCOL, init.protocol); |
| 478 | } |
| 479 | }); |
| 480 | // Remove the menu bar |
| 481 | window.setMenu(null); |
| 482 | // and load the index.html of the app. |
| 483 | window.loadFile(path.join(__dirname, '../window/index.html')); |
| 484 | // Open the DevTools. Don't open if using a remote debugger (like vscode) |
| 485 | if (Util.isDev && !process.env.REMOTE_DEBUG) { |
| 486 | window.webContents.openDevTools(); |
| 487 | } |
| 488 | // Maximize window |
| 489 | if (mw.maximized) { |
| 490 | window.maximize(); |
| 491 | } |
| 492 | // Relay window's maximize/unmaximize events to the renderer (as a single event with a flag) |
| 493 | window.on('maximize', (event: BrowserWindowEvent) => { |
| 494 | event.sender.send(WindowIPC.WINDOW_MAXIMIZE, true); |
| 495 | }); |
| 496 | window.on('unmaximize', (event: BrowserWindowEvent) => { |
| 497 | event.sender.send(WindowIPC.WINDOW_MAXIMIZE, false); |
| 498 | }); |
| 499 | // Replay window's move event to the renderer |
| 500 | window.on('move', () => { |
| 501 | if (!window) { throw new Error(); } |
no test coverage detected