diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2020-02-22 17:35:19 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2020-02-22 18:08:23 +0100 |
commit | 9eed5c04fff403ef6a7d9ad3ca1fe8628510b9a6 (patch) | |
tree | 5a4b0a7e43821a5881365f76cd40c2e4c86273dd /src/main/index.ts | |
parent | d35a68caf3987f24d85cb31cf3b327112459c7ac (diff) | |
download | rpgedit-9eed5c04fff403ef6a7d9ad3ca1fe8628510b9a6.tar rpgedit-9eed5c04fff403ef6a7d9ad3ca1fe8628510b9a6.zip |
Switch from electron-webpack to electron-forge
Diffstat (limited to 'src/main/index.ts')
-rw-r--r-- | src/main/index.ts | 44 |
1 files changed, 12 insertions, 32 deletions
diff --git a/src/main/index.ts b/src/main/index.ts index 3a94ae5..be494a4 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,60 +1,40 @@ import { app, BrowserWindow } from 'electron'; -import * as path from 'path'; -import { format as formatUrl } from 'url'; +declare const MAIN_WINDOW_WEBPACK_ENTRY: string; const isDevelopment = process.env.NODE_ENV !== 'production'; -// global reference to mainWindow (necessary to prevent window from being garbage collected) -let mainWindow: BrowserWindow | null = null; +app.allowRendererProcessReuse = true; -function getIndexURL(): string { - if (isDevelopment) { - return `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`; - } - - return formatUrl({ - pathname: path.join(__dirname, 'index.html'), - protocol: 'file', - slashes: true, - }); -} - -function createMainWindow(): BrowserWindow { +function createWindow(): void { const window = new BrowserWindow({ webPreferences: { nodeIntegration: true } }); + window.loadURL(MAIN_WINDOW_WEBPACK_ENTRY); + if (isDevelopment) { window.webContents.openDevTools(); } - window.loadURL(getIndexURL()); - - window.on('closed', () => { - mainWindow = null; - }); - window.webContents.on('devtools-opened', () => { window.webContents.focus(); }); - - return window; } // quit application when all windows are closed app.on('window-all-closed', () => { - // on macOS it is common for applications to stay open until the user explicitly quits + // On macOS it is common for applications and their menu bar + // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit(); } }); app.on('activate', () => { - // on macOS it is common to re-create a window even after all windows have been closed - if (!mainWindow) { - mainWindow = createMainWindow(); + // On macOS it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (BrowserWindow.getAllWindows().length === 0) { + createWindow(); } }); // create main BrowserWindow when electron is ready -app.on('ready', () => { - mainWindow = createMainWindow(); -}); +app.on('ready', createWindow); |