const { app, BrowserWindow, Menu, Tray, ipcMain, nativeImage } = require('electron'); const path = require('path'); const url = require('url'); let mainWindow; let tray = null; function createWindow() { mainWindow = new BrowserWindow({ width: 1200, height: 800, minWidth: 900, minHeight: 600, icon: path.join(__dirname, 'assets/icon.png'), webPreferences: { nodeIntegration: true, contextIsolation: false, enableRemoteModule: true }, frame: false, titleBarStyle: 'hiddenInset', backgroundColor: '#0f172a', show: false }); // Load the app const startUrl = process.env.ELECTRON_START_URL || url.format({ pathname: path.join(__dirname, 'index.html'), protocol: 'file:', slashes: true }); mainWindow.loadURL(startUrl); // Show window when ready mainWindow.once('ready-to-show', () => { mainWindow.show(); // Uncomment for dev tools // mainWindow.webContents.openDevTools(); }); mainWindow.on('closed', () => { mainWindow = null; }); // Create system tray createTray(); // Create application menu createMenu(); } function createTray() { const iconPath = path.join(__dirname, 'assets/tray-icon.png'); const trayIcon = nativeImage.createFromPath(iconPath); tray = new Tray(trayIcon.resize({ width: 16, height: 16 })); const contextMenu = Menu.buildFromTemplate([ { label: 'Open SpotSync', click: () => mainWindow.show() }, { label: 'Pause Engine', type: 'checkbox', checked: false }, { type: 'separator' }, { label: 'Quit', click: () => app.quit() } ]); tray.setToolTip('SpotSync Alpha - Trading Replication Engine'); tray.setContextMenu(contextMenu); tray.on('click', () => { if (mainWindow.isVisible()) { mainWindow.hide(); } else { mainWindow.show(); } }); } function createMenu() { const template = [ { label: 'File', submenu: [ { label: 'New Follower...', accelerator: 'CmdOrCtrl+N' }, { type: 'separator' }, { label: 'Export Logs...' }, { type: 'separator' }, { label: 'Quit', accelerator: 'CmdOrCtrl+Q', click: () => app.quit() } ] }, { label: 'Edit', submenu: [ { label: 'Undo', accelerator: 'CmdOrCtrl+Z', role: 'undo' }, { label: 'Redo', accelerator: 'Shift+CmdOrCtrl+Z', role: 'redo' }, { type: 'separator' }, { label: 'Cut', accelerator: 'CmdOrCtrl+X', role: 'cut' }, { label: 'Copy', accelerator: 'CmdOrCtrl+C', role: 'copy' }, { label: 'Paste', accelerator: 'CmdOrCtrl+V', role: 'paste' }, { label: 'Select All', accelerator: 'CmdOrCtrl+A', role: 'selectAll' } ] }, { label: 'View', submenu: [ { label: 'Reload', accelerator: 'CmdOrCtrl+R', click: () => mainWindow.reload() }, { label: 'Toggle Developer Tools', accelerator: 'F12', click: () => mainWindow.webContents.toggleDevTools() }, { type: 'separator' }, { label: 'Zoom In', accelerator: 'CmdOrCtrl+=', role: 'zoomIn' }, { label: 'Zoom Out', accelerator: 'CmdOrCtrl+-', role: 'zoomOut' }, { label: 'Reset Zoom', accelerator: 'CmdOrCtrl+0', role: 'resetZoom' } ] }, { label: 'Engine', submenu: [ { label: 'Start Engine', accelerator: 'CmdOrCtrl+E', enabled: true }, { label: 'Pause Engine', accelerator: 'CmdOrCtrl+P', enabled: true }, { label: 'Emergency Stop', accelerator: 'CmdOrCtrl+Shift+S' }, { type: 'separator' }, { label: 'Run Diagnostics', accelerator: 'CmdOrCtrl+D' } ] }, { label: 'Window', submenu: [ { label: 'Minimize', accelerator: 'CmdOrCtrl+M', role: 'minimize' }, { label: 'Zoom', role: 'zoom' }, { type: 'separator' }, { label: 'Always on Top', type: 'checkbox', checked: false, click: (item) => mainWindow.setAlwaysOnTop(item.checked) } ] }, { label: 'Help', submenu: [ { label: 'Documentation', click: () => require('electron').shell.openExternal('https://github.com/public-apis/public-apis') }, { label: 'Report Issue', click: () => require('electron').shell.openExternal('https://github.com/') }, { type: 'separator' }, { label: 'About SpotSync Alpha...' } ] } ]; const menu = Menu.buildFromTemplate(template); Menu.setApplicationMenu(menu); } // IPC handlers for window controls ipcMain.on('window-minimize', () => { if (mainWindow) mainWindow.minimize(); }); ipcMain.on('window-maximize', () => { if (mainWindow) { if (mainWindow.isMaximized()) { mainWindow.unmaximize(); } else { mainWindow.maximize(); } } }); ipcMain.on('window-close', () => { if (mainWindow) mainWindow.close(); }); ipcMain.on('window-hide', () => { if (mainWindow) mainWindow.hide(); }); // App lifecycle app.whenReady().then(createWindow); app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); app.on('activate', () => { if (mainWindow === null) { createWindow(); } });