feat: Check desktop Bluetooth state - #515
Conversation
WalkthroughThis update adds a Bluetooth Low Energy (BLE) availability check to the Electron BLE handler. It introduces state tracking, a persistent listener, a new IPC message key, and exposes a new API method for checking BLE status. The change also updates package versions and dependencies across multiple packages to Changes
Sequence Diagram(s)sequenceDiagram
participant Renderer
participant Preload
participant MainProcess
participant NobleBLE
Renderer->>Preload: nobleBle.checkAvailability()
Preload->>MainProcess: IPC invoke BLE_AVAILABILITY_CHECK
MainProcess->>NobleBLE: checkBluetoothAvailability()
NobleBLE-->>MainProcess: { available, state, unsupported, initialized }
MainProcess-->>Preload: { available, state, unsupported, initialized }
Preload-->>Renderer: { available, state, unsupported, initialized }
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
packages/connect-examples/expo-playground/app/routes/device-info.tsxOops! Something went wrong! :( ESLint: 8.15.0 EslintPluginImportResolveError: typescript with invalid interface loaded as resolver ✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
…e-js-sdk into feat/check-ble-avaiable
There was a problem hiding this comment.
Actionable comments posted: 7
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (19)
packages/connect-examples/electron-example/package.json(1 hunks)packages/connect-examples/electron-example/src/preload.ts(1 hunks)packages/connect-examples/expo-example/package.json(2 hunks)packages/connect-examples/expo-playground/package.json(2 hunks)packages/core/package.json(2 hunks)packages/hd-ble-sdk/package.json(2 hunks)packages/hd-common-connect-sdk/package.json(2 hunks)packages/hd-transport-electron/package.json(2 hunks)packages/hd-transport-electron/src/noble-ble-handler.ts(6 hunks)packages/hd-transport-electron/src/types/desktop-api.ts(1 hunks)packages/hd-transport-emulator/package.json(2 hunks)packages/hd-transport-http/package.json(2 hunks)packages/hd-transport-lowlevel/package.json(2 hunks)packages/hd-transport-react-native/package.json(2 hunks)packages/hd-transport-web-device/package.json(2 hunks)packages/hd-transport/package.json(1 hunks)packages/hd-web-sdk/package.json(2 hunks)packages/shared/package.json(1 hunks)packages/shared/src/constants.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: lint (20.x)
- GitHub Check: build (20.x)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (22)
packages/hd-transport-web-device/package.json (1)
3-3: Version bump looks goodInternal deps now reference the new alpha.8 tag; keeps the tree in sync.
Also applies to: 23-24
packages/connect-examples/electron-example/package.json (1)
5-5: Confirm the lock-file matches the new versionBumping the package version looks good. Make sure you ran your package manager after the edit so
yarn.lock/package-lock.jsonrecords1.0.39-alpha.8; otherwise CI might still pull the old tag.packages/hd-ble-sdk/package.json (1)
3-3: Version bumps LGTMAll internal deps now point at
alpha.8. Nice and tidy.Also applies to: 23-25
packages/connect-examples/expo-playground/package.json (1)
3-3: Keep the example’s lock file in syncThe playground now uses
alpha.8, good. Runyarn installinside this package so its lock file follows suit before publishing.Also applies to: 20-22
packages/hd-transport-electron/package.json (1)
3-3: Peer range consistency check
alpha.8bump looks fine. Double-check that@onekeyfe/hd-transport-web-devicealso advances toalpha.8; mismatched peers can confuse consumers.Also applies to: 29-29
packages/hd-web-sdk/package.json (1)
3-3: Version bump looks good.
Matches the globalalpha.8wave.packages/shared/src/constants.ts (1)
30-30: New IPC key acknowledged.
Enum stays unique and follows the$onekey-ble-*convention.packages/hd-transport-http/package.json (2)
3-3: Package version aligns with core bump.
No red flags.
27-29: Validate dependency range.
Ensurealpha.8of@onekeyfe/hd-transportactually ships; HTTP transport will fail at runtime otherwise.packages/connect-examples/expo-example/package.json (2)
3-3: Example app version updated.
Keeps the demo in lockstep.
22-25: Smoke-test the Expo demo before merging.
React-Native BLE often breaks with new native deps.packages/hd-common-connect-sdk/package.json (2)
3-3: SDK version bump fine.
23-28: Confirm all α.8 packages resolve.
A missed publish will stall consumers.packages/connect-examples/electron-example/src/preload.ts (1)
110-110: LGTM! Clean IPC integration.The method follows the established pattern for IPC communication. It correctly invokes the new BLE availability check handler.
packages/hd-transport-electron/src/types/desktop-api.ts (1)
17-23: LGTM! Well-structured status interface.The return type provides comprehensive Bluetooth state information. The property names are clear and self-documenting.
packages/hd-transport-react-native/package.json (1)
3-3: LGTM! Version updates aligned.Package versions updated consistently across the monorepo.
Also applies to: 22-23
packages/hd-transport-electron/src/noble-ble-handler.ts (6)
28-41: LGTM! Proper state management setup.The global state object and listener variable are appropriate for tracking Bluetooth state in the main process singleton.
157-178: LGTM! Clean availability check implementation.The function properly ensures Noble initialization and returns comprehensive state information. Good reuse of existing initialization logic.
180-221: LGTM! Comprehensive state tracking.The persistent listener setup includes proper guards and initial state detection. All Noble states are mapped correctly to the state flags.
265-268: LGTM! Enhanced initialization with state tracking.Good additions:
- Explicit poweredOff error handling
- Persistent listener setup after successful init
- State updates on failure for accurate tracking
Also applies to: 283-284, 288-290
1071-1086: LGTM! Robust IPC handler with proper error handling.The handler includes comprehensive error handling with a safe fallback response. This ensures the renderer always receives a valid state object.
1100-1104: LGTM! Proper cleanup prevents memory leaks.The persistent state listener is correctly removed on app quit. This prevents dangling event listeners.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (2)
packages/connect-examples/expo-playground/app/routes/device-info.tsx(7 hunks)packages/connect-examples/expo-playground/app/routes/device-methods._index.tsx(0 hunks)
💤 Files with no reviewable changes (1)
- packages/connect-examples/expo-playground/app/routes/device-methods._index.tsx
🧰 Additional context used
📓 Path-based instructions (4)
packages/connect-examples/expo-playground/**/*.{ts,tsx}
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- packages/connect-examples/expo-playground/.cursorrules
packages/connect-examples/expo-playground/**/*.tsx
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- packages/connect-examples/expo-playground/.cursorrules
packages/connect-examples/expo-playground/**/*.{css,scss,tsx,jsx}
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- packages/connect-examples/expo-playground/.cursorrules
packages/connect-examples/expo-playground/**/*.{ts,tsx,css,scss}
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- packages/connect-examples/expo-playground/.cursorrules
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: lint (20.x)
- GitHub Check: build (20.x)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
packages/connect-examples/expo-playground/app/routes/device-info.tsx (8)
1-2: Clean import optimization.Good cleanup removing unused imports and keeping only necessary ones.
12-26: Strong TypeScript interfaces improve type safety.The new interfaces provide clear structure for device information data. This eliminates runtime errors and improves code maintainability.
70-185: Well-structured device sections with proper typing.The typed deviceSections object provides clear organization of device information fields by categories. The grouping makes the UI more readable and maintainable.
201-212: Proper type annotations in forEach loops.The explicit typing of parameters in forEach loops improves code clarity and catches potential type errors.
238-244: Accessibility keyboard handling implemented well.The keyboard event handler supports both Enter and Space keys, which follows standard accessibility practices. The preventDefault() call ensures proper event handling.
249-280: Enhanced accessibility with proper ARIA attributes.The updated renderField function adds proper keyboard navigation, focus management, and screen reader support. The conditional role and tabIndex attributes correctly handle interactive vs non-interactive states.
282-315: Type-safe rendering functions with proper parameter types.The renderGroup and renderSection functions now have explicit typing for their parameters, improving code safety and IntelliSense support.
356-372: Improved content clarity and user experience.The updated text content provides clearer instructions and better describes the component's purpose. The changes make the interface more user-friendly.
Summary by CodeRabbit