// Biz Connect — technician desktop client (Electron main process). // // This is a thin shell: it loads the live Connect web UI from the server origin, so every // relative /api and /ws URL in the web app keeps working unchanged. What it adds over a // browser tab: // - native full-screen capture for "Share Screen" (setDisplayMediaRequestHandler) // - a real desktop window (no browser chrome), persisted login session // - external links open in the user's browser, not inside the app // // Server origin is configurable so the same build works against prod or a dev server. const { app, BrowserWindow, session, desktopCapturer, shell, Menu } = require('electron'); const path = require('path'); const SERVER_URL = (process.env.SERVER_URL || 'https://remote.bizgaze.com').replace(/\/+$/, ''); let win; function createWindow() { win = new BrowserWindow({ width: 1200, height: 800, minWidth: 880, minHeight: 600, title: 'Biz Connect', backgroundColor: '#0f1830', webPreferences: { preload: path.join(__dirname, 'preload.js'), contextIsolation: true, nodeIntegration: false, // Persist cookies/localStorage so the technician stays logged in between launches. partition: 'persist:bizconnect', }, }); win.loadURL(SERVER_URL + '/home'); // Open target=_blank / external links in the system browser instead of a new Electron window. win.webContents.setWindowOpenHandler(({ url }) => { if (!url.startsWith(SERVER_URL)) { shell.openExternal(url); return { action: 'deny' }; } return { action: 'allow' }; }); } // Electron requires an explicit handler for getDisplayMedia(); without it the web UI's // "Share Screen" silently fails. Default to the primary display with loopback audio. // A production build can swap this for a source-picker window. function registerDisplayMediaHandler() { session.fromPartition('persist:bizconnect').setDisplayMediaRequestHandler((request, callback) => { desktopCapturer.getSources({ types: ['screen', 'window'] }).then((sources) => { callback(sources.length ? { video: sources[0], audio: 'loopback' } : {}); }).catch(() => callback({})); }); } app.whenReady().then(() => { registerDisplayMediaHandler(); createWindow(); Menu.setApplicationMenu(null); // hide the default menu bar; the web UI is the chrome app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow(); }); }); app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit(); });