'use strict'; const { contextBridge, ipcRenderer } = require('electron'); function onConnectionStateChanged(callback) { if (typeof callback !== 'function') return () => {}; const listener = (_event, state) => callback(state); ipcRenderer.on('connection-state-changed', listener); return () => ipcRenderer.removeListener('connection-state-changed', listener); } contextBridge.exposeInMainWorld('electronAPI', Object.freeze({ getDevices: () => ipcRenderer.invoke('get-devices'), getDeviceSites: () => ipcRenderer.invoke('get-device-sites'), getDeviceGroups: () => ipcRenderer.invoke('get-device-groups'), getDeviceHierarchy: () => ipcRenderer.invoke('get-device-hierarchy'), getAuthInfo: () => ipcRenderer.invoke('get-auth-info'), launchProxy: (deviceId) => ipcRenderer.invoke('launch-proxy', deviceId), stopProxy: (key) => ipcRenderer.invoke('stop-proxy', key), disconnect: () => ipcRenderer.invoke('disconnect'), getConnectionState: () => ipcRenderer.invoke('get-connection-state'), checkForUpdates: () => ipcRenderer.invoke('check-for-updates'), openFixedReleasesPage: () => ipcRenderer.invoke('open-fixed-releases-page'), rotatePairing: () => ipcRenderer.invoke('rotate-pairing'), revokePairing: () => ipcRenderer.invoke('revoke-pairing'), getPairingStatus: () => ipcRenderer.invoke('get-pairing-status'), onConnectionStateChanged, }));