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.

129 lines 5.22 kB
export default TinyElectronNotification; /** * A generic callback function used for event listeners. */ export type ListenerCallback = (...args: any[]) => void; export type NotificationInstance = { /** * - Indicates whether the feature is supported. */ isSupported: () => boolean; /** * - Shows the notification. */ show: () => Promise<void>; /** * - Closes the notification. */ close: () => Promise<void>; /** * - Registers an event listener. */ on: (event: string | symbol, callback: ListenerCallback) => void; /** * - Removes an event listener. */ off: (event: string | symbol, callback: ListenerCallback) => void; /** * - Registers a one-time event listener. */ once: (event: string | symbol, callback: ListenerCallback) => void; /** * - Alias for `on`. */ addListener: (event: string | symbol, callback: ListenerCallback) => void; /** * - Alias for `off`. */ removeListener: (event: string | symbol, callback: ListenerCallback) => void; /** * - Adds listener to the beginning. */ prependListener: (event: string | symbol, callback: ListenerCallback) => void; /** * - Adds one-time listener to the beginning. */ prependOnceListener: (event: string | symbol, callback: ListenerCallback) => void; /** * - Sets the maximum number of listeners. */ setMaxListeners: (count: number) => void; /** * - Gets the maximum number of listeners. */ getMaxListeners: () => number; /** * - Returns the number of listeners for the event. */ listenerCount: (event: string | symbol) => number; /** * - Returns an array of listeners. */ listeners: (event: string | symbol) => Function[]; /** * - Returns raw array of listeners. */ rawListeners: (event: string | symbol) => Function[]; /** * - Returns registered event names. */ eventNames: () => (string | symbol)[]; }; /** * @typedef {(...args: any[]) => void} ListenerCallback * A generic callback function used for event listeners. */ /** * @typedef {Object} NotificationInstance * @property {() => boolean} isSupported - Indicates whether the feature is supported. * @property {() => Promise<void>} show - Shows the notification. * @property {() => Promise<void>} close - Closes the notification. * @property {(event: string|symbol, callback: ListenerCallback) => void} on - Registers an event listener. * @property {(event: string|symbol, callback: ListenerCallback) => void} off - Removes an event listener. * @property {(event: string|symbol, callback: ListenerCallback) => void} once - Registers a one-time event listener. * @property {(event: string|symbol, callback: ListenerCallback) => void} addListener - Alias for `on`. * @property {(event: string|symbol, callback: ListenerCallback) => void} removeListener - Alias for `off`. * @property {(event: string|symbol, callback: ListenerCallback) => void} prependListener - Adds listener to the beginning. * @property {(event: string|symbol, callback: ListenerCallback) => void} prependOnceListener - Adds one-time listener to the beginning. * @property {(count: number) => void} setMaxListeners - Sets the maximum number of listeners. * @property {() => number} getMaxListeners - Gets the maximum number of listeners. * @property {(event: string|symbol) => number} listenerCount - Returns the number of listeners for the event. * @property {(event: string|symbol) => Function[]} listeners - Returns an array of listeners. * @property {(event: string|symbol) => Function[]} rawListeners - Returns raw array of listeners. * @property {() => (string|symbol)[]} eventNames - Returns registered event names. */ /** * Provides an interface to manage notifications with event handling * through Electron's native IPC. * * @beta This API is experimental and may change in future versions. */ declare class TinyElectronNotification { /** * Creates a new TinyElectronNotification instance and binds renderer IPC listeners. * * @param {Object} [settings={}] - Configuration settings for the notifications. * @param {NotificationEvents} [settings.eventNames=this.#Events] - Set of event names for internal messaging. */ constructor({ eventNames }?: { eventNames?: NotificationEvents | undefined; }); /** * Exposes the API securely to the main window context. * * @param {string} [apiName='newElectronNotification'] - The name under which the API will be exposed. */ installWinScript(apiName?: string): void; /** * Creates a new notification instance and sets up event bridging. * * @param {Electron.NotificationConstructorOptions & { tag: string }} arg - Notification configuration. * @returns {Promise<NotificationInstance>} Resolves to the notification instance methods. */ create(arg: Electron.NotificationConstructorOptions & { tag: string; }): Promise<NotificationInstance>; #private; } import { NotificationEvents } from '../global/Events.mjs'; //# sourceMappingURL=TinyElectronNotification.d.mts.map