-
Notifications
You must be signed in to change notification settings - Fork 434
feat: Support desktop webUsb , OK-44281 #8727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: x
Are you sure you want to change the base?
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
WalkthroughDesktop app adds WebUSB support: permission handlers, device detection, transport selection honoring a new Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration 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:
📒 Files selected for processing (1)
⏰ 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)
🔇 Additional comments (1)
Comment |
There was a problem hiding this 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 asHardwareSDK
).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.
⛔ 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.
packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts
Show resolved
Hide resolved
packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts
Outdated
Show resolved
Hide resolved
packages/kit/src/views/Onboarding/pages/ConnectHardwareWallet/ConnectYourDevice.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
📒 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.
packages/kit/src/views/Onboarding/pages/ConnectHardwareWallet/ConnectYourDevice.tsx
Outdated
Show resolved
Hide resolved
packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts
Outdated
Show resolved
Hide resolved
packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts
Outdated
Show resolved
Hide resolved
packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts
Outdated
Show resolved
Hide resolved
packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts
Outdated
Show resolved
Hide resolved
packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts
Outdated
Show resolved
Hide resolved
packages/kit/src/views/Onboarding/pages/ConnectHardwareWallet/ConnectYourDevice.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 -C2packages/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.
⛔ 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:
- SectionFieldItem extracts value from the atom:
devSetting?.settings?.[name]
(where name="desktopUsbComm")- cloneElement injects props to the Select child:
cloneElement(child, { ..., value, onChange: handleChange })
- handleChange persists via
updateDevSetting()
, which updates the atom and syncs to storageThe 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.
packages/kit-bg/src/services/ServiceHardware/HardwareConnectionManager.ts
Show resolved
Hide resolved
Review the following changes in direct dependencies. Learn more about Socket for GitHub. |
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. |
There was a problem hiding this 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.
📒 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
andDesktopWebBle
. 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 whetherBLE
andBridge
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.
packages/kit-bg/src/services/ServiceFirmwareUpdate/ServiceFirmwareUpdate.ts
Show resolved
Hide resolved
There was a problem hiding this 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.
📒 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.
<SectionFieldItem | ||
icon="UsbOutline" | ||
name="desktopUsbComm" | ||
title="USB 通信方式" | ||
> | ||
<Select | ||
items={[ | ||
{ label: 'WebUSB', value: 'webusb' }, | ||
{ label: 'Bridge', value: 'bridge' }, | ||
]} | ||
placement="bottom-end" | ||
/> | ||
</SectionFieldItem> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Select missing value binding and change handler.
The Select won't display the current setting or save changes. You need:
- A
value
prop bound todevSettings.settings?.desktopUsbComm
- 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.
<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', |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要用 comm
这样缩写的变量名
Summary by CodeRabbit
New Features
Chores