Files
Alta-Proxy-Tool/preload.js
T

29 lines
1.4 KiB
JavaScript

'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, username) => ipcRenderer.invoke('launch-proxy', deviceId, username),
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,
}));