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.
This commit is contained in:
Scott Idem
2026-05-20 17:48:09 -04:00
parent 48e24af84e
commit 7199d45719

View File

@@ -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);