import { WebContents } from 'electron'; import { Characteristic, Peripheral } from '@stoprocent/noble'; import { OneKeyDeviceInfoBase } from '@onekeyfe/hd-transport'; import { EBleDisconnectReason } from '@onekeyfe/hd-shared'; interface DeviceInfo extends OneKeyDeviceInfoBase { id: string; name: string; state: string; mtu?: number; } interface CharacteristicPair { write: Characteristic; notify: Characteristic; } interface NobleModule { state: string; startScanning(serviceUUIDs: string[], allowDuplicates: boolean, callback?: (error?: Error) => void): void; stopScanning(callback?: () => void): void; stop(): void; cancelConnect?(id: string): void; on(event: 'stateChange', listener: (state: string) => void): void; on(event: 'discover', listener: (peripheral: Peripheral) => void): void; removeListener(event: 'stateChange', listener: (state: string) => void): void; removeListener(event: 'discover', listener: (peripheral: Peripheral) => void): void; } interface Logger { info(message: string, ...args: any[]): void; debug(message: string, ...args: any[]): void; warn(message: string, ...args: any[]): void; error(message: string, ...args: any[]): void; } /** * Desktop API types for Electron preload script * These types define the core interface for Noble BLE communication */ interface NobleBleWriteOptions { pacingDelayMs?: number; } type NobleBleIpcErrorPayload = { name: string; message: string; errorCode: number; params?: unknown; }; type NobleBleIpcErrorResponse = { type: 'NobleBleIpcError'; success: false; error: NobleBleIpcErrorPayload; }; declare function isNobleBleIpcErrorResponse(response: unknown): response is NobleBleIpcErrorResponse; /** * Keeps structured Noble errors intact across Electron's IPC and contextBridge * boundaries. Every preload implementation must use this for Noble invokes. */ declare function invokeNobleBleIpc(request: Promise): Promise; interface NobleBleAPI { enumerate: () => Promise<{ id: string; name: string; }[]>; getDevice: (uuid: string) => Promise<{ id: string; name: string; mtu?: number; } | null>; connect: (uuid: string) => Promise; release?: (uuid: string, keepSession?: boolean) => Promise; disconnect: (uuid: string) => Promise; subscribe: (uuid: string) => Promise; unsubscribe: (uuid: string) => Promise; write: (uuid: string, data: string, options?: NobleBleWriteOptions) => Promise; onNotification: (callback: (deviceId: string, data: string) => void) => () => void; onMtuChanged?: (callback: (device: { id: string; mtu: number; }) => void) => () => void; /** * Fires whenever a BLE link drops. `reason` distinguishes a real peripheral * drop from the main process freeing an idle link on its keep-alive timer; * it is optional so an older host bridge that omits it still type-checks * (absent is treated as a real drop by consumers). */ onDeviceDisconnected: (callback: (device: { id: string; name: string; reason?: EBleDisconnectReason; }) => void) => () => void; checkAvailability: () => Promise<{ available: boolean; state: string; unsupported: boolean; initialized: boolean; }>; } interface DesktopAPI { nobleBle?: NobleBleAPI; } declare function initNobleBleSupport(webContents: WebContents): Promise; /** Terminal process cleanup. A host sharing Noble can defer native stop until all users are idle. */ declare function disposeNobleBleSupport(releaseNoble?: (noble: { stop(): void; }) => void): Promise; export { CharacteristicPair, DesktopAPI, DeviceInfo, Logger, NobleBleAPI, NobleBleIpcErrorPayload, NobleBleIpcErrorResponse, NobleBleWriteOptions, NobleModule, disposeNobleBleSupport, initNobleBleSupport, invokeNobleBleIpc, isNobleBleIpcErrorResponse };