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.
85 lines • 4.46 kB
text/typescript
export default TinyElectronNotification;
export type NotificationConstructorOptions = Electron.NotificationConstructorOptions & {
tag?: string;
};
/** @typedef {Electron.NotificationConstructorOptions & { tag?: string; }} NotificationConstructorOptions */
/**
* Provides an interface to manage notifications with event handling
* through Electron's IPC. Each notification instance supports lifecycle
* management (create, show, close) and full event listener control based
* on Node.js `EventEmitter`.
*
* This class acts as a bridge between the renderer and the main process,
* allowing you to create persistent notification instances identified by tags.
*
* @beta This API is experimental and may change in future versions.
*/
declare class TinyElectronNotification {
/**
* Creates a new TinyElectronNotification instance.
*
* @param {Object} [settings={}] - Configuration settings for the notifications.
* @param {NotificationEvents} [settings.eventNames=this.#Events] - Set of event names for internal messaging.
* @param {TinyIpcRequestManager} [settings.ipcRequest] - The IPC request manager instance for communication.
*
* @throws {Error} If `ipcRequest` is not an instance of `TinyIpcRequestManager`.
* @throws {Error} If `id` is not a string.
*/
constructor({ ipcRequest, eventNames }?: {
eventNames?: NotificationEvents | undefined;
ipcRequest?: TinyIpcRequestManager | undefined;
});
/**
* @param {string} apiName - The name under which the API will be exposed in the window context.
*/
installWinScript(apiName?: string): void;
/**
* Creates a new notification instance with event handling capabilities.
*
* @param {NotificationConstructorOptions} arg Notification configuration object. The `tag` is required and must be unique.
* @returns {Promise<{
* isSupported: () => boolean,
* show: () => void,
* close: () => void,
* on: (event: string|symbol, callback: ListenerCallback) => void,
* off: (event: string|symbol, callback: ListenerCallback) => void,
* once: (event: string|symbol, callback: ListenerCallback) => void,
* addListener: (event: string|symbol, callback: ListenerCallback) => void,
* removeListener: (event: string|symbol, callback: ListenerCallback) => void,
* prependListener: (event: string|symbol, callback: ListenerCallback) => void,
* prependOnceListener: (event: string|symbol, callback: ListenerCallback) => void,
* setMaxListeners: (count: number) => void,
* getMaxListeners: () => number,
* listenerCount: (event: string|symbol) => number,
* listeners: (event: string|symbol) => Function[],
* rawListeners: (event: string|symbol) => Function[],
* eventNames: () => (string|symbol)[]
* }>} Promise resolving to the notification instance with event methods.
*
* @throws {TypeError} If `arg` is not an object.
* @throws {Error} If `arg.tag` is missing or not a non-empty string.
* @throws {Error} If a notification with the same `tag` already exists.
*/
create(arg: NotificationConstructorOptions): Promise<{
isSupported: () => boolean;
show: () => void;
close: () => void;
on: (event: string | symbol, callback: (...args: any[]) => void) => void;
off: (event: string | symbol, callback: (...args: any[]) => void) => void;
once: (event: string | symbol, callback: (...args: any[]) => void) => void;
addListener: (event: string | symbol, callback: (...args: any[]) => void) => void;
removeListener: (event: string | symbol, callback: (...args: any[]) => void) => void;
prependListener: (event: string | symbol, callback: (...args: any[]) => void) => void;
prependOnceListener: (event: string | symbol, callback: (...args: any[]) => void) => void;
setMaxListeners: (count: number) => void;
getMaxListeners: () => number;
listenerCount: (event: string | symbol) => number;
listeners: (event: string | symbol) => Function[];
rawListeners: (event: string | symbol) => Function[];
eventNames: () => (string | symbol)[];
}>;
#private;
}
import { NotificationEvents } from '../global/Events.mjs';
import TinyIpcRequestManager from './TinyIpcRequestManager.mjs';
//# sourceMappingURL=TinyElectronNotification.d.mts.map