@zubridge/electron
Version:
A streamlined state management library for Electron applications using Zustand.
50 lines (49 loc) • 2.03 kB
TypeScript
import type { WebContents } from 'electron';
import type { WebContentsWrapper, WrapperOrWebContents } from '@zubridge/types';
/**
* Type guard to check if an object is an Electron WebContents
*/
export declare const isWebContents: (wrapperOrWebContents: WrapperOrWebContents) => wrapperOrWebContents is WebContents;
/**
* Type guard to check if an object is a WebContentsWrapper
*/
export declare const isWrapper: (wrapperOrWebContents: WrapperOrWebContents) => wrapperOrWebContents is WebContentsWrapper;
/**
* Get the WebContents object from either a WebContentsWrapper or WebContents
*/
export declare const getWebContents: (wrapperOrWebContents: WrapperOrWebContents) => WebContents | undefined;
/**
* Check if a WebContents is destroyed
*/
export declare const isDestroyed: (webContents: WebContents) => boolean;
/**
* Safely send a message to a WebContents
*/
export declare const safelySendToWindow: (webContents: WebContents, channel: string, data: unknown) => boolean;
/**
* Set up cleanup when WebContents is destroyed
*/
export declare const setupDestroyListener: (webContents: WebContents, cleanup: () => void) => void;
/**
* Creates a tracker for WebContents objects using WeakMap for automatic garbage collection
* and a Set to keep track of active IDs
*/
export interface WebContentsTracker {
track(webContents: WebContents): boolean;
untrack(webContents: WebContents): void;
untrackById(id: number): void;
isTracked(webContents: WebContents): boolean;
hasId(id: number): boolean;
getActiveIds(): number[];
getActiveWebContents(): WebContents[];
cleanup(): void;
}
/**
* Creates a WebContents tracker that uses WeakMap for automatic garbage collection
* but maintains a set of active IDs for tracking purposes
*/
export declare const createWebContentsTracker: () => WebContentsTracker;
/**
* Prepare WebContents objects from an array of wrappers or WebContents
*/
export declare const prepareWebContents: (wrappers?: WrapperOrWebContents[]) => WebContents[];