Files
Toju/electron/main.js
2025-12-28 08:23:30 +01:00

86 lines
2.0 KiB
JavaScript

const { app, BrowserWindow, ipcMain, desktopCapturer } = require('electron');
const path = require('path');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1400,
height: 900,
minWidth: 800,
minHeight: 600,
frame: false,
titleBarStyle: 'hidden',
backgroundColor: '#0a0a0f',
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js'),
webSecurity: true,
},
});
// In development, load from Angular dev server
if (process.env.NODE_ENV === 'development') {
mainWindow.loadURL('http://localhost:4200');
mainWindow.webContents.openDevTools();
} else {
// In production, load the built Angular app
// The dist folder is at the project root, not in electron folder
mainWindow.loadFile(path.join(__dirname, '..', 'dist', 'client', 'browser', 'index.html'));
}
mainWindow.on('closed', () => {
mainWindow = null;
});
}
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.on('window-minimize', () => {
mainWindow?.minimize();
});
ipcMain.on('window-maximize', () => {
if (mainWindow?.isMaximized()) {
mainWindow.unmaximize();
} else {
mainWindow?.maximize();
}
});
ipcMain.on('window-close', () => {
mainWindow?.close();
});
// IPC handler for desktop capturer (screen sharing)
ipcMain.handle('get-sources', async () => {
const sources = await desktopCapturer.getSources({
types: ['window', 'screen'],
thumbnailSize: { width: 150, height: 150 },
});
return sources.map((source) => ({
id: source.id,
name: source.name,
thumbnail: source.thumbnail.toDataURL(),
}));
});
// IPC handler for app data path
ipcMain.handle('get-app-data-path', () => {
return app.getPath('userData');
});