Files
5chan/electron/preload.mjs
T

25 lines
1.1 KiB
JavaScript
Raw Normal View History

2025-05-22 13:15:40 +02:00
import { contextBridge, ipcRenderer } from 'electron';
2023-04-24 19:42:49 +00:00
// dev uses http://localhost, prod uses file://...index.html
2023-12-16 16:49:26 +00:00
const isDev = window.location.protocol === 'http:';
2023-04-24 19:42:49 +00:00
const defaultPlebbitOptions = {
2023-12-16 16:49:26 +00:00
plebbitRpcClientsOptions: ['ws://localhost:9138'],
2025-05-22 13:15:40 +02:00
httpRoutersOptions: ['https://peers.pleb.bot', 'https://routing.lol', 'https://peers.forumindex.com', 'https://peers.plebpubsub.xyz'],
2023-12-16 16:49:26 +00:00
};
2023-04-24 19:42:49 +00:00
2024-10-11 17:24:35 +02:00
contextBridge.exposeInMainWorld('isElectron', true);
2023-12-16 16:49:26 +00:00
contextBridge.exposeInMainWorld('defaultPlebbitOptions', defaultPlebbitOptions);
contextBridge.exposeInMainWorld('defaultMediaIpfsGatewayUrl', 'http://localhost:6473');
2023-04-24 19:42:49 +00:00
// receive plebbit rpc auth key from main
ipcRenderer.on('plebbit-rpc-auth-key', (event, plebbitRpcAuthKey) => contextBridge.exposeInMainWorld('plebbitRpcAuthKey', plebbitRpcAuthKey));
ipcRenderer.send('get-plebbit-rpc-auth-key');
2025-05-22 17:42:04 +02:00
contextBridge.exposeInMainWorld('electronApi', {
isElectron: true,
copyToClipboard: (text) => ipcRenderer.invoke('copy-to-clipboard', text),
getPlatform: () => ipcRenderer.invoke('get-platform'),
automateUploadMedia: (options) => ipcRenderer.invoke('automate-upload-media', options),
});