Open-Generative-AI/electron/main.js
Anil Matcha 6e0b18cd22 Add Electron desktop app with macOS DMG and Windows installer support
- Add electron/main.js as the Electron main process
- Configure electron-builder for macOS (x64 + arm64 DMG) and Windows (x64 + arm64 NSIS installer)
- Add build scripts: electron:build (mac), electron:build:win (windows)
- Set vite base to './' for file:// protocol compatibility in Electron
2026-03-18 11:45:23 +05:30

59 lines
1.4 KiB
JavaScript

import { app, BrowserWindow, shell } from 'electron';
import { fileURLToPath } from 'url';
import path from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1440,
height: 900,
minWidth: 1024,
minHeight: 640,
webPreferences: {
webSecurity: false, // Allow file:// origin to call external APIs
contextIsolation: true,
nodeIntegration: false,
},
titleBarStyle: 'hiddenInset',
backgroundColor: '#0d0d0d',
show: false,
title: 'Open Higgsfield AI',
});
const indexPath = path.join(__dirname, '../dist/index.html');
mainWindow.loadFile(indexPath);
// Open external links in the system browser
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: 'deny' };
});
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
mainWindow.on('closed', () => {
mainWindow = null;
});
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});