41 lines
2.2 KiB
JavaScript
41 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
// Sandboxed preload: the only surface the renderer gets. No paths, no commands, no generic IPC.
|
|
const { contextBridge, ipcRenderer } = require('electron');
|
|
|
|
function subscribe(channel, callback) {
|
|
if (typeof callback !== 'function') throw new TypeError('callback must be a function');
|
|
const handler = (_event, payload) => callback(payload);
|
|
ipcRenderer.on(channel, handler);
|
|
return () => ipcRenderer.removeListener(channel, handler);
|
|
}
|
|
|
|
contextBridge.exposeInMainWorld('teamspeach', {
|
|
request: (cmd, args) => ipcRenderer.invoke('core:request', cmd, args),
|
|
sendAudioFrame: (frame) => ipcRenderer.send('core:audio-frame', frame),
|
|
endAudio: () => ipcRenderer.send('core:audio-end'),
|
|
onEvent: (callback) => subscribe('core:event', callback),
|
|
onAudio: (callback) => subscribe('core:audio', callback),
|
|
onCoreStatus: (callback) => subscribe('core:status', callback),
|
|
getCoreStatus: () => ipcRenderer.invoke('core:status'),
|
|
restartCore: () => ipcRenderer.invoke('core:restart'),
|
|
getAppInfo: () => ipcRenderer.invoke('app:info'),
|
|
getPrefs: () => ipcRenderer.invoke('prefs:get'),
|
|
setPrefs: (partial) => ipcRenderer.invoke('prefs:set', partial),
|
|
exportIdentity: () => ipcRenderer.invoke('identity:export'),
|
|
importIdentity: () => ipcRenderer.invoke('identity:import'),
|
|
copyText: (text) => ipcRenderer.invoke('clipboard:write', text),
|
|
openLogs: () => ipcRenderer.invoke('app:open-logs'),
|
|
fetchExternalMedia: (url) => ipcRenderer.invoke('media:external', url),
|
|
getVideoStatus: () => ipcRenderer.invoke('app:video-status'),
|
|
relaunch: () => ipcRenderer.invoke('app:relaunch'),
|
|
getUpdateState: () => ipcRenderer.invoke('update:get-state'),
|
|
checkForUpdates: () => ipcRenderer.invoke('update:check'),
|
|
downloadUpdate: () => ipcRenderer.invoke('update:download'),
|
|
installUpdate: (confirmInterrupt) => ipcRenderer.invoke('update:install', { confirmInterrupt: confirmInterrupt === true }),
|
|
openUpdateRelease: () => ipcRenderer.invoke('update:open-release'),
|
|
setUpdateChannel: (channel) => ipcRenderer.invoke('update:set-channel', channel),
|
|
onUpdateState: (callback) => subscribe('update:state', callback),
|
|
log: (level, message) => ipcRenderer.send('app:log', level, String(message)),
|
|
});
|