Skip to content

feat: Check desktop Bluetooth state - #515

Merged
originalix merged 7 commits into
onekeyfrom
feat/check-ble-avaiable
Jul 15, 2025
Merged

feat: Check desktop Bluetooth state#515
originalix merged 7 commits into
onekeyfrom
feat/check-ble-avaiable

Conversation

@originalix

@originalix originalix commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added the ability to check and report Bluetooth (BLE) availability and state in the Electron app, providing detailed status information.
    • Enhanced accessibility in device info view with keyboard support for copying field values.
  • Chores
    • Updated package versions and dependencies across multiple packages to 1.0.39-alpha.8.
  • Refactor
    • Improved type safety and code clarity in device info component.
    • Removed unused imports and state variables in device methods index page.

@coderabbitai

coderabbitai Bot commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This 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 1.0.39-alpha.8. Additionally, it improves typing and accessibility in a React device-info component and cleans unused imports in another React page.

Changes

Files/Groups Change Summary
.../electron-example/package.json, .../expo-example/package.json, .../expo-playground/package.json Updated package versions to 1.0.39-alpha.8 and dependencies to match.
.../core/package.json, .../hd-ble-sdk/package.json, .../hd-common-connect-sdk/package.json,
.../hd-transport-electron/package.json, .../hd-transport-emulator/package.json, .../hd-transport-http/package.json,
.../hd-transport-lowlevel/package.json, .../hd-transport-react-native/package.json, .../hd-transport-web-device/package.json,
.../hd-transport/package.json, .../hd-web-sdk/package.json, .../shared/package.json
Updated package versions and dependency versions to 1.0.39-alpha.8.
packages/shared/src/constants.ts Added BLE_AVAILABILITY_CHECK to EOneKeyBleMessageKeys enum.
packages/hd-transport-electron/src/types/desktop-api.ts Added checkAvailability method to NobleBleAPI interface.
packages/connect-examples/electron-example/src/preload.ts Added checkAvailability method to nobleBle in desktopApi, calling the new IPC channel.
packages/hd-transport-electron/src/noble-ble-handler.ts Added BLE state tracking, persistent listener, new IPC handler for BLE availability, and cleanup logic.
packages/connect-examples/expo-playground/app/routes/device-info.tsx Added TypeScript interfaces for device info, improved typing, accessibility, and keyboard support for copying fields.
packages/connect-examples/expo-playground/app/routes/device-methods._index.tsx Removed unused imports and unused state variable.

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 }
Loading

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/connect-examples/expo-playground/app/routes/device-info.tsx

Oops! Something went wrong! :(

ESLint: 8.15.0

EslintPluginImportResolveError: typescript with invalid interface loaded as resolver
Occurred while linting /packages/connect-examples/expo-playground/app/routes/device-info.tsx:1
Rule: "import/namespace"
at requireResolver (/node_modules/eslint-module-utils/resolve.js:188:17)
at fullResolve (/node_modules/eslint-module-utils/resolve.js:134:22)
at resolve.relative (/node_modules/eslint-module-utils/resolve.js:84:10)
at remotePath (/node_modules/eslint-plugin-import/lib/ExportMap.js:811:381)
at captureDependency (/node_modules/eslint-plugin-import/lib/ExportMap.js:817:463)
at captureDependencyWithSpecifiers (/node_modules/eslint-plugin-import/lib/ExportMap.js:817:144)
at /node_modules/eslint-plugin-import/lib/ExportMap.js:822:42
at Array.forEach ()
at ExportMap.parse (/node_modules/eslint-plugin-import/lib/ExportMap.js:821:427)
at ExportMap.for (/node_modules/eslint-plugin-import/lib/ExportMap.js:807:201)

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/check-ble-avaiable

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or Summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@originalix
originalix enabled auto-merge (squash) July 15, 2025 08:01
@revan-zhang

revan-zhang commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

🎉 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)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 885b67a and ac900fb.

📒 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 good

Internal 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 version

Bumping the package version looks good. Make sure you ran your package manager after the edit so yarn.lock/package-lock.json records 1.0.39-alpha.8; otherwise CI might still pull the old tag.

packages/hd-ble-sdk/package.json (1)

3-3: Version bumps LGTM

All 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 sync

The playground now uses alpha.8, good. Run yarn install inside 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.8 bump looks fine. Double-check that @onekeyfe/hd-transport-web-device also advances to alpha.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 global alpha.8 wave.

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.
Ensure alpha.8 of @onekeyfe/hd-transport actually 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.

Comment thread packages/shared/package.json
Comment thread packages/hd-transport/package.json
Comment thread packages/hd-transport-lowlevel/package.json
Comment thread packages/hd-transport-emulator/package.json
Comment thread packages/core/package.json
Comment thread packages/hd-web-sdk/package.json
Comment thread packages/shared/src/constants.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between ac900fb and e3bae61.

📒 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.

@wabicai
wabicai self-requested a review July 15, 2025 09:38
@originalix
originalix merged commit af4ab42 into onekey Jul 15, 2025
10 checks passed
@originalix
originalix deleted the feat/check-ble-avaiable branch July 15, 2025 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants