Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

wabicai
Copy link
Contributor

@wabicai wabicai commented Oct 21, 2025

Summary by CodeRabbit

  • New Features

    • WebUSB enabled on desktop for direct USB device communication and permission handling.
    • Developer setting to choose desktop USB method (WebUSB or Bridge).
    • Improved detection of USB/bridge availability and smarter transport selection, including mini device behavior.
    • Firmware updates on desktop skip in-browser device prompts.
  • Chores

    • Bumped HD SDK packages to newer alpha versions.

@revan-zhang
Copy link
Contributor

revan-zhang commented Oct 21, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 21, 2025

Walkthrough

Desktop app adds WebUSB support: permission handlers, device detection, transport selection honoring a new desktopUsbComm dev setting; SDK loader and platform capability updated; UI exposes desktop USB method; firmware update calls skip web prompts on desktop. (50 words)

Changes

Cohort / File(s) Summary
Permission & Init
apps/desktop/app/app.ts, package.json
Add WebUSB permission handlers in main-window setup. Bump several @onekeyfe HD SDK packages from 1.1.16-alpha.11.1.16-alpha.5.
Device Detection & Transport Selection
packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts
Add getDesktopUsbSetting(), detectWebUSBAvailability(), detectBridgeAvailability(), detectUSBDeviceAvailability(). Transport selection now checks WebUSB/Bridge availability and respects desktopUsbComm, affecting mini-device handling and fallbacks.
Transport Environment Resolution
packages/kit-bg/src/services/ServiceHardware/ServiceHardware.ts
switchTransport maps transports to explicit env values: webusb, desktop-web-ble, or web before calling hardwareSDK.switchTransport(env).
Onboarding / Connect Flow
packages/kit/src/views/Onboarding/pages/ConnectHardwareWallet/ConnectYourDevice.tsx
Desktop forced transport derives from device settings (desktopUsbComm → Bridge or WEBUSB). Allow WEBUSB on desktop where applicable.
Settings UI — Transport List
packages/kit/src/views/Setting/pages/Tab/CustomElement.tsx
Build desktop transport options from persisted desktopUsbComm (WebUSB or Bridge first), optionally append DesktopWebBle; remove Mac-specific hardcoding.
Settings UI — Dev Section
packages/kit/src/views/Setting/pages/Tab/DevSettingsSection/index.tsx
Add UI field (Select) to choose desktopUsbComm between webusb and bridge.
Dev Settings State
packages/kit-bg/src/states/jotai/atoms/devSettings.ts
Add `desktopUsbComm?: 'webusb'
Platform Capability
packages/shared/src/platformEnv.ts
isSupportWebUSB now includes desktop Electron (`isExtension
SDK Loader
packages/shared/src/hardware/sdk-loader/index.ts
Use hd-common-connect-sdk loader for WEBUSB like DesktopWebBle; adjust default import access to HardwareSDKTopLevel for hd-web-sdk.
Firmware Update Flow
packages/kit-bg/src/services/ServiceFirmwareUpdate/ServiceFirmwareUpdate.ts
Add skipWebDevicePrompt: platformEnv.isDesktop to firmwareUpdateV2/V3 payloads to skip web device permission prompts on desktop.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App as Desktop App
    participant Perm as Permission Handler
    participant HCM as HardwareConnectionManager
    participant Trans as Transport Selector
    participant SDK as Hardware SDK

    User->>App: Request device connect
    App->>Perm: setPermissionCheckHandler / setDevicePermissionHandler
    Perm-->>App: Allow usb permission (desktop)
    App->>HCM: detectUSBDeviceAvailability(read desktopUsbComm)
    HCM->>HCM: detectWebUSBAvailability() or detectBridgeAvailability()
    HCM-->>Trans: availability result
    Trans->>Trans: determineOptimalTransportType()
    Trans-->>App: selected transport (webusb / bridge / desktop-web-ble / web)
    App->>SDK: initialize hardware SDK (env = 'webusb'|'desktop-web-ble'|'web')
    SDK-->>App: ready / connected
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "feat: Support desktop webUsb , OK-44281" directly describes the main change in the pull request—adding WebUSB support to the desktop platform. It's concise and specific enough that a teammate scanning history would immediately understand the primary objective. The conventional commit prefix "feat:" and issue reference provide additional clarity. While there's minor formatting (extra space before the comma), the title effectively communicates the core change.
Linked Issues Check ✅ Passed The linked issue OK-44281 requests integration of WebUSB support into the desktop SDK. The code changes directly fulfill this requirement: WebUSB permissions are added to the Electron app, availability detection methods are implemented, transport selection logic prioritizes WebUSB on desktop, a UI setting allows users to choose between WebUSB and Bridge, and the SDK loader is updated to use appropriate libraries for WebUSB. All changes work cohesively to deliver the requested WebUSB integration for desktop.
Out of Scope Changes Check ✅ Passed All code changes are directly related to integrating WebUSB support on desktop: permission handlers in the Electron app, WebUSB detection methods, transport selection logic updates, USB communication settings, firmware update adjustments, SDK loader configuration, and platform environment checks. No unrelated changes or scope creep is evident—every modification supports the core objective of enabling WebUSB on desktop.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/webusb-desktop

📜 Recent 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

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a7074c5 and 1c0c0c9.

📒 Files selected for processing (1)
  • packages/kit/src/views/Setting/pages/Tab/DevSettingsSection/index.tsx (2 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). (4)
  • GitHub Check: lint (20.x)
  • GitHub Check: unittest (20.x)
  • GitHub Check: Analyze (java-kotlin)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
packages/kit/src/views/Setting/pages/Tab/DevSettingsSection/index.tsx (1)

11-11: LGTM: Import added for new Select component.

The Select import is correctly added to support the new desktop USB communication setting.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (6)
packages/shared/src/hardware/sdk-loader/index.ts (2)

22-24: Keep low-level import consistent with the chosen top-level SDK.

If you stick with hd-common-connect-sdk for WEBUSB/DesktopWebBle, consider adding a transportType param here and route low-level accordingly to avoid implementation skew.


10-20: Fix the import: .default.HardwareSDKTopLevel doesn't exist in hd-web-sdk.

The package does not export a default export object with a HardwareSDKTopLevel property. The correct named export is HardwareWebSdk (commonly aliased as HardwareSDK).

Your code will throw a runtime error when DesktopWebBle or WEBUSB is selected. Change the fallback to:

return (await import('@onekeyfe/hd-web-sdk')).HardwareWebSdk;

Also verify the return type matches Promise<CoreApi> after importing the correct export.

packages/kit-bg/src/services/ServiceHardware/ServiceHardware.ts (3)

236-265: Include hd-common-connect-sdk in the version parity check.

Avoid silent drift between top‑level/common SDKs in dev.

       const {
         version: version5,
       } = require('@onekeyfe/hd-web-sdk/package.json');
+      const {
+        version: version6,
+      } = require('@onekeyfe/hd-common-connect-sdk/package.json');
       const allVersions = {
         HARDWARE_SDK_VERSION,
         version1,
         version2,
         version3,
         version4,
-        version5,
+        version5,
+        version6,
       };

1399-1403: Use the desktop env name when switching to WebUSB.

On desktop, prefer 'desktop-web-usb' to match the new mapping.

-      if (!isBridgeAvailable) {
-        await hardwareSDKInstance.switchTransport('webusb');
+      if (!isBridgeAvailable) {
+        const env = platformEnv.isDesktop ? 'desktop-web-usb' : 'webusb';
+        await hardwareSDKInstance.switchTransport(env);
         await this.fallbackToWebUSBTransport();
       }

316-324: Comment contradicts behavior for “mini” devices.

The comment says “always use bridge” but you return WEBUSB. Fix the comment or the logic.

-      // mini device should always use bridge transport type
+      // mini device should always use WebUSB transport type
       if (isMiniDevice) {
         return {
           shouldSwitch: false,
           targetType: EHardwareTransportType.WEBUSB,
         };
       }
packages/kit/src/views/Onboarding/pages/ConnectHardwareWallet/ConnectYourDevice.tsx (1)

793-821: Always clear loading state.

Set isChecking(false) in a finally to avoid sticky spinner if the flow short‑circuits.

   const onConnectWebDevice = useCallback(async () => {
-    setIsChecking(true);
-    try {
+    setIsChecking(true);
+    try {
       // ...
-    } catch (error) {
+    } catch (error) {
       console.error('onConnectWebDevice error:', error);
-      setIsChecking(false);
-    }
+    } finally {
+      setIsChecking(false);
+    }
   }, [onDeviceConnect, promptWebUsbDeviceAccess, tabValue, setIsChecking]);
📜 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

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 94b90d8 and 13bf5f2.

⛔ Files ignored due to path filters (20)
  • packages/shared/src/locale/json/bn.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/de.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/en_US.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/es.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/fr_FR.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/hi_IN.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/id.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/it_IT.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/ja_JP.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/ko_KR.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/pt.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/pt_BR.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/ru.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/th_TH.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/uk_UA.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/vi.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/zh_CN.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/zh_HK.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/zh_TW.json is excluded by !packages/shared/src/locale/json/*.json
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (9)
  • apps/desktop/app/app.ts (2 hunks)
  • package.json (1 hunks)
  • packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts (5 hunks)
  • packages/kit-bg/src/services/ServiceHardware/ServiceHardware.ts (1 hunks)
  • packages/kit/src/views/Onboarding/pages/ConnectHardwareWallet/ConnectYourDevice.tsx (4 hunks)
  • packages/kit/src/views/Setting/pages/Tab/CustomElement.tsx (1 hunks)
  • packages/shared/src/hardware/sdk-loader/index.ts (1 hunks)
  • packages/shared/src/locale/enum/translations.ts (1 hunks)
  • packages/shared/src/platformEnv.ts (1 hunks)
🧰 Additional context used
🪛 ESLint
packages/kit/src/views/Setting/pages/Tab/CustomElement.tsx

[error] 306-306: Insert ,

(prettier/prettier)

apps/desktop/app/app.ts

[error] 748-748: Delete ··

(prettier/prettier)

packages/kit/src/views/Onboarding/pages/ConnectHardwareWallet/ConnectYourDevice.tsx

[error] 1742-1742: Insert ··

(prettier/prettier)


[error] 1743-1743: Insert ··

(prettier/prettier)


[error] 1744-1744: Insert ··

(prettier/prettier)


[error] 1745-1745: Replace ···················· with ······················

(prettier/prettier)


[error] 1746-1746: Insert ··

(prettier/prettier)


[error] 1747-1747: Insert ··

(prettier/prettier)


[error] 1748-1748: Insert ··

(prettier/prettier)


[error] 1767-1767: Delete ··

(prettier/prettier)

⏰ 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). (4)
  • GitHub Check: lint (20.x)
  • GitHub Check: unittest (20.x)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: release-desktop (20.x)
🔇 Additional comments (6)
packages/shared/src/locale/enum/translations.ts (1)

1219-1219: LGTM! New translation key added correctly.

The global_discover key follows the naming pattern and sits in alphabetical order. No issues.

packages/shared/src/platformEnv.ts (1)

392-394: Enable WebUSB on desktop — LGTM.

Good alignment with Electron flow. Please sanity-check Linux Snap/Store builds where WebUSB may be sandboxed.

packages/kit-bg/src/services/ServiceHardware/ServiceHardware.ts (1)

1425-1434: Env mapping for switchTransport — LGTM.

packages/kit/src/views/Onboarding/pages/ConnectHardwareWallet/ConnectYourDevice.tsx (2)

133-147: Desktop usbOrBle → WebUSB first — LGTM.


822-833: Auto‑list on desktop WebUSB — LGTM.

packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts (1)

257-275: Optimal transport selection — LGTM.

Respects user setting when USB paths exist; falls back to DesktopWebBle, then WebUSB. Clear and predictable.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
apps/desktop/app/app.ts (1)

732-748: Critical security vulnerability: USB access granted to all origins and devices.

Your WebUSB handlers allow any origin to access any USB device. A malicious dapp in a webview could hijack hardware wallets.

Restrict by:

  • Origin: Only file:// (the app itself).
  • Device: Only OneKey VID/PIDs via ONEKEY_WEBUSB_FILTER.

The previous review comment provides a complete fix. Apply it before merge.

Based on past review comments.

packages/kit/src/views/Setting/pages/Tab/CustomElement.tsx (1)

304-309: Add missing trailing comma (already flagged).

The trailing comma after iconProps: { name: 'UsbOutline' as const } on line 306 is missing, causing a Prettier error. This issue was already flagged in a previous review.

📜 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

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 13bf5f2 and da9dd08.

📒 Files selected for processing (3)
  • apps/desktop/app/app.ts (1 hunks)
  • packages/kit/src/views/Onboarding/pages/ConnectHardwareWallet/ConnectYourDevice.tsx (2 hunks)
  • packages/kit/src/views/Setting/pages/Tab/CustomElement.tsx (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). (4)
  • GitHub Check: lint (20.x)
  • GitHub Check: unittest (20.x)
  • GitHub Check: Analyze (java-kotlin)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
packages/kit/src/views/Onboarding/pages/ConnectHardwareWallet/ConnectYourDevice.tsx (1)

822-833: LGTM! WebUSB now enabled on desktop.

The updated condition correctly allows WebUSB on desktop platforms. The early return at lines 825-826 now only triggers for WebUSB on non-desktop (web/extension), where manual device access is required. Desktop with WebUSB can proceed to automatic device listing.

@wabicai wabicai changed the title Feat/webusb-desktop feat: Support desktop webUsb , OK-44281 Oct 22, 2025
@wabicai wabicai requested a review from originalix October 22, 2025 11:25
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts (1)

384-388: Memoization key should include connectId.

Cache can bleed across devices if only keyed by context. Include connectId.

-      normalizer: (args) => `${args[0].hardwareCallContext || 'default'}`,
+      normalizer: (args) => {
+        const { hardwareCallContext, connectId } = (args && args[0]) || {};
+        return `${hardwareCallContext || 'default'}:${connectId || 'none'}`;
+      },
♻️ Duplicate comments (4)
package.json (1)

75-81: SDK parity check: include new packages and bump the gate.

You bumped hd-* to 1.1.16-alpha.3. Ensure the version gate and parity list in ServiceHardware cover:

  • @onekeyfe/hd-common-connect-sdk
  • @onekeyfe/hd-transport-electron
  • HARDWARE_SDK_VERSION = 1.1.16-alpha.3

Run:

#!/bin/bash
# Show installed hd-* versions
jq -r '.dependencies | to_entries[] | select(.key|test("^@onekeyfe/hd-")) | "\(.key)=\(.value)"' package.json

# Check the version gate and parity list
rg -n "HARDWARE_SDK_VERSION|allVersions|PARITY" packages/kit-bg/src/services/ServiceHardware/ServiceHardware.ts -C2

# Ensure both packages are in the parity object
rg -n "@onekeyfe/hd-common-connect-sdk|@onekeyfe/hd-transport-electron" packages/kit-bg/src/services/ServiceHardware/ServiceHardware.ts -C2
packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts (3)

128-148: Same issue for Bridge detection.

Don’t return true off relevant platforms. Gate to Desktop/Web/Extension (Bridge is reachable via localhost in browsers), else return false.

-  async detectBridgeAvailability(): Promise<boolean> {
-    if (!platformEnv.isSupportDesktopBle) {
-      return true;
-    }
+  async detectBridgeAvailability(): Promise<boolean> {
+    if (!(platformEnv.isDesktop || platformEnv.isWeb || platformEnv.isExtension)) {
+      return false;
+    }
     try {
       const response = await axios.post(
         'http://localhost:21320/enumerate',

109-126: Availability misreported off‑desktop/web; don’t return true.

Returning true when !isSupportDesktopBle falsely claims WebUSB is available on non‑desktop contexts. Let feature detection decide, or return false off native.

-  async detectWebUSBAvailability(): Promise<boolean> {
-    if (!platformEnv.isSupportDesktopBle) return true;
+  async detectWebUSBAvailability(): Promise<boolean> {
+    // Allow detection on Desktop/Web/Extension; report unavailable elsewhere.
+    if (!(platformEnv.isDesktop || platformEnv.isWeb || platformEnv.isExtension)) {
+      return false;
+    }
     try {
       const usb = globalThis?.navigator?.usb;
       if (!usb || typeof usb.getDevices !== 'function') return false;

151-160: USB availability wrapper: fix early return and honor mode.

Same early‑return bug. Report false on native, and defer to the selected mode or detection.

-  async detectUSBDeviceAvailability(
+  async detectUSBDeviceAvailability(
     mode?: 'webusb' | 'bridge',
   ): Promise<boolean> {
-    if (!platformEnv.isSupportDesktopBle) return true;
+    // Native environments have neither WebUSB nor Bridge
+    if (platformEnv.isNative) return false;
     const _mode = mode ?? (await this.getDesktopUsbSetting());
     if (_mode === 'bridge') {
       return this.detectBridgeAvailability();
     }
     return this.detectWebUSBAvailability();
   }
📜 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

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between da9dd08 and 14b214e.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (6)
  • package.json (1 hunks)
  • packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts (6 hunks)
  • packages/kit-bg/src/states/jotai/atoms/devSettings.ts (2 hunks)
  • packages/kit/src/views/Onboarding/pages/ConnectHardwareWallet/ConnectYourDevice.tsx (2 hunks)
  • packages/kit/src/views/Setting/pages/Tab/CustomElement.tsx (4 hunks)
  • packages/kit/src/views/Setting/pages/Tab/DevSettingsSection/index.tsx (2 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). (5)
  • GitHub Check: Socket Security: Pull Request Alerts
  • GitHub Check: unittest (20.x)
  • GitHub Check: lint (20.x)
  • GitHub Check: Socket Security: Project Report
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
packages/kit/src/views/Onboarding/pages/ConnectHardwareWallet/ConnectYourDevice.tsx (1)

136-140: Desktop transport derived from dev setting — good.

Pulling desktopUsbComm from dev settings to choose Bridge vs WebUSB is correct and keeps a single desktop USB mode.

packages/kit/src/views/Setting/pages/Tab/CustomElement.tsx (1)

291-291: Desktop options reflect the single USB mode — good.

The list now shows only the chosen USB mode (WebUSB or Bridge) plus Desktop BLE when available. This matches the “determine a single communication method” requirement.

Also applies to: 303-324, 339-339

packages/kit/src/views/Setting/pages/Tab/DevSettingsSection/index.tsx (1)

261-279: Code is already wired correctly—review comment is incorrect.

The value and onChange binding already happens automatically through SectionFieldItem's existing mechanism:

  1. SectionFieldItem extracts value from the atom: devSetting?.settings?.[name] (where name="desktopUsbComm")
  2. cloneElement injects props to the Select child: cloneElement(child, { ..., value, onChange: handleChange })
  3. handleChange persists via updateDevSetting(), which updates the atom and syncs to storage

The current code (lines 261-279) correctly relies on this pattern. The suggested diff would duplicate this mechanism with explicit props. No changes needed—the persistence already flows to transport selection.

Likely an incorrect or invalid review comment.

@socket-security
Copy link

socket-security bot commented Oct 22, 2025

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 14b214e and 95cdf32.

📒 Files selected for processing (2)
  • packages/kit-bg/src/services/ServiceFirmwareUpdate/ServiceFirmwareUpdate.ts (2 hunks)
  • packages/kit-bg/src/services/ServiceHardware/ServiceHardware.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). (5)
  • GitHub Check: Socket Security: Pull Request Alerts
  • GitHub Check: unittest (20.x)
  • GitHub Check: lint (20.x)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (java-kotlin)
🔇 Additional comments (2)
packages/kit-bg/src/services/ServiceHardware/ServiceHardware.ts (1)

1425-1433: Three enum values are not explicitly handled—verify this is intentional.

The code only handles WEBUSB and DesktopWebBle. Two other enum values exist:

  • BLE → maps to 'web' (implicit fallback)
  • Bridge → maps to 'web' (implicit fallback)

The type annotation ('webusb' | 'desktop-web-ble' | 'web') has only three values, suggesting the intent to normalize certain types. Confirm whether BLE and Bridge should explicitly map to 'web', or if they need separate handling. If intentional, add a comment explaining the design decision.

packages/kit-bg/src/services/ServiceFirmwareUpdate/ServiceFirmwareUpdate.ts (1)

1746-1746: LGTM! Consistent with bootloader update path.

The skipWebDevicePrompt: platformEnv.isDesktop parameter is correctly added for the V3 firmware update path, matching the pattern from line 967.

@wabicai wabicai enabled auto-merge (squash) October 22, 2025 12:34
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3817101 and a7074c5.

📒 Files selected for processing (1)
  • packages/kit/src/views/Setting/pages/Tab/DevSettingsSection/index.tsx (2 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: unittest (20.x)
  • GitHub Check: lint (20.x)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
packages/kit/src/views/Setting/pages/Tab/DevSettingsSection/index.tsx (1)

11-11: LGTM!

Import added correctly for the new Select component.

Comment on lines 261 to 273
<SectionFieldItem
icon="UsbOutline"
name="desktopUsbComm"
title="USB 通信方式"
>
<Select
items={[
{ label: 'WebUSB', value: 'webusb' },
{ label: 'Bridge', value: 'bridge' },
]}
placement="bottom-end"
/>
</SectionFieldItem>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: Select missing value binding and change handler.

The Select won't display the current setting or save changes. You need:

  1. A value prop bound to devSettings.settings?.desktopUsbComm
  2. An onValueChange handler to persist changes

Apply this diff:

           <SectionFieldItem
             icon="UsbOutline"
             name="desktopUsbComm"
             title="USB 通信方式"
+            onValueChange={(value: 'webusb' | 'bridge') => {
+              void backgroundApiProxy.serviceDevSetting.updateDevSetting(
+                'desktopUsbComm',
+                value,
+              );
+            }}
           >
             <Select
               items={[
                 { label: 'WebUSB', value: 'webusb' },
                 { label: 'Bridge', value: 'bridge' },
               ]}
+              value={devSettings.settings?.desktopUsbComm ?? 'bridge'}
               placement="bottom-end"
             />
           </SectionFieldItem>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<SectionFieldItem
icon="UsbOutline"
name="desktopUsbComm"
title="USB 通信方式"
>
<Select
items={[
{ label: 'WebUSB', value: 'webusb' },
{ label: 'Bridge', value: 'bridge' },
]}
placement="bottom-end"
/>
</SectionFieldItem>
<SectionFieldItem
icon="UsbOutline"
name="desktopUsbComm"
title="USB 通信方式"
onValueChange={(value: 'webusb' | 'bridge') => {
void backgroundApiProxy.serviceDevSetting.updateDevSetting(
'desktopUsbComm',
value,
);
}}
>
<Select
items={[
{ label: 'WebUSB', value: 'webusb' },
{ label: 'Bridge', value: 'bridge' },
]}
value={devSettings.settings?.desktopUsbComm ?? 'bridge'}
placement="bottom-end"
/>
</SectionFieldItem>
🤖 Prompt for AI Agents
In packages/kit/src/views/Setting/pages/Tab/DevSettingsSection/index.tsx around
lines 261-273 the Select is missing value binding and a change handler so it
neither shows the current setting nor persists updates; bind its value to
devSettings.settings?.desktopUsbComm and add an onValueChange handler that
updates the stored settings (e.g. call the module's update function to set
devSettings.settings.desktopUsbComm = newValue while preserving other settings),
ensuring the update function is imported/available and handling undefined
devSettings safely.


// Checking USB availability based on DevSetting (single mode)
async detectUSBDeviceAvailability(
mode?: 'webusb' | 'bridge',
Copy link
Collaborator

Choose a reason for hiding this comment

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

mode 参数有使用到么?没搜到

useLocalTradingViewUrl?: boolean;
showPerpsRenderStats?: boolean;

desktopUsbComm?: 'webusb' | 'bridge';
Copy link
Collaborator

Choose a reason for hiding this comment

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

不要用 comm 这样缩写的变量名

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