38 lines
963 B
JavaScript
38 lines
963 B
JavaScript
import { app, BrowserWindow } from 'electron';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const isDev = process.env.NODE_ENV !== 'production';
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
function createWindow() {
|
|
const win = new BrowserWindow({
|
|
width: 1024,
|
|
height: 768,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, 'preload.cjs'),
|
|
contextIsolation: true,
|
|
nodeIntegration: false
|
|
}
|
|
});
|
|
|
|
if (isDev) {
|
|
const devUrl = process.env.ELECTRON_START_URL || 'http://localhost:5173';
|
|
win.loadURL(devUrl);
|
|
win.webContents.openDevTools();
|
|
} else {
|
|
win.loadFile(path.join(__dirname, '..', 'dist', 'index.html'));
|
|
}
|
|
}
|
|
|
|
app.whenReady().then(createWindow);
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') app.quit();
|
|
});
|
|
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
|
});
|