81 lines
1.9 KiB
JavaScript
81 lines
1.9 KiB
JavaScript
const { app, BrowserWindow, ipcMain } = require('electron');
|
|
const path = require('path');
|
|
const isDev = process.env.NODE_ENV === 'development';
|
|
const port = process.env.PORT || 3000;
|
|
const fs = require('fs');
|
|
const serve = require('electron-serve');
|
|
|
|
// Setup for production with static files
|
|
const loadURL = process.env.NODE_ENV !== 'development'
|
|
? serve({ directory: path.join(__dirname, '../.next') })
|
|
: null;
|
|
|
|
// Keep a global reference of the window object to prevent garbage collection
|
|
let mainWindow;
|
|
|
|
function createWindow() {
|
|
mainWindow = new BrowserWindow({
|
|
width: 1200,
|
|
height: 800,
|
|
webPreferences: {
|
|
nodeIntegration: false,
|
|
contextIsolation: true,
|
|
preload: path.join(__dirname, 'preload.js')
|
|
},
|
|
icon: path.join(__dirname, '../public/favicon.ico')
|
|
});
|
|
|
|
// Load the app
|
|
if (isDev) {
|
|
// In development, load from local server
|
|
mainWindow.loadURL(`http://localhost:${port}`);
|
|
mainWindow.webContents.openDevTools();
|
|
} else {
|
|
// In production, load from static files
|
|
loadURL(mainWindow);
|
|
}
|
|
|
|
mainWindow.on('closed', () => {
|
|
mainWindow = null;
|
|
});
|
|
|
|
// Handle window maximize/unmaximize
|
|
mainWindow.on('maximize', () => {
|
|
mainWindow.webContents.send('window-maximized');
|
|
});
|
|
|
|
mainWindow.on('unmaximize', () => {
|
|
mainWindow.webContents.send('window-unmaximized');
|
|
});
|
|
}
|
|
|
|
app.whenReady().then(createWindow);
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') {
|
|
app.quit();
|
|
}
|
|
});
|
|
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
createWindow();
|
|
}
|
|
});
|
|
|
|
// IPC handlers for window controls
|
|
ipcMain.handle('minimize-window', () => {
|
|
mainWindow.minimize();
|
|
});
|
|
|
|
ipcMain.handle('maximize-window', () => {
|
|
if (mainWindow.isMaximized()) {
|
|
mainWindow.unmaximize();
|
|
} else {
|
|
mainWindow.maximize();
|
|
}
|
|
});
|
|
|
|
ipcMain.handle('close-window', () => {
|
|
mainWindow.close();
|
|
});
|