Files
client/app/preload/preload.js
T
omar c75c8f3d74
release / linux-x64 (push) Failing after 59s
ci / linux-x64 (push) Failing after 1m9s
ci / linux-arm64-cross (push) Failing after 4m15s
release / linux-arm64 (push) Successful in 4m36s
release / appimage-startup (push) Skipped
release / publish (push) Skipped
release: prepare v0.1.5 verified account-free snapshot
2026-11-02 10:50:54 +03:00

132 lines
9.9 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', {
// Every core request names its server connection (one core process per connection, see main/connections.js).
request: (connectionId, cmd, args) => ipcRenderer.invoke('core:request', connectionId, cmd, args),
// profile_get / profile_create / rename: shared by all connections, routed by main (profileRequest).
profileRequest: (cmd, args) => ipcRenderer.invoke('profile:request', cmd, args),
onProfileChanged: (callback) => subscribe('profile:changed', callback),
// Captured voice: main routes it to the selected input connection only (setInputConnection).
sendAudioFrame: (frame, whisper) => ipcRenderer.send('core:audio-frame', frame, whisper),
getWhisper: () => ipcRenderer.invoke('whisper:get'),
saveWhisperList: (list) => ipcRenderer.invoke('whisper:save-list', list),
deleteWhisperList: (listUuid) => ipcRenderer.invoke('whisper:delete-list', listUuid),
setWhisperReceiveMode: (mode) => ipcRenderer.invoke('whisper:set-receive-mode', mode),
getKeybinds: () => ipcRenderer.invoke('keybinds:get'),
setKeybinds: (profileId, bindings) => ipcRenderer.invoke('keybinds:set', profileId, bindings),
setKeybindExact: (value) => ipcRenderer.invoke('keybinds:set-exact', value),
addKeybindProfile: (name) => ipcRenderer.invoke('keybinds:profile-add', name),
renameKeybindProfile: (profileId, name) => ipcRenderer.invoke('keybinds:profile-rename', profileId, name),
activateKeybindProfile: (profileId) => ipcRenderer.invoke('keybinds:profile-activate', profileId),
deleteKeybindProfile: (profileId) => ipcRenderer.invoke('keybinds:profile-delete', profileId),
setKeybindCapture: (on) => ipcRenderer.invoke('keybinds:capture', on),
onKeybindEvent: (callback) => subscribe('keybinds:event', callback),
onKeybindStatus: (callback) => subscribe('keybinds:status', callback),
snapshotExport: (connectionId, options) => ipcRenderer.invoke('snapshots:export', connectionId, options),
snapshotOpen: (connectionId) => ipcRenderer.invoke('snapshots:open', connectionId),
snapshotApply: (connectionId, options) => ipcRenderer.invoke('snapshots:apply', connectionId, options),
snapshotCancel: (connectionId) => ipcRenderer.invoke('snapshots:cancel', connectionId),
onSnapshotProgress: (callback) => subscribe('snapshots:progress', callback),
endAudio: () => ipcRenderer.send('core:audio-end'),
onEvent: (callback) => subscribe('core:event', callback),
onAudio: (callback) => subscribe('core:audio', callback),
onCoreStatus: (callback) => subscribe('core:status', callback),
restartCore: (connectionId) => ipcRenderer.invoke('core:restart', connectionId),
listConnections: () => ipcRenderer.invoke('connections:list'),
createConnection: () => ipcRenderer.invoke('connections:create'),
closeConnection: (connectionId) => ipcRenderer.invoke('connections:close', connectionId),
setInputConnection: (connectionId) => ipcRenderer.invoke('connections:set-input', connectionId),
onConnections: (callback) => subscribe('connections:changed', callback),
listThemes: (force) => ipcRenderer.invoke('themes:list', force === true),
selectTheme: (selection) => ipcRenderer.invoke('themes:select', selection),
openThemeDirectory: (identifier) => ipcRenderer.invoke('themes:open-dir', typeof identifier === 'string' ? identifier : null),
openThemeLink: (identifier, kind) => ipcRenderer.invoke('themes:open-link', { identifier, kind }),
chatHistoryAppend: (scope, record, label) => ipcRenderer.invoke('chat-history:append', scope, record, label),
chatHistoryPage: (scope, before, count) => ipcRenderer.invoke('chat-history:page', scope, before, count),
chatHistoryList: (base) => ipcRenderer.invoke('chat-history:list', base),
chatHistorySetOpen: (scope, open, label) => ipcRenderer.invoke('chat-history:set-open', scope, open, label),
openExternalLink: (url) => ipcRenderer.invoke('link:open-external', url),
setUnreadBadge: (count, png) => ipcRenderer.invoke('app:unread-badge', count, png),
pickRecordingFolder: (title) => ipcRenderer.invoke('recording:pick-folder', title),
filesChooseDownloadDir: (connectionId) => ipcRenderer.invoke('files:choose-download-dir', connectionId),
filesChooseUpload: (connectionId) => ipcRenderer.invoke('files:choose-upload', connectionId),
filesDownload: (connectionId, options) => ipcRenderer.invoke('files:download', connectionId, options),
filesUpload: (connectionId, options) => ipcRenderer.invoke('files:upload', connectionId, options),
filesRelease: (token) => ipcRenderer.invoke('files:release', token),
filesOpenFolder: (token) => ipcRenderer.invoke('files:open-folder', token),
filesSettings: () => ipcRenderer.invoke('files:settings/get'),
filesSetSettings: (options) => ipcRenderer.invoke('files:settings/set', options),
filesChooseDefaultDir: () => ipcRenderer.invoke('files:settings/choose-default'),
filesCopyDefaultDir: () => ipcRenderer.invoke('files:settings/copy-default'),
prepareStreamPopout: (input) => ipcRenderer.invoke('stream-popout:prepare', input),
closeStreamPopout: (input) => ipcRenderer.invoke('stream-popout:close', input),
onStreamPopoutClosed: (callback) => subscribe('stream-popout:closed', callback),
onStreamPopoutReady: (callback) => subscribe('stream-popout:ready', callback),
presentStreamPopout: (input) => ipcRenderer.invoke('stream-popout:present', input),
osCapabilities: () => ipcRenderer.invoke('os:capabilities'),
getChangelog: () => ipcRenderer.invoke('about:changelog'),
getLicenses: () => ipcRenderer.invoke('about:licenses'),
getLicenseText: (id) => ipcRenderer.invoke('about:license-text', id),
badgeInfo: (uuids) => ipcRenderer.invoke('badges:info', uuids),
badgeArt: (uuid, detailed) => ipcRenderer.invoke('badges:art', uuid, detailed === true),
serverIconsList: (id) => ipcRenderer.invoke('server-icons:list', id),
serverIconsUpload: (id, authorization) => ipcRenderer.invoke('server-icons:upload', id, authorization),
serverIconsDelete: (id, authorization, ids) => ipcRenderer.invoke('server-icons:delete', id, authorization, ids),
osSetAutostart: (on) => ipcRenderer.invoke('os:set-autostart', on === true),
osApply: () => ipcRenderer.invoke('os:apply'),
osFlash: (kind) => ipcRenderer.invoke('os:flash', kind === 'poke' ? 'poke' : 'message'),
osNotify: (title, body, kind = 'private') => ipcRenderer.invoke('os:notify', String(title), String(body), kind),
privacyLinkThreat: (host) => ipcRenderer.invoke('privacy:link-threat', host),
privacyThreatStatus: () => ipcRenderer.invoke('privacy:threat-status'),
onOsLock: (callback) => subscribe('os:lock', (locked) => callback(locked === true)),
getAppInfo: () => ipcRenderer.invoke('app:info'),
getWindowState: () => ipcRenderer.invoke('window:get-state'),
onWindowState: (callback) => subscribe('window:state', callback),
getPrefs: () => ipcRenderer.invoke('prefs:get'),
setPrefs: (partial) => ipcRenderer.invoke('prefs:set', partial),
getBookmarkPasswordState: (id) => ipcRenderer.invoke('bookmarks:password-state', id),
setBookmarkPassword: (id, address, kind, value) => ipcRenderer.invoke('bookmarks:password-set', id, address, kind, value),
revealBookmarkPassword: (id, address, kind) => ipcRenderer.invoke('bookmarks:password-reveal', id, address, kind),
connectBookmark: (connectionId, id, startup = false) => ipcRenderer.invoke('bookmarks:connect', connectionId, id, startup),
getStartupBookmarks: () => ipcRenderer.invoke('bookmarks:startup'),
identityRequest: (action, args) => ipcRenderer.invoke('identity:request', action, args),
exportIdentity: (uid) => ipcRenderer.invoke('identity:export', uid),
onIdentityProgress: (callback) => subscribe('identity:progress', callback),
onIdentitiesChanged: (callback) => subscribe('identities:changed', callback),
setClientVolume: (uid, db) => ipcRenderer.invoke('client-volumes:set', uid, db),
importIdentity: () => ipcRenderer.invoke('identity:import'),
chooseAvatar: () => ipcRenderer.invoke('avatar:choose'),
getCaptureCapabilities: () => ipcRenderer.invoke('capture:capabilities'),
listCaptureSources: (options) => ipcRenderer.invoke('capture:sources', options),
selectCaptureSource: (options) => ipcRenderer.invoke('capture:select', options),
cancelCaptureSelection: () => ipcRenderer.invoke('capture:cancel'),
listAppAudio: () => ipcRenderer.invoke('appaudio:list'),
startAppAudio: (options) => ipcRenderer.invoke('appaudio:start', options),
stopAppAudio: (options) => ipcRenderer.invoke('appaudio:stop', options),
ackAppAudio: (options) => ipcRenderer.send('appaudio:ack', options),
onAppAudio: (callback) => subscribe('appaudio:event', callback),
copyText: (text) => ipcRenderer.invoke('clipboard:write', text),
openLogs: () => ipcRenderer.invoke('app:open-logs'),
fetchExternalMedia: (connectionId, url) => ipcRenderer.invoke('media:external', connectionId, 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)),
});