@onekeyfe/hd-transport-electron 1.2.0-alpha.161 → 1.2.0-alpha.163

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-e87ba8bc.js'); });
35
+ const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-8b4037fe.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-fea7f7d5.js');
5
+ var index = require('./index-b18020df.js');
6
6
 
7
7
 
8
8
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-fea7f7d5.js');
3
+ var index = require('./index-b18020df.js');
4
4
  var hdShared = require('@onekeyfe/hd-shared');
5
5
  var pRetry = require('p-retry');
6
6
 
@@ -1046,7 +1046,7 @@ function tryDirectConnectById(deviceId) {
1046
1046
  });
1047
1047
  }
1048
1048
  function connectDevice(deviceId, webContents) {
1049
- var _a;
1049
+ var _a, _b;
1050
1050
  return index.__awaiter(this, void 0, void 0, function* () {
1051
1051
  logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Connect device request:', {
1052
1052
  deviceId,
@@ -1058,29 +1058,28 @@ function connectDevice(deviceId, webContents) {
1058
1058
  });
1059
1059
  let peripheral = (_a = discoveredDevices.get(deviceId)) !== null && _a !== void 0 ? _a : connectedDevices.get(deviceId);
1060
1060
  if (!peripheral) {
1061
- logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Device not discovered, attempting targeted scan for:', deviceId);
1062
1061
  if (!noble) {
1063
1062
  yield initializeNoble();
1064
1063
  }
1065
1064
  if (!noble) {
1066
1065
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Noble not available');
1067
1066
  }
1068
- peripheral = yield tryDirectConnectById(deviceId);
1069
- if (peripheral) {
1070
- discoveredDevices.set(deviceId, peripheral);
1071
- }
1072
- }
1073
- if (!peripheral) {
1067
+ logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Device not cached, scanning for:', deviceId);
1074
1068
  try {
1075
- const foundPeripheral = yield performTargetedScan(deviceId);
1076
- if (!foundPeripheral) {
1077
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Device ${deviceId} not found even after targeted scan`);
1078
- }
1079
- peripheral = foundPeripheral;
1069
+ peripheral = (_b = (yield performTargetedScan(deviceId))) !== null && _b !== void 0 ? _b : undefined;
1080
1070
  }
1081
- catch (error) {
1082
- logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Targeted scan failed:', error);
1083
- throw error;
1071
+ catch (scanError) {
1072
+ logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Targeted scan failed, falling back to direct connect', {
1073
+ deviceId,
1074
+ error: scanError instanceof Error ? scanError.message : String(scanError),
1075
+ });
1076
+ }
1077
+ if (!peripheral) {
1078
+ logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Device not advertising, attempting direct connect by id:', deviceId);
1079
+ peripheral = yield tryDirectConnectById(deviceId);
1080
+ if (peripheral) {
1081
+ discoveredDevices.set(deviceId, peripheral);
1082
+ }
1084
1083
  }
1085
1084
  }
1086
1085
  if (!peripheral) {
@@ -1 +1 @@
1
- {"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AA+BA,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;AAuoDD,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":"AA+BA,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;AAwoDD,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.161",
3
+ "version": "1.2.0-alpha.163",
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.161",
29
- "@onekeyfe/hd-shared": "1.2.0-alpha.161",
30
- "@onekeyfe/hd-transport": "1.2.0-alpha.161",
28
+ "@onekeyfe/hd-core": "1.2.0-alpha.163",
29
+ "@onekeyfe/hd-shared": "1.2.0-alpha.163",
30
+ "@onekeyfe/hd-transport": "1.2.0-alpha.163",
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": "06316117fc9a7ebaecea1ca583b2d105709361bf"
39
+ "gitHead": "afed1c82345fc277cadf49677ab8371e6c6f3f9a"
40
40
  }
@@ -1444,10 +1444,7 @@ async function connectDevice(deviceId: string, webContents: WebContents): Promis
1444
1444
  // enumerate clears the discovery map; a kept-alive link outlives it.
1445
1445
  let peripheral = discoveredDevices.get(deviceId) ?? connectedDevices.get(deviceId);
1446
1446
 
1447
- // If device not discovered, try a targeted scan for this specific device
1448
1447
  if (!peripheral) {
1449
- logger?.info('[NobleBLE] Device not discovered, attempting targeted scan for:', deviceId);
1450
-
1451
1448
  // Initialize Noble if not already done
1452
1449
  if (!noble) {
1453
1450
  await initializeNoble();
@@ -1457,27 +1454,31 @@ async function connectDevice(deviceId: string, webContents: WebContents): Promis
1457
1454
  throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Noble not available');
1458
1455
  }
1459
1456
 
1460
- // Reaches a bonded device that is not advertising; else falls to the scan.
1461
- peripheral = await tryDirectConnectById(deviceId);
1462
- if (peripheral) {
1463
- discoveredDevices.set(deviceId, peripheral);
1457
+ // Scan before connecting by id. A live advertisement proves the device
1458
+ // holds no link and will open a fresh session, and it is how 6.5.0 reached
1459
+ // every cold connect (control logs: found in ~52ms, 16/16 sessions
1460
+ // answered within ~1s). Connecting by id resolves through the OS cache
1461
+ // instead: on a Classic 1S that can hand back a session the device no
1462
+ // longer serves, where the link comes up and GATT resolves from cache but
1463
+ // the device answers no protocol traffic at all.
1464
+ logger?.info('[NobleBLE] Device not cached, scanning for:', deviceId);
1465
+ try {
1466
+ peripheral = (await performTargetedScan(deviceId)) ?? undefined;
1467
+ } catch (scanError) {
1468
+ logger?.info('[NobleBLE] Targeted scan failed, falling back to direct connect', {
1469
+ deviceId,
1470
+ error: scanError instanceof Error ? scanError.message : String(scanError),
1471
+ });
1464
1472
  }
1465
- }
1466
1473
 
1467
- if (!peripheral) {
1468
- // Perform a targeted scan to find the specific device
1469
- try {
1470
- const foundPeripheral = await performTargetedScan(deviceId);
1471
- if (!foundPeripheral) {
1472
- throw ERRORS.TypedError(
1473
- HardwareErrorCode.DeviceNotFound,
1474
- `Device ${deviceId} not found even after targeted scan`
1475
- );
1474
+ if (!peripheral) {
1475
+ // Not advertising: held by another host, or bonded and silent. Connect
1476
+ // by id is then the only way in.
1477
+ logger?.info('[NobleBLE] Device not advertising, attempting direct connect by id:', deviceId);
1478
+ peripheral = await tryDirectConnectById(deviceId);
1479
+ if (peripheral) {
1480
+ discoveredDevices.set(deviceId, peripheral);
1476
1481
  }
1477
- peripheral = foundPeripheral;
1478
- } catch (error) {
1479
- logger?.error('[NobleBLE] Targeted scan failed:', error);
1480
- throw error;
1481
1482
  }
1482
1483
  }
1483
1484