From 7199d4571956a2a889da8112fad8a6b8be754841 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Wed, 20 May 2026 17:48:09 -0400 Subject: [PATCH] feat: single instance lock; auto-size window to primary display bounds - requestSingleInstanceLock(): second launch focuses existing window and quits. - Window width/height/x/y set from screen.getPrimaryDisplay().bounds so the app fills the built-in display exactly on launch, regardless of resolution. --- src/main/index.ts | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 6a6c423..8cea37e 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,4 +1,4 @@ -import { app, BrowserWindow, ipcMain } from 'electron'; +import { app, BrowserWindow, ipcMain, screen } from 'electron'; import * as path from 'path'; import * as os from 'os'; import { loadSeedConfig } from './config_loader'; @@ -18,9 +18,13 @@ async function createWindow() { cachedFullConfig = await fetchFullConfig(cachedSeed); } + const { bounds } = screen.getPrimaryDisplay(); + mainWindow = new BrowserWindow({ - width: 1600, - height: 900, + width: bounds.width, + height: bounds.height, + x: bounds.x, + y: bounds.y, title: 'OSIT Aether Launcher (Native)', webPreferences: { preload: path.join(__dirname, '../preload/index.js'), @@ -55,15 +59,28 @@ registerShellHandlers(); registerFileHandlers(); registerSystemHandlers(); -app.on('ready', createWindow); +// Single instance lock — if another instance is already running, focus it and quit. +const gotTheLock = app.requestSingleInstanceLock(); +if (!gotTheLock) { + app.quit(); +} else { + app.on('second-instance', () => { + if (mainWindow) { + if (mainWindow.isMinimized()) mainWindow.restore(); + mainWindow.focus(); + } + }); -app.on('window-all-closed', () => { - if (process.platform !== 'darwin') app.quit(); -}); + app.on('ready', createWindow); -app.on('activate', () => { - if (mainWindow === null) createWindow(); -}); + app.on('window-all-closed', () => { + if (process.platform !== 'darwin') app.quit(); + }); + + app.on('activate', () => { + if (mainWindow === null) createWindow(); + }); +} ipcMain.handle('get-seed-config', async () => cachedSeed || await loadSeedConfig()); ipcMain.handle('get-device-config', async () => cachedFullConfig);