Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hadron-ipc

Package Overview
Dependencies
Maintainers
34
Versions
495
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hadron-ipc - npm Package Compare versions

Comparing version 0.0.0-next-514d0059aae41f2aa9cb0bbe6e204dacbac3d73f to 0.0.0-next-516eced55d345dc219ea74b01bd1f493443fc9b6

1

dist/index.js

@@ -19,2 +19,3 @@ "use strict";

if (process.env.NODE_ENV !== 'test') {
// eslint-disable-next-line no-console
console.warn('Unsupported environment for hadron-ipc');

@@ -21,0 +22,0 @@ }

import type { IpcMain, IpcMainEvent } from 'electron';
type ResponseHandler = (event: IpcMainEvent, ...args: any[]) => any;
export declare function respondTo(ipcMain: Pick<IpcMain, 'on'> | undefined, methodName: string | Record<string, ResponseHandler>, handler?: ResponseHandler): void;
/**
* Broadcast an event to all the renderer processes
*/
export declare function broadcast(channel: string, ...args: any[]): void;
/**
* Broadcast an event to currently focused window
*/
export declare function broadcastFocused(channel: string, ...args: any[]): void;
/**
* Remove listener for a channel
*/
export declare function remove(ipcMain: Pick<IpcMain, 'removeListener'> | undefined, channel: string, listener: (...args: unknown[]) => void): void;
declare const ipcMain: (Electron.IpcMain & {
/**
* Broadcast an event to all the renderer processes
*/
broadcast: typeof broadcast;
/**
* Broadcast an event to currently focused window
*/
broadcastFocused: typeof broadcastFocused;
/**
* Set up a listener for a call from the renderer process dispatched with
* a `ipcRenderer.call` or `ipcRenderer.callQuiet` method
*/
respondTo: (methodName: string | Record<string, ResponseHandler>, handler?: ResponseHandler | undefined) => void;
/**
* Remove event listener from ipcMain
*/
remove: (channel: string, listener: (...args: unknown[]) => void) => void;
/**
* Helper method to expose multiple methods from the main process through
* `ipcMain.handle` with stricter types, better error handling, and
* support for AbortController
*
* @param serviceName Identifier used to locate the service methods from
* the renderer process
* @param obj Object which methods will be exposed to the renderer
* process
* @param methodNames List of the method names that will get exposed
*/
createHandle: <T>(serviceName: string, obj: T, methodNames: Extract<{ [k in keyof T]: T[k] extends (options: any) => Promise<any> ? k : never; }[keyof T], string>[]) => void;
}) | undefined;
/**
* Exported for testing purposes
* @internal
*/
export declare const ControllerMap: Map<string, AbortController>;

@@ -15,0 +52,0 @@ export declare function setupSignalHandler(_ipcMain?: Pick<IpcMain, 'handle'> | undefined, forceSetup?: boolean): void;

@@ -62,3 +62,7 @@ "use strict";

exports.respondTo = respondTo;
/**
* Broadcast an event to all the renderer processes
*/
function broadcast(channel, ...args) {
// We might not be in electron environment
electron_1.default.BrowserWindow?.getAllWindows().forEach((browserWindow) => {

@@ -69,6 +73,13 @@ browserWindow.webContents?.send(channel, ...args);

exports.broadcast = broadcast;
/**
* Broadcast an event to currently focused window
*/
function broadcastFocused(channel, ...args) {
// We might not be in electron environment
electron_1.default.BrowserWindow?.getFocusedWindow()?.webContents?.send(channel, ...args);
}
exports.broadcastFocused = broadcastFocused;
/**
* Remove listener for a channel
*/
function remove(ipcMain, channel, listener) {

@@ -80,6 +91,30 @@ ipcMain?.removeListener(channel, listener);

? Object.assign(electron_1.default.ipcMain, {
/**
* Broadcast an event to all the renderer processes
*/
broadcast,
/**
* Broadcast an event to currently focused window
*/
broadcastFocused,
/**
* Set up a listener for a call from the renderer process dispatched with
* a `ipcRenderer.call` or `ipcRenderer.callQuiet` method
*/
respondTo: respondTo.bind(null, electron_1.default.ipcMain),
/**
* Remove event listener from ipcMain
*/
remove: remove.bind(null, electron_1.default.ipcMain),
/**
* Helper method to expose multiple methods from the main process through
* `ipcMain.handle` with stricter types, better error handling, and
* support for AbortController
*
* @param serviceName Identifier used to locate the service methods from
* the renderer process
* @param obj Object which methods will be exposed to the renderer
* process
* @param methodNames List of the method names that will get exposed
*/
createHandle: (serviceName, obj, methodNames) => {

@@ -90,2 +125,6 @@ return ipcHandle(ipcMain, serviceName, obj, methodNames);

: undefined;
/**
* Exported for testing purposes
* @internal
*/
exports.ControllerMap = new Map();

@@ -92,0 +131,0 @@ let setup = false;

import type { IpcRenderer } from 'electron';
export declare function call(ipcRenderer: Pick<IpcRenderer, 'on' | 'removeAllListeners' | 'send'> | undefined, debug: (...args: unknown[]) => void, methodName: string, ...args: any[]): Promise<any>;
declare const ipcRenderer: (Electron.IpcRenderer & {
/**
* Call a method in the main process set up with `ipcMain.respondTo`
* helper
*/
call: (methodName: string, ...args: any[]) => Promise<any>;
/**
* Same as `ipcRenderer.call`, but doesn't print any debug information
* when called (`debug` is no-op)
*/
callQuiet: (methodName: string, ...args: any[]) => Promise<any>;
/**
* Helper method to create a caller for the method in the main process set
* up with `ipcMain.createHandler` method
*
* @param serviceName Identifier used to locate the service methods in the
* main process
* @param methodNames List of the method names that will get exposed
*/
createInvoke: <T, K extends Extract<{ [k in keyof T]: T[k] extends (options: any) => Promise<any> ? k : never; }[keyof T], string>>(serviceName: string, methodNames: K[]) => Pick<T, K>;

@@ -7,0 +23,0 @@ }) | undefined;

@@ -35,5 +35,22 @@ "use strict";

? Object.assign(electron_1.default.ipcRenderer, {
/**
* Call a method in the main process set up with `ipcMain.respondTo`
* helper
*/
call: call.bind(null, electron_1.default.ipcRenderer, debug),
/**
* Same as `ipcRenderer.call`, but doesn't print any debug information
* when called (`debug` is no-op)
*/
callQuiet: call.bind(null, electron_1.default.ipcRenderer, () => {
// noop for a quiet call
}),
/**
* Helper method to create a caller for the method in the main process set
* up with `ipcMain.createHandler` method
*
* @param serviceName Identifier used to locate the service methods in the
* main process
* @param methodNames List of the method names that will get exposed
*/
createInvoke: (serviceName, methodNames) => {

@@ -56,2 +73,5 @@ return ipcInvoke(ipcRenderer, serviceName, methodNames);

};
// If signal is already aborted, make sure that handler will see it
// when it runs, otherwise just set up abort listener to communicate
// this to main process
if (signal?.aborted) {

@@ -66,2 +86,4 @@ await onAbort();

const res = await ipcRenderer?.invoke(`${serviceName}.${name}`, {
// We replace this with a matched signal on the other side, this
// is mostly for testing / debugging purposes
signal: signalId,

@@ -68,0 +90,0 @@ ...rest,

@@ -12,2 +12,4 @@ "use strict";

try {
// If we can't serialize something, it will mess up with the error we
// get on another side, ignore those properties
v8_1.default.serialize(o[p]);

@@ -24,5 +26,11 @@ return [p, o[p]];

}
// We are serializing errors to get a better error shape on the other end, ipc
// will only preserve message from the original error. See
// https://github.com/electron/electron/issues/24427
function serializeErrorForIpc(err) {
return {
$$error: {
// We serialize all the own properties as properties for the Error and then
// cherry-pick name, message and stack, since those are properties that we
// want to have even if they are not own props.
...pickSerializeableProperties(err),

@@ -29,0 +37,0 @@ name: err.name,

14

package.json
{
"name": "hadron-ipc",
"description": "Simplified IPC for electron apps.",
"version": "0.0.0-next-514d0059aae41f2aa9cb0bbe6e204dacbac3d73f",
"version": "0.0.0-next-516eced55d345dc219ea74b01bd1f493443fc9b6",
"author": {

@@ -53,6 +53,6 @@ "name": "MongoDB Inc",

"devDependencies": {
"@mongodb-js/eslint-config-compass": "0.0.0-next-514d0059aae41f2aa9cb0bbe6e204dacbac3d73f",
"@mongodb-js/mocha-config-compass": "0.0.0-next-514d0059aae41f2aa9cb0bbe6e204dacbac3d73f",
"@mongodb-js/prettier-config-compass": "0.0.0-next-514d0059aae41f2aa9cb0bbe6e204dacbac3d73f",
"@mongodb-js/tsconfig-compass": "0.0.0-next-514d0059aae41f2aa9cb0bbe6e204dacbac3d73f",
"@mongodb-js/eslint-config-compass": "0.0.0-next-516eced55d345dc219ea74b01bd1f493443fc9b6",
"@mongodb-js/mocha-config-compass": "0.0.0-next-516eced55d345dc219ea74b01bd1f493443fc9b6",
"@mongodb-js/prettier-config-compass": "0.0.0-next-516eced55d345dc219ea74b01bd1f493443fc9b6",
"@mongodb-js/tsconfig-compass": "0.0.0-next-516eced55d345dc219ea74b01bd1f493443fc9b6",
"@types/chai": "^4.2.21",

@@ -73,6 +73,6 @@ "@types/is-electron-renderer": "^2.0.1",

"debug": "^4.3.4",
"electron": "^29.4.2",
"electron": "^30.5.1",
"is-electron-renderer": "^2.0.1"
},
"gitHead": "514d0059aae41f2aa9cb0bbe6e204dacbac3d73f"
"gitHead": "516eced55d345dc219ea74b01bd1f493443fc9b6"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc