UNPKG

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.

97 lines 3.39 kB
export default TinyIpcRequestManager; /** * Options for customizing the IPC emit behavior. */ export type EmitOptions = { /** * - Optional timeout in milliseconds. If defined, the request will automatically reject if no response is received in this time. */ timeout?: number | undefined; }; /** * The data structure used to send a message through IPC. */ export type SendData = { /** * - A unique identifier for correlating the request and its response. */ __requestId: string; /** * - The actual data being sent with the request. */ payload: unknown; }; /** * Represents the structure of a response message sent to the main process. */ export type SendResult = { /** * - Unique ID that matches the original request, used to resolve the correct Promise. */ __requestId: string; /** * - The actual response data sent back to the requester. */ payload: unknown; /** * - An Error if the request failed, or null if it succeeded. */ error: Error | null; }; /** * Options for customizing the IPC emit behavior. * * @typedef {Object} EmitOptions * @property {number} [timeout] - Optional timeout in milliseconds. If defined, the request will automatically reject if no response is received in this time. */ /** * The data structure used to send a message through IPC. * * @typedef {Object} SendData * @property {string} __requestId - A unique identifier for correlating the request and its response. * @property {unknown} payload - The actual data being sent with the request. */ /** * @typedef {Object} SendResult * Represents the structure of a response message sent to the main process. * * @property {string} __requestId - Unique ID that matches the original request, used to resolve the correct Promise. * @property {unknown} payload - The actual response data sent back to the requester. * @property {Error|null} error - An Error if the request failed, or null if it succeeded. */ /** * Manages outgoing IPC requests with response handling for Electron. * * This class provides a request/response mechanism over Electron's IPC, * allowing you to send messages to the main process and await replies * with automatic promise-based handling. It manages timeouts, request IDs, * and error handling for reliable communication. * * Commonly used when the renderer process needs to request data or actions * from the main process. * * @class */ declare class TinyIpcRequestManager { /** * @param {string} [responseChannel='ipc-response'] - Custom channel name for receiving responses. * @throws {Error} If the provided responseChannel is not a non-empty string. */ constructor(responseChannel?: string); /** * Returns the channel name used to listen for responses. * @returns {string} */ getResponseChannel(): string; /** * Sends a request and returns a promise that resolves on response * @param {string} channel - The ipcRenderer channel to send * @param {any} [payload] - The data to send with the request * @param {EmitOptions} [options] * @returns {Promise<*>} * @throws {Error} If the channel or options are invalid */ send(channel: string, payload?: any, options?: EmitOptions): Promise<any>; #private; } //# sourceMappingURL=TinyIpcRequestManager.d.mts.map