@lynker-desktop/electron-window-manager
Version:
electron-window-manager
123 lines • 4.91 kB
TypeScript
import { WebContents } from 'electron';
import type { ElectronWindowsManagerOptions, BWItem, BVItem, PreloadWebContentsConfig } from '../common';
export declare const getCustomSession: () => Electron.Session;
export declare const enable: (win: WebContents) => void;
export declare class WindowsManager {
loadingViewUrl: string | undefined;
errorViewUrl: string | undefined;
preload?: string;
preloadWebContentsConfig?: PreloadWebContentsConfig;
windows: Map<number, BWItem | BVItem>;
windowsByName: Map<string, number>;
preloadedBW: BWItem | null;
preloadedBW_FramelessWithButtons: BWItem | null;
preloadedBW_FramelessNoButtons: BWItem | null;
preloadedBV: BVItem | null;
preloading: boolean;
webviewDomainWhiteList: string[];
private cleanupDestroyedWindowsDebounced;
/**
* webview 域名白名单
* 传入格式示例:
* [
* 'example.com', // 精确匹配 example.com
* '.example.com', // 匹配所有 example.com 的子域名,如 a.example.com、b.example.com
* 'sub.domain.com', // 精确匹配 sub.domain.com
* 'localhost', // 匹配 localhost 及本地回环地址
* '127.0.0.1', // 匹配 127.0.0.1
* '::1' // 匹配 IPv6 本地回环
* ]
* 注意:
* - 以点开头的(如 .example.com)会匹配所有子域名。
* - 不带点的(如 example.com)只匹配主域名。
* - 'localhost'、'127.0.0.1'、'::1' 以及局域网 IP(如 192.168.x.x、10.x.x.x、172.16.x.x~172.31.x.x)都视为本地白名单。
*/
constructor(preload?: string, loadingViewUrl?: string, errorViewUrl?: string, preloadWebContentsConfig?: PreloadWebContentsConfig, webviewDomainWhiteList?: string[]);
/**
* 设置预加载的webContents配置
* @param preloadWebContentsConfig 预加载的webContents配置
*/
setPreloadWebContentsConfig(preloadWebContentsConfig: PreloadWebContentsConfig): void;
/**
* Promise 超时包装函数
* @param promise 要包装的 Promise
* @param timeout 超时时间(毫秒)
* @param errorMessage 超时错误信息
*/
private _withTimeout;
/**
* 预加载实例
*/
private _preloadInstances;
/**
* 创建预加载的窗口
* @param options 窗口选项
* @returns 预加载的窗口
*/
private _createPreloadBW;
/**
* 创建预加载的浏览器视图
* @returns 预加载的浏览器视图
*/
private _createPreloadBV;
create(options: Omit<ElectronWindowsManagerOptions, 'type'> & {
type?: 'BW';
}): Promise<BWItem>;
create(options: ElectronWindowsManagerOptions & {
type: 'BV';
}): Promise<BVItem>;
create(options: ElectronWindowsManagerOptions): Promise<BVItem | BWItem>;
/**
* 实际的窗口创建逻辑
*/
private _createWindow;
_setLoadingView(window: BWItem, createOptions: ElectronWindowsManagerOptions): void;
/**
* 检查窗口是否已销毁
*/
private _isWindowDestroyed;
/**
* 安全地获取窗口的 webContents.id
* 如果 webContents 已销毁,返回 undefined
*/
_getWebContentsId(win: BWItem | BVItem | null | undefined): number | undefined;
/**
* 判断是否本地/内网IP
*/
private _isLocalhost;
/**
* 清理已销毁的窗口(延迟执行,避免频繁检查)
*/
private _cleanupDestroyedWindows;
get(idOrName: string | number): BWItem | BVItem | undefined;
getAll(type: 'BW'): Map<number, BWItem>;
getAll(type: 'BV'): Map<number, BVItem>;
getAll(): Map<number, BWItem | BVItem>;
close(idOrName: string | number): boolean;
closeAll(): void;
rename(idOrName: string | number, newName: string): BWItem | BVItem | undefined;
reInitUrl(idOrName: string | number, url: string): BWItem | BVItem | undefined;
getPreload(): string | undefined;
private _applyBrowserWindowOptions;
private _applyBrowserViewOptions;
createPreloadWebContents(url: string): Promise<unknown>;
getWindowForWebContentsId(wcId: number): Promise<BWItem | undefined>;
/**
* 手动对BrowserView进行排序
* @param windowId 窗口ID或名称
*/
sortBrowserViews(windowId: string | number): void;
/**
* 防抖的排序方法
* @param window 目标窗口
*/
private sortBrowserViewsDebounced;
/**
* 对BrowserView进行排序
* @param window 目标窗口
*/
private _sortBrowserViews;
}
export declare let isInitialized: boolean;
export declare const initialize: (preload?: string, loadingViewUrl?: string, errorViewUrl?: string, preloadWebContentsConfig?: PreloadWebContentsConfig, webviewDomainWhiteList?: string[]) => WindowsManager;
//# sourceMappingURL=index.d.ts.map