tiny-electron-essentials
Version:
A lightweight and modular utility library for Electron apps, offering simplified window management, tray support, IPC channels, and custom frameless window styling.
89 lines • 3.43 kB
text/typescript
export default TinyIpcResponder;
export type SendData = import("../preload/TinyIpcRequestManager.mjs").SendData;
export type SendResult = import("../preload/TinyIpcRequestManager.mjs").SendResult;
/**
* A callback function used to respond to an IPC request.
*/
export type IPCRespondCallback = (response: unknown, error?: Error | null) => void;
/**
* A handler function used to process incoming IPC requests on the main process.
*/
export type IPCRequestHandler = (event: Electron.IpcMainEvent, payload: any, respond: IPCRespondCallback) => void;
/**
* @typedef {import('../preload/TinyIpcRequestManager.mjs').SendData} SendData
*/
/**
* @typedef {import('../preload/TinyIpcRequestManager.mjs').SendResult} SendResult
*/
/**
* @typedef {(response: unknown, error?: Error | null) => void} IPCRespondCallback
* A callback function used to respond to an IPC request.
*/
/**
* @typedef {(event: Electron.IpcMainEvent, payload: any, respond: IPCRespondCallback) => void} IPCRequestHandler
* A handler function used to process incoming IPC requests on the main process.
*/
/**
* Manages IPC responses for incoming requests in Electron.
*
* This class listens for IPC requests and provides handlers to respond
* with data or errors. It enables structured, reliable communication
* from the main process or between renderer processes.
*
* Typically used to expose APIs from the main process to renderer processes
* with clear request/response patterns.
*
* @class
*/
declare class TinyIpcResponder {
/**
* @param {string} [responseChannel='ipc-response'] - Custom response channel name.
* @throws {TypeError} If `responseChannel` is not a valid non-empty string.
*/
constructor(responseChannel?: string);
/**
* Returns the channel name used to listen for responses.
* @returns {string}
*/
getResponseChannel(): string;
/**
* Register a channel listener that can use requestId to respond.
*
* @param {string} channel - Channel name for listening
* @param {IPCRequestHandler} handler
* @throws {Error} If the channel is invalid or handler is not a function
* @throws {Error} If a handler is already registered for the channel
*/
on(channel: string, handler: IPCRequestHandler): void;
/**
* Cancel the listener of a channel
*
* @param {string} channel - Channel name to remove listener from
* @throws {Error} If the channel is invalid
* @throws {Error} If no handler is registered for the channel
*/
off(channel: string): void;
/**
* Register a channel listener that can use requestId to respond.
*
* @param {string} channel - Channel name for listening
* @param {IPCRequestHandler} handler
* @throws {Error} If the channel is invalid or handler is not a function
* @throws {Error} If a handler is already registered for the channel
*/
addListener(channel: string, handler: IPCRequestHandler): void;
/**
* Cancel the listener of a channel
*
* @param {string} channel - Channel name to remove listener from
* @throws {Error} If the channel is invalid
* @throws {Error} If no handler is registered for the channel
*/
removeListener(channel: string): void;
/**
* Cancel all registered listeners by this instance
*/
clear(): void;
#private;
}
//# sourceMappingURL=TinyIpcResponder.d.mts.map