44 lines
1003 B
TypeScript
44 lines
1003 B
TypeScript
import { app, BrowserWindow } from 'electron';
|
|
import * as path from 'path';
|
|
import { setupIpcHandlers } from './ipc-handlers';
|
|
|
|
let mainWindow: BrowserWindow | null = null;
|
|
|
|
function createWindow(): BrowserWindow {
|
|
mainWindow = new BrowserWindow({
|
|
width: 1200,
|
|
height: 800,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, '../preload/preload.js'),
|
|
contextIsolation: true,
|
|
nodeIntegration: false
|
|
}
|
|
});
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
mainWindow.loadURL('http://localhost:5173');
|
|
mainWindow.webContents.openDevTools();
|
|
} else {
|
|
mainWindow.loadFile(path.join(__dirname, '../renderer/index.html'));
|
|
}
|
|
|
|
setupIpcHandlers(mainWindow);
|
|
|
|
return mainWindow;
|
|
}
|
|
|
|
app.whenReady().then(async () => {
|
|
createWindow();
|
|
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
createWindow();
|
|
}
|
|
});
|
|
});
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') {
|
|
app.quit();
|
|
}
|
|
}); |