import os from 'os' import { join } from 'path' import { app, BrowserWindow } from 'electron' import './samples/electron-store' const isWin7 = os.release().startsWith('6.1') if (isWin7) app.disableHardwareAcceleration() if (!app.requestSingleInstanceLock()) { app.quit() process.exit(0) } let win: BrowserWindow | null = null async function mainWin() { win = new BrowserWindow({ title: 'Main window', webPreferences: { preload: join(__dirname, '../preload/index.cjs') }, }) if (app.isPackaged) { win.loadFile(join(__dirname, '../renderer/index.html')) } else { const pkg = await import('../../package.json') const url = `http://${pkg.env.HOST || '127.0.0.1'}:${pkg.env.PORT}` win.loadURL(url) win.maximize() win.webContents.openDevTools() } // Test active push message to Renderer-process. win.webContents.on('did-finish-load', () => { win?.webContents.send('main-process-message', (new Date).toLocaleString()) }) } app.whenReady().then(mainWin) app.on('window-all-closed', () => { win = null if (process.platform !== 'darwin') { app.quit() } }) app.on('second-instance', () => { if (win) { // Someone tried to run a second instance, we should focus our window. if (win.isMinimized()) win.restore() win.focus() } })