UNPKG

super-browser-window-kit

Version:

Super toolkit for enhanced Electron BrowserWindow with rounded corners and macOS liquid glass effects

318 lines 12.4 kB
//#region js/variants.d.ts type GlassMaterialVariant = number; declare const GlassMaterialVariant: { readonly regular: 0; readonly clear: 1; readonly dock: 2; readonly appIcons: 3; readonly widgets: 4; readonly text: 5; readonly avplayer: 6; readonly facetime: 7; readonly controlCenter: 8; readonly notificationCenter: 9; readonly monogram: 10; readonly bubbles: 11; readonly identity: 12; readonly focusBorder: 13; readonly focusPlatter: 14; readonly keyboard: 15; readonly sidebar: 16; readonly abuttedSidebar: 17; readonly inspector: 18; readonly control: 19; readonly loupe: 20; readonly slider: 21; readonly camera: 22; readonly cartouchePopover: 23; }; //#endregion //#region js/index.d.ts interface GlassOptions { cornerRadius?: number; tintColor?: string | { light: string; dark: string; }; } interface BackgroundOptions { cornerRadius?: number; color?: string | { light: string; dark: string; }; } interface GlassFrame { x: number; y: number; width: number; height: number; } // NSWindowToolbarStyle constants for macOS declare enum NSWindowToolbarStyle { Automatic = 0, Expanded = 1, Preference = 2, Unified = 3, UnifiedCompact = 4, } // NSView autoresizing mask constants for macOS declare enum AutoresizingMask { NotSizable = 0, MinXMargin = 1, WidthSizable = 2, MaxXMargin = 4, MinYMargin = 8, HeightSizable = 16, MaxYMargin = 32, // Common combinations FlexibleWidth = 2, FlexibleHeight = 16, FlexibleSize = 18, FlexibleLeftMargin = 1, FlexibleRightMargin = 4, FlexibleTopMargin = 32, FlexibleBottomMargin = 8, FlexibleMargins = 45, All = 63, } // 全屏通知信息接口 interface FullScreenNotificationInfo { name: string; windowNumber?: number; } // 全屏通知回调函数类型 type FullScreenNotificationCallback = (info: FullScreenNotificationInfo) => void; interface TahoeFidelityKitNative { addGlassEffectView(handle: Buffer): number; removeView(handle: Buffer, id: number): boolean; setVariant(handle: Buffer, id: number, variant: GlassMaterialVariant): void; setScrimState(handle: Buffer, id: number, scrim: number): void; setSubduedState(handle: Buffer, id: number, subdued: number): void; setFrame(handle: Buffer, id: number, x: number, y: number, width: number, height: number): boolean; setAutoresizingMask(handle: Buffer, id: number, mask: number): boolean; getFrame(handle: Buffer, id: number): GlassFrame | null; // Glass view management setGlassCornerRadius(handle: Buffer, id: number, cornerRadius: number): void; setGlassColor(handle: Buffer, id: number, colorHex: string): void; setGlassDynamicColor(handle: Buffer, id: number, lightColorHex: string, darkColorHex: string): void; // Background view management addBackgroundView(handle: Buffer): number; setBackgroundCornerRadius(handle: Buffer, id: number, cornerRadius: number): void; setBackgroundColor(handle: Buffer, id: number, colorHex: string): void; setBackgroundDynamicColor(handle: Buffer, id: number, lightColorHex: string, darkColorHex: string): void; // Window Toolbar methods setWindowToolbar(handle: Buffer, toolbarIdentifier: string): boolean; setWindowToolbarStyle(handle: Buffer, toolbarStyle: number): boolean; getWindowToolbar(handle: Buffer): string | null; removeWindowToolbar(handle: Buffer): boolean; // Full Screen Notification methods setFullScreenNotificationListener(handle: Buffer, callback: FullScreenNotificationCallback): boolean; removeFullScreenNotificationListener(handle: Buffer): boolean; // Full Screen Presentation Options addFullScreenOptionsMethod(handle: Buffer): boolean; // Window Corner Customization methods enableWindowCornerCustomization(): boolean; setWindowCornerRadius(handle: Buffer, radius: number): boolean; disableWindowCornerCustomization(): boolean; // License Verification setLicense(license: string): boolean; verifyLicense(data: string, license: string): boolean; } // Create a nice JavaScript wrapper declare class TahoeFidelityKit { _addon?: TahoeFidelityKitNative; _macosVersion: number; // Instance property for easy access to variants readonly GlassMaterialVariant: typeof GlassMaterialVariant; constructor(); /** * 设置全屏通知监听器。 * @param handle BrowserWindow.getNativeWindowHandle() * @param callback 回调函数 (FullScreenNotificationInfo) => void * @returns true if listener was set, false otherwise */ setFullScreenNotificationListener(handle: Buffer, callback: FullScreenNotificationCallback): boolean; /** * 移除全屏通知监听器。 * @param handle BrowserWindow.getNativeWindowHandle() * @returns true if listener was removed, false otherwise */ removeFullScreenNotificationListener(handle: Buffer): boolean; /** * Dynamically add window:willUseFullScreenPresentationOptions: to NSWindow.delegate. * This enables autoHideToolbar/fullScreen/autoHideMenuBar for full screen transitions. * @param handle BrowserWindow.getNativeWindowHandle() * @returns true if method was added, false otherwise */ addFullScreenOptionsMethod(handle: Buffer): boolean; /** * Wrap the Electron window with a glass / vibrancy view. * @param handle BrowserWindow.getNativeWindowHandle() * @param options Glass effect options * @returns id – can be used for future API (remove/update) */ addGlassEffectView(handle: Buffer, options?: GlassOptions): number; /** * Remove a view (glass or background) by its ID. * This method works for both glass views and background views. * * @param handle BrowserWindow.getNativeWindowHandle() * @param id The view ID returned by addGlassEffectView or addBackgroundView * @returns true if the view was successfully removed, false otherwise */ removeView(handle: Buffer, id: number): boolean; setVariant(handle: Buffer, id: number, variant: GlassMaterialVariant): void; setScrim(handle: Buffer, id: number, scrim: number): void; setSubdued(handle: Buffer, id: number, subdued: number): void; /** * Set the corner radius of a glass view. * * @param handle BrowserWindow.getNativeWindowHandle() * @param id The glass view ID returned by addGlassEffectView * @param cornerRadius Corner radius in points */ setGlassCornerRadius(handle: Buffer, id: number, cornerRadius: number): void; /** * Set the color of a glass view. * Supports both single color and dynamic color (light/dark mode). * * @param handle BrowserWindow.getNativeWindowHandle() * @param id The glass view ID returned by addGlassEffectView * @param color Hex color string (e.g., "#FF0000") or object with light/dark colors */ setGlassColor(handle: Buffer, id: number, color: string | { light: string; dark: string; }): void; /** * Set the autoresizing mask of a view (glass or background). * * The autoresizing mask determines how the view resizes and repositions * when its parent (the window) changes size. This follows macOS NSView conventions. * * Common patterns: * - AutoresizingMask.NotSizable: Fixed position and size (use with setFrame) * - AutoresizingMask.FlexibleSize: Fill entire parent * - AutoresizingMask.FlexibleMargins: Maintain size, center in parent * * @param handle BrowserWindow.getNativeWindowHandle() * @param id The view ID returned by addGlassEffectView or addBackgroundView * @param mask The autoresizing mask (use AutoresizingMask enum values) * @returns true if the mask was successfully set, false otherwise */ setAutoresizingMask(handle: Buffer, id: number, mask: AutoresizingMask | number): boolean; /** * Get the current frame (position and size) of a view (glass or background). * @param handle BrowserWindow.getNativeWindowHandle() * @param id The view ID returned by addGlassEffectView or addBackgroundView * @returns The frame object with x, y, width, height properties, or null if not found */ getFrame(handle: Buffer, id: number): GlassFrame | null; /** * Set frame components selectively. Pass null/undefined for values you want to keep unchanged. * This provides maximum flexibility for partial frame updates. * * @param handle BrowserWindow.getNativeWindowHandle() * @param id The view ID returned by addGlassEffectView * @param options Object with optional x, y, width, height properties * @returns true if the frame was successfully updated, false otherwise */ updateFrame(handle: Buffer, id: number, options: { x?: number; y?: number; width?: number; height?: number; }): boolean; /** * Add a background view to the window. * Background views are managed independently from glass views, * allowing you to have multiple glass views with a single background. * * @param handle BrowserWindow.getNativeWindowHandle() * @param options Background view options (optional) * @returns background view ID that can be used for future operations */ addBackgroundView(handle: Buffer, options?: BackgroundOptions): number; /** * Set the corner radius of a background view. * * @param handle BrowserWindow.getNativeWindowHandle() * @param id The background view ID returned by addBackgroundView * @param cornerRadius Corner radius in points */ setBackgroundCornerRadius(handle: Buffer, id: number, cornerRadius: number): void; /** * Set the color of a background view. * Supports both single color and dynamic color (light/dark mode). * * @param handle BrowserWindow.getNativeWindowHandle() * @param id The background view ID returned by addBackgroundView * @param color Hex color string (e.g., "#FF0000") or object with light/dark colors */ setBackgroundColor(handle: Buffer, id: number, color: string | { light: string; dark: string; }): void; // Window Toolbar methods /** * Set a toolbar for the window with the specified identifier. * * @param handle BrowserWindow.getNativeWindowHandle() * @param toolbarIdentifier A unique identifier for the toolbar * @returns true if the toolbar was successfully set, false otherwise */ setWindowToolbar(handle: Buffer, toolbarIdentifier: string): boolean; /** * Set the toolbar style for the window. * * @param handle BrowserWindow.getNativeWindowHandle() * @param toolbarStyle NSWindowToolbarStyle value * @returns true if the toolbar style was successfully set, false otherwise */ setWindowToolbarStyle(handle: Buffer, toolbarStyle: NSWindowToolbarStyle | number): boolean; /** * Get the current toolbar identifier for the window. * * @param handle BrowserWindow.getNativeWindowHandle() * @returns The toolbar identifier string, or null if no toolbar is set */ getWindowToolbar(handle: Buffer): string | null; /** * Remove the toolbar from the window. * * @param handle BrowserWindow.getNativeWindowHandle() * @returns true if the toolbar was successfully removed, false otherwise */ removeWindowToolbar(handle: Buffer): boolean; // Window Corner Customization methods /** * Enable custom window corner radius support globally. * Must be called before using setWindowCornerRadius. * * @returns true if corner customization was successfully enabled, false otherwise */ enableWindowCornerCustomization(): boolean; /** * Set a custom corner radius for the specified window. * Note: enableWindowCornerCustomization() must be called first. * * @param handle BrowserWindow.getNativeWindowHandle() * @param radius Corner radius in points * @returns true if the corner radius was successfully set, false otherwise */ setWindowCornerRadius(handle: Buffer, radius: number): boolean; /** * Disable custom window corner radius support globally. * This restores the original corner mask behavior and clears all custom settings. * * @returns true if corner customization was successfully disabled, false otherwise */ disableWindowCornerCustomization(): boolean; setLicense(license: string): boolean; } // Create and export the singleton instance // The class constructor handles platform checks internally declare const superBrowserWindowKit: TahoeFidelityKit; //#endregion export { AutoresizingMask, BackgroundOptions, FullScreenNotificationCallback, FullScreenNotificationInfo, GlassFrame, GlassMaterialVariant, GlassOptions, NSWindowToolbarStyle, TahoeFidelityKitNative, superBrowserWindowKit as default };