UNPKG

@minimaltech/electron-infra

Version:

Minimal Technology ElectronJS Infrastructure

52 lines 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildBridge = void 0; const electron_1 = require("electron"); const performance_utilities_1 = require("./utilities/performance.utilities"); // --------------------------------------------------------------------- const system = { performance: () => (0, performance_utilities_1.hrTimeToPerformance)(), }; // --------------------------------------------------------------------- const preference = {}; // --------------------------------------------------------------------- const ipc = { send: (opts) => { return electron_1.ipcRenderer.send(opts.channel, opts.payload); }, invoke: (opts) => { return electron_1.ipcRenderer.invoke(opts.channel, opts.payload); }, on: (opts) => { return electron_1.ipcRenderer.on(opts.channel, opts.listener); }, once: (opts) => { return electron_1.ipcRenderer.on(opts.channel, opts.listener); }, off: (opts) => { const { channel, listener } = opts; if (!listener) { return electron_1.ipcRenderer.removeAllListeners(channel); } return electron_1.ipcRenderer.off(channel, listener); }, offAll: (opts) => { return electron_1.ipcRenderer.removeAllListeners(opts.channel); }, }; // --------------------------------------------------------------------- const buildBridge = (opts) => { const { apiKey, extraScopes = {} } = opts; const scopes = Object.keys(extraScopes); if (scopes.includes('system') || scopes.includes('preference') || scopes.includes('ipc')) { throw new Error('[buildBridge] Invalid extra scope name! extra scope cannot be [system | preference | ipc]'); } return { apiKey: apiKey, routes: Object.assign({ system, preference, ipc }, extraScopes), }; }; exports.buildBridge = buildBridge; //# sourceMappingURL=bridge.js.map