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:
@@ -1,4 +1,4 @@
|
|||||||
import { app, BrowserWindow, ipcMain } from 'electron';
|
import { app, BrowserWindow, ipcMain, screen } from 'electron';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import { loadSeedConfig } from './config_loader';
|
import { loadSeedConfig } from './config_loader';
|
||||||
@@ -18,9 +18,13 @@ async function createWindow() {
|
|||||||
cachedFullConfig = await fetchFullConfig(cachedSeed);
|
cachedFullConfig = await fetchFullConfig(cachedSeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { bounds } = screen.getPrimaryDisplay();
|
||||||
|
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 1600,
|
width: bounds.width,
|
||||||
height: 900,
|
height: bounds.height,
|
||||||
|
x: bounds.x,
|
||||||
|
y: bounds.y,
|
||||||
title: 'OSIT Aether Launcher (Native)',
|
title: 'OSIT Aether Launcher (Native)',
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, '../preload/index.js'),
|
preload: path.join(__dirname, '../preload/index.js'),
|
||||||
@@ -55,15 +59,28 @@ registerShellHandlers();
|
|||||||
registerFileHandlers();
|
registerFileHandlers();
|
||||||
registerSystemHandlers();
|
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', () => {
|
app.on('ready', createWindow);
|
||||||
if (process.platform !== 'darwin') app.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on('window-all-closed', () => {
|
||||||
if (mainWindow === null) createWindow();
|
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-seed-config', async () => cachedSeed || await loadSeedConfig());
|
||||||
ipcMain.handle('get-device-config', async () => cachedFullConfig);
|
ipcMain.handle('get-device-config', async () => cachedFullConfig);
|
||||||
|
|||||||
Reference in New Issue
Block a user