import { join } from 'path' import { app, BrowserWindow } from 'electron' 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, '../react-ts/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() } } 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() } })