miru/electron/src/preload/preload.js
ThaUnknown d47aa0cd23 wip: abandoned as capacitor doesn't support transfering messagechannels which are required for callbacks
this is doable by exposing on both ends, but that's too much work for now
2024-02-10 22:11:21 +01:00

22 lines
702 B
JavaScript

import { ipcRenderer } from 'electron'
const mainChannel = new MessageChannel()
globalThis.Native = mainChannel.port1
ipcRenderer.postMessage('mainPort', null, [mainChannel.port2])
const d = mainChannel.port1.postMessage.bind(mainChannel.port1)
mainChannel.port1.postMessage = (...args) => {
if (args[0]?.argumentList) {
for (const arg of args[0].argumentList) {
if (arg.type === 'HANDLER' && arg.name === 'proxy') delete arg.value
}
}
d(...args)
}
const torrentChannel = new MessageChannel()
globalThis.Torrent = torrentChannel.port1
ipcRenderer.postMessage('torrentPort', null, [torrentChannel.port2])
globalThis.version = {
arch: process.arch,
platform: process.platform
}