Files
MrTerm/src/preload.js
T

39 lines
1.2 KiB
JavaScript

const { contextBridge, ipcRenderer } = require('electron');
async function call(channel, ...args) {
const r = await ipcRenderer.invoke(channel, ...args);
if (!r.ok) throw new Error(r.error);
return r.value;
}
function on(channel, fn) {
const h = (_e, ...a) => fn(...a);
ipcRenderer.on(channel, h);
return () => ipcRenderer.removeListener(channel, h);
}
contextBridge.exposeInMainWorld('api', {
platform: process.platform,
call,
on,
win: {
min: () => ipcRenderer.send('win:min'),
max: () => ipcRenderer.send('win:max'),
close: () => ipcRenderer.send('win:close'),
},
ssh: {
write: (id, d) => ipcRenderer.send('ssh:write', id, d),
resize: (id, c, r) => ipcRenderer.send('ssh:resize', id, c, r),
close: (id) => ipcRenderer.send('ssh:close', id),
},
rdp: {
bounds: (id, b) => ipcRenderer.send('rdp:bounds', id, b),
show: (id) => ipcRenderer.send('rdp:show', id),
hide: (id) => ipcRenderer.send('rdp:hide', id),
focus: (id) => ipcRenderer.send('rdp:focus', id),
close: (id) => ipcRenderer.send('rdp:close', id),
},
replySecret: (reqId, v) => ipcRenderer.send('secret:reply', reqId, v),
pairReply: (reqId, ok) => ipcRenderer.send('sync:pairReply', reqId, ok),
});