UNPKG

electron-findbar

Version:
153 lines (152 loc) 5.03 kB
import { BaseWindow, BrowserWindow, WebContents, BrowserWindowConstructorOptions, Rectangle } from 'electron'; interface LastState { text: string; matchCase: boolean; movable: boolean; theme: 'light' | 'dark' | 'system'; } /** * Chrome-like findbar for Electron applications. */ declare class Findbar { private static readonly assetPaths; private static defaultTheme; private static defaultWindowHandler?; private static defaultBoundsHandler; private parent?; private window?; private findableContents; private followVisibilityEventsFlag; private matches; private windowHandler; private boundsHandler; private customOptions?; private lastText; private theme; private matchCaseFlag; private isMovableFlag; private fixMove?; /** * Configure the findbar and link to the web contents. * * @param parent - Parent window or web contents * @param webContents - Custom findable web contents (optional) */ constructor(parent: BaseWindow | BrowserWindow | WebContents, webContents?: WebContents); /** * Open the findbar. If the findbar is already opened, focus the input text. */ open(): void; /** * Close the findbar. */ close(): void; /** * Detach the findbar from the web contents and close it if opened. */ detach(): void; /** * Update the parent window of the findbar. */ updateParentWindow(newParent?: BaseWindow): void; /** * Get the last state of the findbar. */ getLastState(): LastState; /** * Starts a request to find all matches for the text in the page. */ startFind(text: string, skipRendererEvent?: boolean): void; /** * Whether the search should be case-sensitive. */ matchCase(status: boolean, skipRendererEvent?: boolean): void; /** * Select previous match if any. */ findPrevious(): void; /** * Select next match if any. */ findNext(): void; /** * Stops the find request and clears selection. */ stopFind(): void; /** * Whether the findbar is opened. */ isOpen(): boolean; /** * Whether the findbar is focused. */ isFocused(): boolean; /** * Whether the findbar is visible to the user. */ isVisible(): boolean; /** * Set custom options for the findbar window. */ setWindowOptions(customOptions: BrowserWindowConstructorOptions): void; /** * Set a window handler for the findbar window. */ setWindowHandler(windowHandler: (findbarWindow: BrowserWindow) => void): void; /** * Set a bounds handler to calculate findbar bounds. */ setBoundsHandler(boundsHandler: (parentBounds: Rectangle, findbarBounds: Rectangle) => Rectangle): void; /** * Set whether the findbar will follow the parent window "show" and "hide" events. Default is true. * If false, the findbar will not hide automatically with the parent window. */ followVisibilityEvents(shouldFollow: boolean): void; /** * Get the current theme of this findbar instance. * @returns The current theme setting ('light', 'dark', or 'system'). */ getTheme(): 'light' | 'dark' | 'system'; /** * Update the theme of the findbar. Only affects the current instance. * @param theme - The theme to set. If not provided, uses the default theme. */ updateTheme(theme?: 'light' | 'dark' | 'system'): void; /** * Get the default theme. */ static getDefaultTheme(): 'light' | 'dark' | 'system'; /** * Set the default theme for new findbar instances. */ static setDefaultTheme(theme: 'light' | 'dark' | 'system'): void; /** * Set the default window handler for new findbar instances. */ static setDefaultWindowHandler(windowHandler: (findbarWindow: BrowserWindow) => void): void; /** * Set the default bounds handler for new findbar instances. */ static setDefaultBoundsHandler(boundsHandler: (parentBounds: Rectangle, findbarBounds: Rectangle) => Rectangle): void; private registerKeyboardShortcuts; private findInContent; private stopFindInContent; private registerListeners; private sendMatchesCount; private focusWindowAndHighlightInput; private static retrieveWebContents; private static getBaseWindowFromWebContents; private static setDefaultPosition; private static mergeStandardOptions; private static buildAssetPaths; private static setRef; /** * Get the findbar instance for a given BrowserWindow or WebContents. */ static from(windowOrWebContents: BaseWindow | BrowserWindow | WebContents, customWebContents?: WebContents): Findbar; /** * Get the findbar instance for a given BrowserWindow or WebContents if it exists. */ static fromIfExists(windowOrWebContents: BaseWindow | BrowserWindow | WebContents): Findbar | undefined; } export = Findbar;