@onekeyfe/hd-transport-web-device 1.2.0-alpha.11 → 1.2.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";AAmBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnG,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAevC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,CAAC,EAAE,UAAU,CAAC;KACzB;CACF;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,YAAY,CAAC;CACjC,CAAC;AAqCF,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC,OAAO,CAAC,SAAS,CAA0D;IAE3E,OAAO,CAAC,WAAW,CAA0D;IAE7E,IAAI,SAA0B;IAE9B,UAAU,UAAS;IAEnB,UAAU,EAAE,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,GAAG,IAAI,CAAQ;IAExD,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;IAEvB,OAAO,CAAC,gBAAgB,CAA0B;IAElD,OAAO,CAAC,cAAc,CAAwC;IAE9D,OAAO,CAAC,mBAAmB,CAAwC;IAEnE,OAAO,CAAC,SAAS,CAAsE;IAEvF,OAAO,CAAC,YAAY,CAAoD;IAExE,OAAO,CAAC,aAAa,CAAwC;IAE7D,OAAO,CAAC,eAAe,C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Error : function (error, suppr
41
41
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
42
42
  };
43
43
 
44
+ const HIGH_VOLUME_CALLS = new Set(['FileWrite', 'FilesystemFileWrite', 'EmmcFileWrite']);
45
+ function shouldSuppressHighVolumeCallLog(name) {
46
+ return HIGH_VOLUME_CALLS.has(name);
47
+ }
48
+ function createTransportCallLog(name, protocol) {
49
+ return { name, protocol };
50
+ }
51
+
44
52
  const { parseConfigure: parseConfigure$1, check: check$1, ProtocolV1: ProtocolV1$1 } = transport__default["default"];
45
53
  const CONFIGURATION_ID = 1;
46
54
  const INTERFACE_ID = 0;
@@ -52,19 +60,6 @@ const HEADER_LENGTH = transport.PROTOCOL_V1_MESSAGE_HEADER_SIZE;
52
60
  const PACKET_IO_MAX_RETRIES = 3;
53
61
  const PACKET_IO_RETRY_DELAY = 300;
54
62
  const PROTOCOL_PROBE_TIMEOUT = 1000;
55
- const WEBUSB_FILE_WRITE_LOG_BLOCK_PATTERN = /(?:^|[^a-z])(?:raw)?(?:filesystem|emmc)?filewrite$/i;
56
- function shouldSuppressWebUsbCallLog(name) {
57
- const normalized = name.replace(/[_\s-]/g, '');
58
- return WEBUSB_FILE_WRITE_LOG_BLOCK_PATTERN.test(normalized);
59
- }
60
- function isLogBlockCommand$1(name) {
61
- var _a, _b;
62
- return (_b = (_a = transport.LogBlockCommand === null || transport.LogBlockCommand === void 0 ? void 0 : transport.LogBlockCommand.has) === null || _a === void 0 ? void 0 : _a.call(transport.LogBlockCommand, name)) !== null && _b !== void 0 ? _b : false;
63
- }
64
- function shouldBlockWebUsbCallDataLog(name) {
65
- const normalized = name.replace(/[_\s-]/g, '');
66
- return isLogBlockCommand$1(name) || WEBUSB_FILE_WRITE_LOG_BLOCK_PATTERN.test(normalized);
67
- }
68
63
  function inferProtocolHintFromDeviceName$1(name) {
69
64
  return /\bpro\s*2\b/i.test(name !== null && name !== void 0 ? name : '') ? 'V2' : undefined;
70
65
  }
@@ -100,11 +95,9 @@ class WebUsbTransport {
100
95
  this.messages = messages;
101
96
  }
102
97
  configureProtocolV2(signedData) {
103
- var _a;
104
98
  this.messagesV2 = parseConfigure$1(signedData);
105
99
  this.protocolV2Sessions.clear();
106
100
  this.protocolV2ReadTimeouts.clear();
107
- (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[WebUsbTransport] Protocol V2 schema configured');
108
101
  }
109
102
  promptDeviceAccess() {
110
103
  return __awaiter(this, void 0, void 0, function* () {
@@ -158,10 +151,6 @@ class WebUsbTransport {
158
151
  commType: 'webusb',
159
152
  };
160
153
  });
161
- for (const dev of onekeyDevices) {
162
- this.Log.debug(`[WebUSB] Device: name="${dev.productName}" serial="${dev.serialNumber}" ` +
163
- `VID=0x${dev.vendorId.toString(16)} PID=0x${dev.productId.toString(16)}`);
164
- }
165
154
  return this.deviceList;
166
155
  });
167
156
  }
@@ -200,14 +189,12 @@ class WebUsbTransport {
200
189
  if (expectedProtocol === 'V1') {
201
190
  if (yield this.probeProtocolV1(path)) {
202
191
  this.deviceProtocol.set(path, 'V1');
203
- this.Log.debug(`[WebUsbTransport] detectProtocol: path=${path} -> V1 (expected)`);
204
192
  return 'V1';
205
193
  }
206
194
  throw this.createProtocolMismatchError(expectedProtocol);
207
195
  }
208
196
  if (expectedProtocol === 'V2') {
209
197
  this.deviceProtocol.set(path, 'V2');
210
- this.Log.debug(`[WebUsbTransport] detectProtocol: path=${path} -> V2 (expected)`);
211
198
  return 'V2';
212
199
  }
213
200
  const probeOrder = protocolHint === 'V2' || this.deviceProtocol.get(path) === 'V2' ? ['V2', 'V1'] : ['V1', 'V2'];
@@ -215,7 +202,6 @@ class WebUsbTransport {
215
202
  const detected = protocol === 'V1' ? yield this.probeProtocolV1(path) : yield this.probeProtocolV2(path);
216
203
  if (detected) {
217
204
  this.deviceProtocol.set(path, protocol);
218
- this.Log.debug(`[WebUsbTransport] detectProtocol: path=${path} -> ${protocol}`);
219
205
  return protocol;
220
206
  }
221
207
  }
@@ -287,7 +273,6 @@ class WebUsbTransport {
287
273
  var _a, _b;
288
274
  return __awaiter(this, void 0, void 0, function* () {
289
275
  let device = yield this.findDevice(path);
290
- this.Log.debug('[WebUsbTransport] connecting to device:', device.productName, 'PID:', device.productId);
291
276
  if (!device.opened) {
292
277
  yield device.open();
293
278
  }
@@ -524,7 +509,7 @@ class WebUsbTransport {
524
509
  yield this.connect(path, false);
525
510
  });
526
511
  }
527
- withProtocolReadTimeout(path, promise, timeoutMs, protocol, onTimeout) {
512
+ withProtocolReadTimeout(_path, promise, timeoutMs, protocol, onTimeout) {
528
513
  return __awaiter(this, void 0, void 0, function* () {
529
514
  let timer;
530
515
  let timedOut = false;
@@ -539,11 +524,11 @@ class WebUsbTransport {
539
524
  return yield Promise.race([
540
525
  guardedPromise,
541
526
  new Promise((_, reject) => {
542
- timer = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
527
+ timer = setTimeout(() => {
543
528
  timedOut = true;
544
529
  onTimeout === null || onTimeout === void 0 ? void 0 : onTimeout();
545
530
  reject(new Error(`Protocol ${protocol} read timeout after ${timeoutMs}ms`));
546
- }), timeoutMs);
531
+ }, timeoutMs);
547
532
  }),
548
533
  ]);
549
534
  }
@@ -562,8 +547,7 @@ class WebUsbTransport {
562
547
  yield this.callProtocolV1(path, 'Initialize', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT });
563
548
  return true;
564
549
  }
565
- catch (error) {
566
- this.Log.debug('[WebUsbTransport] Protocol V1 Initialize probe failed:', error);
550
+ catch (_error) {
567
551
  return false;
568
552
  }
569
553
  });
@@ -595,12 +579,8 @@ class WebUsbTransport {
595
579
  if (!protocol) {
596
580
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol has not been detected for ${path}`);
597
581
  }
598
- if (shouldSuppressWebUsbCallLog(name)) ;
599
- else if (shouldBlockWebUsbCallDataLog(name)) {
600
- this.Log.debug('call-', ' name: ', name, ' protocol: ', protocol);
601
- }
602
- else {
603
- this.Log.debug('call-', ' name: ', name, ' data: ', data, ' protocol: ', protocol);
582
+ if (!shouldSuppressHighVolumeCallLog(name)) {
583
+ this.Log.debug('transport call', createTransportCallLog(name, protocol));
604
584
  }
605
585
  if (protocol === 'V2') {
606
586
  return this.callProtocolV2(path, name, data, options);
@@ -750,15 +730,6 @@ class WebUsbTransport {
750
730
  }
751
731
  }
752
732
 
753
- const FILE_WRITE_LOG_BLOCK_PATTERN = /(?:^|[^a-z])(?:raw)?(?:filesystem|emmc)?filewrite$/i;
754
- function shouldSuppressHighVolumeCallLog(name) {
755
- const normalized = name.replace(/[_\s-]/g, '');
756
- return FILE_WRITE_LOG_BLOCK_PATTERN.test(normalized);
757
- }
758
- function isLogBlockCommand(name) {
759
- var _a, _b;
760
- return (_b = (_a = transport.LogBlockCommand === null || transport.LogBlockCommand === void 0 ? void 0 : transport.LogBlockCommand.has) === null || _a === void 0 ? void 0 : _a.call(transport.LogBlockCommand, name)) !== null && _b !== void 0 ? _b : false;
761
- }
762
733
  const { parseConfigure, ProtocolV1, check } = transport__default["default"];
763
734
  function inferProtocolHintFromDeviceName(name) {
764
735
  return /\bpro\s*2\b/i.test(name !== null && name !== void 0 ? name : '') ? 'V2' : undefined;
@@ -871,12 +842,10 @@ class ElectronBleTransport {
871
842
  this.configured = true;
872
843
  }
873
844
  configureProtocolV2(signedData) {
874
- var _a;
875
845
  this._messagesV2 = parseConfigure(signedData);
876
846
  this.protocolV2Links
877
847
  .invalidateAllLinks('Protocol V2 schema reconfigured')
878
848
  .catch(error => { var _a; return (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] schema link cleanup failed:', error); });
879
- (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] Protocol V2 schema configured');
880
849
  }
881
850
  listen() {
882
851
  return __awaiter(this, void 0, void 0, function* () {
@@ -1281,7 +1250,7 @@ class ElectronBleTransport {
1281
1250
  }
1282
1251
  }
1283
1252
  call(uuid, name, data, options) {
1284
- var _a, _b;
1253
+ var _a;
1285
1254
  return __awaiter(this, void 0, void 0, function* () {
1286
1255
  if (!this._messages) {
1287
1256
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
@@ -1293,12 +1262,8 @@ class ElectronBleTransport {
1293
1262
  if (!protocol) {
1294
1263
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol has not been detected for ${uuid}`);
1295
1264
  }
1296
- if (shouldSuppressHighVolumeCallLog(name)) ;
1297
- else if (isLogBlockCommand(name)) {
1298
- (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] call', 'name:', name, 'protocol:', protocol);
1299
- }
1300
- else {
1301
- (_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug('[Electron BLE] call', 'name:', name, 'data:', data, 'protocol:', protocol);
1265
+ if (!shouldSuppressHighVolumeCallLog(name)) {
1266
+ (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('transport call', createTransportCallLog(name, protocol));
1302
1267
  }
1303
1268
  if (protocol === 'V2') {
1304
1269
  return this.callProtocolV2(uuid, name, data, options);
@@ -0,0 +1,7 @@
1
+ import type { ProtocolType } from '@onekeyfe/hd-transport';
2
+ export declare function shouldSuppressHighVolumeCallLog(name: string): boolean;
3
+ export declare function createTransportCallLog(name: string, protocol: ProtocolType): {
4
+ name: string;
5
+ protocol: ProtocolType;
6
+ };
7
+ //# sourceMappingURL=transportLog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transportLog.d.ts","sourceRoot":"","sources":["../src/transportLog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAI3D,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,WAE3D;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY;;;EAE1E"}
@@ -1 +1 @@
1
- {"version":3,"file":"webusb.d.ts","s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IAkB1C,OAAO,CAAC,iBAAiB;IAiCnB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;YAmCpC,eAAe;YAmBf,iBAAiB;IAezB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIvE,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,wBAAwB;YAalB,yBAAyB;IAiCvC,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,aAAa;YASP,oBAAoB;YA2BpB,eAAe;YAaf,mBAAmB;YA2CnB,yBAAyB;YAyBzB,uBAAuB;YAmCvB,eAAe;YAaf,eAAe;IAiBvB,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;YA8BlB,cAAc;YAkCd,cAAc;YA4Cd,sBAAsB;IA4C9B,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;IAgD5C,OAAO,CAAC,IAAI,EAAE,MAAM;IAiB1B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-web-device",
3
- "version": "1.2.0-alpha.11",
3
+ "version": "1.2.0-alpha.12",
4
4
  "author": "OneKey",
5
5
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
6
6
  "license": "MIT",
@@ -20,13 +20,13 @@
20
20
  "lint:fix": "eslint . --fix"
21
21
  },
22
22
  "dependencies": {
23
- "@onekeyfe/hd-shared": "1.2.0-alpha.11",
24
- "@onekeyfe/hd-transport": "1.2.0-alpha.11"
23
+ "@onekeyfe/hd-shared": "1.2.0-alpha.12",
24
+ "@onekeyfe/hd-transport": "1.2.0-alpha.12"
25
25
  },
26
26
  "devDependencies": {
27
- "@onekeyfe/hd-transport-electron": "1.2.0-alpha.11",
27
+ "@onekeyfe/hd-transport-electron": "1.2.0-alpha.12",
28
28
  "@types/w3c-web-usb": "^1.0.6",
29
29
  "@types/web-bluetooth": "^0.0.17"
30
30
  },
31
- "gitHead": "05d3421ec00e07e99f6665e6436a612503e32dfc"
31
+ "gitHead": "3601e8003c96a2a4ca7856e865d16f48c0c5b758"
32
32
  }
@@ -1,5 +1,4 @@
1
1
  import transport, {
2
- LogBlockCommand,
3
2
  PROTOCOL_V1_MESSAGE_HEADER_SIZE,
4
3
  PROTOCOL_V2_CHANNEL_BLE_UART,
5
4
  ProtocolV2FrameAssembler,
@@ -17,22 +16,13 @@ import {
17
16
  wait,
18
17
  } from '@onekeyfe/hd-shared';
19
18
 
19
+ import { createTransportCallLog, shouldSuppressHighVolumeCallLog } from './transportLog';
20
+
20
21
  import type { Deferred } from '@onekeyfe/hd-shared';
21
22
  import type { DesktopAPI } from '@onekeyfe/hd-transport-electron';
22
23
  import type { OneKeyDeviceInfo, ProtocolType, TransportCallOptions } from '@onekeyfe/hd-transport';
23
24
  import type EventEmitter from 'events';
24
25
 
25
- const FILE_WRITE_LOG_BLOCK_PATTERN = /(?:^|[^a-z])(?:raw)?(?:filesystem|emmc)?filewrite$/i;
26
-
27
- function shouldSuppressHighVolumeCallLog(name: string) {
28
- const normalized = name.replace(/[_\s-]/g, '');
29
- return FILE_WRITE_LOG_BLOCK_PATTERN.test(normalized);
30
- }
31
-
32
- function isLogBlockCommand(name: string) {
33
- return (LogBlockCommand as Set<string> | undefined)?.has?.(name) ?? false;
34
- }
35
-
36
26
  const { parseConfigure, ProtocolV1, check } = transport;
37
27
 
38
28
  declare global {
@@ -221,7 +211,6 @@ export default class ElectronBleTransport {
221
211
  this.protocolV2Links
222
212
  .invalidateAllLinks('Protocol V2 schema reconfigured')
223
213
  .catch(error => this.Log?.debug('[Electron BLE] schema link cleanup failed:', error));
224
- this.Log?.debug('[Electron BLE] Protocol V2 schema configured');
225
214
  }
226
215
 
227
216
  async listen() {
@@ -682,12 +671,8 @@ export default class ElectronBleTransport {
682
671
  `Device protocol has not been detected for ${uuid}`
683
672
  );
684
673
  }
685
- if (shouldSuppressHighVolumeCallLog(name)) {
686
- // 高频文件写入不要逐包发 debug 事件,否则调试日志会反向拖慢传输。
687
- } else if (isLogBlockCommand(name)) {
688
- this.Log?.debug('[Electron BLE] call', 'name:', name, 'protocol:', protocol);
689
- } else {
690
- this.Log?.debug('[Electron BLE] call', 'name:', name, 'data:', data, 'protocol:', protocol);
674
+ if (!shouldSuppressHighVolumeCallLog(name)) {
675
+ this.Log?.debug('transport call', createTransportCallLog(name, protocol));
691
676
  }
692
677
 
693
678
  if (protocol === 'V2') {
@@ -0,0 +1,11 @@
1
+ import type { ProtocolType } from '@onekeyfe/hd-transport';
2
+
3
+ const HIGH_VOLUME_CALLS = new Set(['FileWrite', 'FilesystemFileWrite', 'EmmcFileWrite']);
4
+
5
+ export function shouldSuppressHighVolumeCallLog(name: string) {
6
+ return HIGH_VOLUME_CALLS.has(name);
7
+ }
8
+
9
+ export function createTransportCallLog(name: string, protocol: ProtocolType) {
10
+ return { name, protocol };
11
+ }
package/src/webusb.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable no-undef */
2
2
  import transport, {
3
- LogBlockCommand,
4
3
  PROTOCOL_V1_CHUNK_PAYLOAD_SIZE,
5
4
  PROTOCOL_V1_MESSAGE_HEADER_SIZE,
6
5
  PROTOCOL_V1_REPORT_ID,
@@ -14,6 +13,8 @@ import transport, {
14
13
  import { ERRORS, HardwareErrorCode, ONEKEY_WEBUSB_FILTER, wait } from '@onekeyfe/hd-shared';
15
14
  import ByteBuffer from 'bytebuffer';
16
15
 
16
+ import { createTransportCallLog, shouldSuppressHighVolumeCallLog } from './transportLog';
17
+
17
18
  import type {
18
19
  AcquireInput,
19
20
  OneKeyDeviceInfoBase,
@@ -33,22 +34,6 @@ const HEADER_LENGTH = PROTOCOL_V1_MESSAGE_HEADER_SIZE;
33
34
  const PACKET_IO_MAX_RETRIES = 3;
34
35
  const PACKET_IO_RETRY_DELAY = 300;
35
36
  const PROTOCOL_PROBE_TIMEOUT = 1000;
36
- const WEBUSB_FILE_WRITE_LOG_BLOCK_PATTERN = /(?:^|[^a-z])(?:raw)?(?:filesystem|emmc)?filewrite$/i;
37
-
38
- function shouldSuppressWebUsbCallLog(name: string) {
39
- const normalized = name.replace(/[_\s-]/g, '');
40
- return WEBUSB_FILE_WRITE_LOG_BLOCK_PATTERN.test(normalized);
41
- }
42
-
43
- function isLogBlockCommand(name: string) {
44
- return (LogBlockCommand as Set<string> | undefined)?.has?.(name) ?? false;
45
- }
46
-
47
- function shouldBlockWebUsbCallDataLog(name: string) {
48
- const normalized = name.replace(/[_\s-]/g, '');
49
- return isLogBlockCommand(name) || WEBUSB_FILE_WRITE_LOG_BLOCK_PATTERN.test(normalized);
50
- }
51
-
52
37
  function inferProtocolHintFromDeviceName(name?: string | null): ProtocolType | undefined {
53
38
  return /\bpro\s*2\b/i.test(name ?? '') ? 'V2' : undefined;
54
39
  }
@@ -159,7 +144,6 @@ export default class WebUsbTransport {
159
144
  this.messagesV2 = parseConfigure(signedData);
160
145
  this.protocolV2Sessions.clear();
161
146
  this.protocolV2ReadTimeouts.clear();
162
- this.Log?.debug('[WebUsbTransport] Protocol V2 schema configured');
163
147
  }
164
148
 
165
149
  /**
@@ -238,14 +222,6 @@ export default class WebUsbTransport {
238
222
  };
239
223
  });
240
224
 
241
- // Debug: log all discovered devices. Protocol is detected after acquire via wire probe.
242
- for (const dev of onekeyDevices) {
243
- this.Log.debug(
244
- `[WebUSB] Device: name="${dev.productName}" serial="${dev.serialNumber}" ` +
245
- `VID=0x${dev.vendorId.toString(16)} PID=0x${dev.productId.toString(16)}`
246
- );
247
- }
248
-
249
225
  return this.deviceList;
250
226
  }
251
227
 
@@ -300,7 +276,6 @@ export default class WebUsbTransport {
300
276
  if (expectedProtocol === 'V1') {
301
277
  if (await this.probeProtocolV1(path)) {
302
278
  this.deviceProtocol.set(path, 'V1');
303
- this.Log.debug(`[WebUsbTransport] detectProtocol: path=${path} -> V1 (expected)`);
304
279
  return 'V1';
305
280
  }
306
281
  throw this.createProtocolMismatchError(expectedProtocol);
@@ -310,7 +285,6 @@ export default class WebUsbTransport {
310
285
  // 免探测路径:调用方显式承诺该设备是 V2(例如固件升级重启后的重连场景,
311
286
  // 上层已经探测过协议并通过 expectedProtocol 传回),这里不再重复探测。
312
287
  this.deviceProtocol.set(path, 'V2');
313
- this.Log.debug(`[WebUsbTransport] detectProtocol: path=${path} -> V2 (expected)`);
314
288
  return 'V2';
315
289
  }
316
290
 
@@ -325,7 +299,6 @@ export default class WebUsbTransport {
325
299
  protocol === 'V1' ? await this.probeProtocolV1(path) : await this.probeProtocolV2(path);
326
300
  if (detected) {
327
301
  this.deviceProtocol.set(path, protocol);
328
- this.Log.debug(`[WebUsbTransport] detectProtocol: path=${path} -> ${protocol}`);
329
302
  return protocol;
330
303
  }
331
304
  }
@@ -414,13 +387,6 @@ export default class WebUsbTransport {
414
387
  */
415
388
  async connectToDevice(path: string, first: boolean) {
416
389
  let device: USBDevice = await this.findDevice(path);
417
- this.Log.debug(
418
- '[WebUsbTransport] connecting to device:',
419
- device.productName,
420
- 'PID:',
421
- device.productId
422
- );
423
-
424
390
  if (!device.opened) {
425
391
  await device.open();
426
392
  }
@@ -676,13 +642,12 @@ export default class WebUsbTransport {
676
642
  }
677
643
 
678
644
  private async withProtocolReadTimeout<T>(
679
- path: string,
645
+ _path: string,
680
646
  promise: Promise<T>,
681
647
  timeoutMs: number,
682
648
  protocol: ProtocolType,
683
649
  onTimeout?: () => void
684
650
  ): Promise<T> {
685
- void path;
686
651
  let timer: ReturnType<typeof setTimeout> | undefined;
687
652
  let timedOut = false;
688
653
  const waitForeverAfterTimeout = () => new Promise<never>(() => {});
@@ -699,7 +664,7 @@ export default class WebUsbTransport {
699
664
  return await Promise.race([
700
665
  guardedPromise,
701
666
  new Promise<never>((_, reject) => {
702
- timer = setTimeout(async () => {
667
+ timer = setTimeout(() => {
703
668
  timedOut = true;
704
669
  onTimeout?.();
705
670
  reject(new Error(`Protocol ${protocol} read timeout after ${timeoutMs}ms`));
@@ -719,8 +684,7 @@ export default class WebUsbTransport {
719
684
  try {
720
685
  await this.callProtocolV1(path, 'Initialize', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT });
721
686
  return true;
722
- } catch (error) {
723
- this.Log.debug('[WebUsbTransport] Protocol V1 Initialize probe failed:', error);
687
+ } catch (_error) {
724
688
  return false;
725
689
  }
726
690
  }
@@ -765,12 +729,8 @@ export default class WebUsbTransport {
765
729
  );
766
730
  }
767
731
 
768
- if (shouldSuppressWebUsbCallLog(name)) {
769
- // 高频文件写入不要逐包发 debug 事件,否则浏览器侧会被日志处理拖慢。
770
- } else if (shouldBlockWebUsbCallDataLog(name)) {
771
- this.Log.debug('call-', ' name: ', name, ' protocol: ', protocol);
772
- } else {
773
- this.Log.debug('call-', ' name: ', name, ' data: ', data, ' protocol: ', protocol);
732
+ if (!shouldSuppressHighVolumeCallLog(name)) {
733
+ this.Log.debug('transport call', createTransportCallLog(name, protocol));
774
734
  }
775
735
 
776
736
  if (protocol === 'V2') {