60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
import { app, BrowserWindow, shell } from 'electron';
|
|
import path from 'node:path';
|
|
|
|
const isDevelopment = process.env.NODE_ENV === 'development';
|
|
const devServerUrl =
|
|
process.env.VITE_DEV_SERVER_URL ?? 'http://127.0.0.1:5173';
|
|
|
|
function reportError(error: unknown) {
|
|
const message = error instanceof Error ? error.stack ?? error.message : error;
|
|
process.stderr.write(`${String(message)}\n`);
|
|
}
|
|
|
|
function createMainWindow() {
|
|
const mainWindow = new BrowserWindow({
|
|
height: 800,
|
|
minHeight: 600,
|
|
minWidth: 900,
|
|
title: 'Throne of the Bone King',
|
|
webPreferences: {
|
|
contextIsolation: true,
|
|
nodeIntegration: false,
|
|
preload: path.join(__dirname, 'preload.js'),
|
|
},
|
|
width: 1200,
|
|
});
|
|
|
|
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
|
shell.openExternal(url).catch(reportError);
|
|
return { action: 'deny' };
|
|
});
|
|
|
|
if (isDevelopment) {
|
|
mainWindow.loadURL(devServerUrl).catch(reportError);
|
|
return;
|
|
}
|
|
|
|
mainWindow
|
|
.loadFile(path.join(__dirname, '../renderer/index.html'))
|
|
.catch(reportError);
|
|
}
|
|
|
|
app
|
|
.whenReady()
|
|
.then(() => {
|
|
createMainWindow();
|
|
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
createMainWindow();
|
|
}
|
|
});
|
|
})
|
|
.catch(reportError);
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') {
|
|
app.quit();
|
|
}
|
|
});
|