Launch the game through the guarded lab
This commit is contained in:
1 parent
462b49b5c4
commit
6c09525834
25 files changed
+920
-23
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { join } from 'node:path';
|
||||
import { BrowserWindow, shell } from 'electron';
|
||||
import { app, BrowserWindow, Menu, shell, Tray } from 'electron';
|
||||
import { getSettings } from './config/settings-store.ts';
|
||||
|
||||
/**
|
||||
* The launcher's single window: a fixed size without the system frame, like the game's own
|
||||
@@ -13,6 +14,24 @@ const CONTENT_HEIGHT = 720;
|
||||
const BACKGROUND = '#13191b';
|
||||
|
||||
let mainWindow: BrowserWindow | null = null;
|
||||
let tray: Tray | null = null;
|
||||
let quitting = false;
|
||||
|
||||
export function beginWindowQuit(): void {
|
||||
quitting = true;
|
||||
tray?.destroy();
|
||||
tray = null;
|
||||
}
|
||||
|
||||
async function hideToTray(window: BrowserWindow): Promise<void> {
|
||||
if (!tray) {
|
||||
tray = new Tray(await app.getFileIcon(process.execPath, { size: 'small' }));
|
||||
tray.setToolTip(app.getName());
|
||||
tray.setContextMenu(Menu.buildFromTemplate([{ role: 'quit' }]));
|
||||
tray.on('click', () => showMainWindow());
|
||||
}
|
||||
if (!window.isDestroyed()) window.hide();
|
||||
}
|
||||
|
||||
export function createMainWindow(): BrowserWindow {
|
||||
const window = new BrowserWindow({
|
||||
@@ -39,6 +58,20 @@ export function createMainWindow(): BrowserWindow {
|
||||
return { action: 'deny' };
|
||||
});
|
||||
window.webContents.on('will-navigate', (event) => event.preventDefault());
|
||||
let handlingClose = false;
|
||||
window.on('close', (event) => {
|
||||
if (quitting) return;
|
||||
event.preventDefault();
|
||||
if (handlingClose) return;
|
||||
handlingClose = true;
|
||||
void getSettings().then(async (settings) => {
|
||||
if (settings.windowClose === 'tray') await hideToTray(window);
|
||||
else app.quit();
|
||||
}).catch((error: unknown) => {
|
||||
console.warn('[window] the close action failed:', error);
|
||||
app.quit();
|
||||
}).finally(() => { handlingClose = false; });
|
||||
});
|
||||
window.on('closed', () => {
|
||||
if (mainWindow === window) mainWindow = null;
|
||||
});
|
||||
@@ -54,5 +87,6 @@ export function createMainWindow(): BrowserWindow {
|
||||
export function showMainWindow(): void {
|
||||
const window = mainWindow ?? createMainWindow();
|
||||
if (window.isMinimized()) window.restore();
|
||||
if (!window.isVisible()) window.show();
|
||||
window.focus();
|
||||
}
|
||||
Reference in new issue
Block a user