@onekeyfe/hd-transport-electron 1.2.0-alpha.175 → 1.2.0-alpha.177

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.
@@ -32,7 +32,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
32
32
 
33
33
  function initNobleBleSupport(webContents) {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
- const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-0fb76826.js'); });
35
+ const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-4ab8a151.js'); });
36
36
  setupNobleBleHandlers(webContents);
37
37
  });
38
38
  }
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-2b9e4f42.js');
5
+ var index = require('./index-d72435df.js');
6
6
 
7
7
 
8
8
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-2b9e4f42.js');
3
+ var index = require('./index-d72435df.js');
4
4
  var hdShared = require('@onekeyfe/hd-shared');
5
5
  var pRetry = require('p-retry');
6
6
 
@@ -609,6 +609,7 @@ function transmitHexDataToDevice(deviceId, hexData, options) {
609
609
  });
610
610
  }
611
611
  const BLE_COLD_CONNECT_SCAN_TIMEOUT_MS = 1500;
612
+ const SERVICE_DISCOVERY_MAX_ATTEMPTS = 2;
612
613
  const bleNamesById = new Map();
613
614
  function rememberBleName(deviceId, name) {
614
615
  const trimmed = name === null || name === void 0 ? void 0 : name.trim();
@@ -966,11 +967,11 @@ function discoverServicesAndCharacteristicsWithRetry(peripheral, deviceId) {
966
967
  deviceId,
967
968
  peripheralState: peripheral.state,
968
969
  attempt: attemptNumber,
969
- maxRetries: 5,
970
+ maxRetries: SERVICE_DISCOVERY_MAX_ATTEMPTS,
970
971
  targetUUIDs: ONEKEY_SERVICE_UUIDS,
971
972
  });
972
973
  if (attemptNumber > 1) {
973
- logger === null || logger === void 0 ? void 0 : logger.info(`[NobleBLE] Service discovery retry attempt ${attemptNumber}/5`);
974
+ logger === null || logger === void 0 ? void 0 : logger.info(`[NobleBLE] Service discovery retry attempt ${attemptNumber}/${SERVICE_DISCOVERY_MAX_ATTEMPTS}`);
974
975
  }
975
976
  if (peripheral.state !== 'connected') {
976
977
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, `Device not connected: ${peripheral.state}`);
@@ -979,16 +980,16 @@ function discoverServicesAndCharacteristicsWithRetry(peripheral, deviceId) {
979
980
  return yield discoverServicesAndCharacteristics(peripheral);
980
981
  }
981
982
  catch (error) {
982
- logger === null || logger === void 0 ? void 0 : logger.error(`[NobleBLE] No services found (attempt ${attemptNumber}/5)`);
983
- if (attemptNumber < 5) {
984
- logger === null || logger === void 0 ? void 0 : logger.error(`[NobleBLE] Will retry service discovery (attempt ${attemptNumber + 1}/5)`);
983
+ logger === null || logger === void 0 ? void 0 : logger.error(`[NobleBLE] No services found (attempt ${attemptNumber}/${SERVICE_DISCOVERY_MAX_ATTEMPTS})`);
984
+ if (attemptNumber < SERVICE_DISCOVERY_MAX_ATTEMPTS) {
985
+ logger === null || logger === void 0 ? void 0 : logger.error(`[NobleBLE] Will retry service discovery (attempt ${attemptNumber + 1}/${SERVICE_DISCOVERY_MAX_ATTEMPTS})`);
985
986
  }
986
987
  throw error;
987
988
  }
988
989
  }), {
989
- retries: 4,
990
+ retries: SERVICE_DISCOVERY_MAX_ATTEMPTS - 1,
990
991
  factor: 1.5,
991
- minTimeout: 1000,
992
+ minTimeout: 500,
992
993
  maxTimeout: 3000,
993
994
  onFailedAttempt: error => {
994
995
  logger === null || logger === void 0 ? void 0 : logger.error(`[NobleBLE] Service discovery attempt ${error.attemptNumber} failed:`, {
@@ -1 +1 @@
1
- {"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAA+B,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAoFhE,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE,oBAAoB,UAI7E;AA+tDD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAkMpE"}
1
+ {"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAA+B,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAoFhE,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE,oBAAoB,UAI7E;AAgvDD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAkMpE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-electron",
3
- "version": "1.2.0-alpha.175",
3
+ "version": "1.2.0-alpha.177",
4
4
  "author": "OneKey",
5
5
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
6
6
  "license": "MIT",
@@ -25,9 +25,9 @@
25
25
  "electron-log": ">=4.0.0"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-core": "1.2.0-alpha.175",
29
- "@onekeyfe/hd-shared": "1.2.0-alpha.175",
30
- "@onekeyfe/hd-transport": "1.2.0-alpha.175",
28
+ "@onekeyfe/hd-core": "1.2.0-alpha.177",
29
+ "@onekeyfe/hd-shared": "1.2.0-alpha.177",
30
+ "@onekeyfe/hd-transport": "1.2.0-alpha.177",
31
31
  "@stoprocent/noble": "2.3.16",
32
32
  "p-retry": "^4.6.2"
33
33
  },
@@ -36,5 +36,5 @@
36
36
  "electron": "^25.0.0",
37
37
  "typescript": "^5.3.3"
38
38
  },
39
- "gitHead": "b2cb2451bd3a56b219d18e0078597b316dbc3ba7"
39
+ "gitHead": "294d4c3ce64a2036742447bcfada14eee6c9591e"
40
40
  }
@@ -807,6 +807,9 @@ async function transmitHexDataToDevice(
807
807
  // 631ms, so this leaves ~2x headroom while keeping a miss cheap.
808
808
  const BLE_COLD_CONNECT_SCAN_TIMEOUT_MS = 1500;
809
809
 
810
+ // Attempts before a link is written off as unable to serve the OneKey service.
811
+ const SERVICE_DISCOVERY_MAX_ATTEMPTS = 2;
812
+
810
813
  // Advertised names, kept for the life of the process: device caches are purged
811
814
  // on every disconnect, but the family a device belongs to never changes and
812
815
  // decides which connection strategy is safe for it.
@@ -1336,12 +1339,14 @@ async function discoverServicesAndCharacteristicsWithRetry(
1336
1339
  deviceId,
1337
1340
  peripheralState: peripheral.state,
1338
1341
  attempt: attemptNumber,
1339
- maxRetries: 5,
1342
+ maxRetries: SERVICE_DISCOVERY_MAX_ATTEMPTS,
1340
1343
  targetUUIDs: ONEKEY_SERVICE_UUIDS,
1341
1344
  });
1342
1345
 
1343
1346
  if (attemptNumber > 1) {
1344
- logger?.info(`[NobleBLE] Service discovery retry attempt ${attemptNumber}/5`);
1347
+ logger?.info(
1348
+ `[NobleBLE] Service discovery retry attempt ${attemptNumber}/${SERVICE_DISCOVERY_MAX_ATTEMPTS}`
1349
+ );
1345
1350
  }
1346
1351
 
1347
1352
  // Verify connection state before attempting service discovery
@@ -1355,20 +1360,32 @@ async function discoverServicesAndCharacteristicsWithRetry(
1355
1360
  try {
1356
1361
  return await discoverServicesAndCharacteristics(peripheral);
1357
1362
  } catch (error) {
1358
- logger?.error(`[NobleBLE] No services found (attempt ${attemptNumber}/5)`);
1363
+ logger?.error(
1364
+ `[NobleBLE] No services found (attempt ${attemptNumber}/${SERVICE_DISCOVERY_MAX_ATTEMPTS})`
1365
+ );
1359
1366
 
1360
- if (attemptNumber < 5) {
1361
- logger?.error(`[NobleBLE] Will retry service discovery (attempt ${attemptNumber + 1}/5)`);
1367
+ if (attemptNumber < SERVICE_DISCOVERY_MAX_ATTEMPTS) {
1368
+ logger?.error(
1369
+ `[NobleBLE] Will retry service discovery (attempt ${
1370
+ attemptNumber + 1
1371
+ }/${SERVICE_DISCOVERY_MAX_ATTEMPTS})`
1372
+ );
1362
1373
  }
1363
1374
 
1364
1375
  throw error; // p-retry will handle the retry logic
1365
1376
  }
1366
1377
  },
1367
1378
  {
1368
- retries: 4, // Total 5 attempts (initial + 4 retries)
1369
- factor: 1.5, // Exponential backoff: 1000ms 1500ms 2250ms 3000ms
1370
- minTimeout: 1000, // Start with 1 second delay
1371
- maxTimeout: 3000, // Maximum 3 seconds delay
1379
+ // One retry, not four. An empty result here is the signature of a device
1380
+ // whose stack no longer serves its application layer, and retrying the
1381
+ // same link has never recovered it — every observed run failed all the
1382
+ // way through. The recovery is the teardown and cold reconnect the caller
1383
+ // performs afterwards, so reaching it sooner is what shortens the wait.
1384
+ // The single retry stays for a genuinely transient miss.
1385
+ retries: SERVICE_DISCOVERY_MAX_ATTEMPTS - 1,
1386
+ factor: 1.5,
1387
+ minTimeout: 500,
1388
+ maxTimeout: 3000,
1372
1389
  onFailedAttempt: error => {
1373
1390
  // This runs after each failed attempt
1374
1391
  logger?.error(`[NobleBLE] Service discovery attempt ${error.attemptNumber} failed:`, {