@onekeyfe/hd-transport-electron 1.2.8-alpha.2 → 1.2.8-alpha.3

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.
@@ -55,13 +55,13 @@ function invokeNobleBleIpc(request) {
55
55
 
56
56
  function initNobleBleSupport(webContents) {
57
57
  return __awaiter(this, void 0, void 0, function* () {
58
- const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-043a7c23.js'); });
58
+ const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-688faeb6.js'); });
59
59
  setupNobleBleHandlers(webContents);
60
60
  });
61
61
  }
62
62
  function disposeNobleBleSupport(releaseNoble) {
63
63
  return __awaiter(this, void 0, void 0, function* () {
64
- const handler = yield Promise.resolve().then(function () { return require('./noble-ble-handler-043a7c23.js'); });
64
+ const handler = yield Promise.resolve().then(function () { return require('./noble-ble-handler-688faeb6.js'); });
65
65
  yield handler.disposeNobleBleSupport(releaseNoble);
66
66
  });
67
67
  }
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-5135e7b9.js');
5
+ var index = require('./index-98d6f724.js');
6
6
 
7
7
 
8
8
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-5135e7b9.js');
3
+ var index = require('./index-98d6f724.js');
4
4
  var hdShared = require('@onekeyfe/hd-shared');
5
5
  var pRetry = require('p-retry');
6
6
 
@@ -418,7 +418,7 @@ function initializeNoble() {
418
418
  }
419
419
  else if (state === 'unauthorized') {
420
420
  cleanup();
421
- reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError));
421
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleLocationError));
422
422
  }
423
423
  };
424
424
  const cancel = () => {
@@ -427,6 +427,7 @@ function initializeNoble() {
427
427
  };
428
428
  pendingCancellations.add(cancel);
429
429
  noble.on('stateChange', onStateChange);
430
+ onStateChange(noble.state);
430
431
  });
431
432
  assertBleActive();
432
433
  if (!persistentDiscoverListener) {
@@ -439,7 +440,7 @@ function initializeNoble() {
439
440
  }
440
441
  catch (error) {
441
442
  logger === null || logger === void 0 ? void 0 : logger.error('[NobleBLE] Failed to initialize Noble:', error);
442
- bluetoothState.unsupported = true;
443
+ bluetoothState.unsupported = (noble === null || noble === void 0 ? void 0 : noble.state) === 'unsupported';
443
444
  bluetoothState.initialized = true;
444
445
  throw error;
445
446
  }
@@ -1 +1 @@
1
- {"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAA+B,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,KAAK,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAiC1F,KAAK,mBAAmB,GAAG,KAAK,GAAG;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,mBAAmB,EAAE,aAAa,SAAK,+CAG3F;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,OAAO,GAAG,wBAAwB,CAgCvF;AA+KD,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE,oBAAoB,UAI7E;AAgzDD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAkOpE;AAOD,wBAAgB,sBAAsB,CACpC,YAAY,GAAE,CAAC,QAAQ,EAAE;IAAE,IAAI,IAAI,IAAI,CAAA;CAAE,KAAK,IAAkC,GAC/E,OAAO,CAAC,IAAI,CAAC,CAiEf"}
1
+ {"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAA+B,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,KAAK,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAiC1F,KAAK,mBAAmB,GAAG,KAAK,GAAG;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,mBAAmB,EAAE,aAAa,SAAK,+CAG3F;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,OAAO,GAAG,wBAAwB,CAgCvF;AA+KD,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE,oBAAoB,UAI7E;AAizDD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAkOpE;AAOD,wBAAgB,sBAAsB,CACpC,YAAY,GAAE,CAAC,QAAQ,EAAE;IAAE,IAAI,IAAI,IAAI,CAAA;CAAE,KAAK,IAAkC,GAC/E,OAAO,CAAC,IAAI,CAAC,CAiEf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-electron",
3
- "version": "1.2.8-alpha.2",
3
+ "version": "1.2.8-alpha.3",
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.8-alpha.2",
29
- "@onekeyfe/hd-shared": "1.2.8-alpha.2",
30
- "@onekeyfe/hd-transport": "1.2.8-alpha.2",
28
+ "@onekeyfe/hd-core": "1.2.8-alpha.3",
29
+ "@onekeyfe/hd-shared": "1.2.8-alpha.3",
30
+ "@onekeyfe/hd-transport": "1.2.8-alpha.3",
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": "74ac64464df3806ef44ad54d313378754c3eaed2"
39
+ "gitHead": "18c57239359413a079fffa730b36149c8516aa85"
40
40
  }
@@ -918,6 +918,28 @@ describe('Noble BLE process shutdown', () => {
918
918
  expect(handlers.size).toBe(0);
919
919
  });
920
920
 
921
+ test.each([
922
+ ['poweredOff', HardwareErrorCode.BlePoweredOff],
923
+ ['unauthorized', HardwareErrorCode.BleLocationError],
924
+ ['unsupported', HardwareErrorCode.BleUnsupported],
925
+ ])(
926
+ 'classifies the initial adapter state %s without waiting for another event',
927
+ async (state, errorCode) => {
928
+ jest.useFakeTimers({ doNotFake: ['performance'] });
929
+ const { sdk, native, handlers } = await setup(state);
930
+ await expect(
931
+ handlers.get(EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE)?.({})
932
+ ).resolves.toMatchObject({
933
+ success: false,
934
+ error: { errorCode },
935
+ });
936
+ expect(native.startScanning).not.toHaveBeenCalled();
937
+ expect(native.listenerCount('stateChange')).toBe(1);
938
+ expect(jest.getTimerCount()).toBe(0);
939
+ await sdk.disposeNobleBleSupport();
940
+ }
941
+ );
942
+
921
943
  test('cancels an active scan, ignores its late callback and releases native once', async () => {
922
944
  jest.useFakeTimers({ doNotFake: ['performance'] });
923
945
  const { sdk, native, handlers } = await setup();
@@ -482,7 +482,7 @@ async function initializeNoble(): Promise<void> {
482
482
  reject(ERRORS.TypedError(HardwareErrorCode.BlePoweredOff));
483
483
  } else if (state === 'unauthorized') {
484
484
  cleanup();
485
- reject(ERRORS.TypedError(HardwareErrorCode.BlePermissionError));
485
+ reject(ERRORS.TypedError(HardwareErrorCode.BleLocationError));
486
486
  }
487
487
  };
488
488
 
@@ -494,6 +494,7 @@ async function initializeNoble(): Promise<void> {
494
494
  };
495
495
  pendingCancellations.add(cancel);
496
496
  noble.on('stateChange', onStateChange);
497
+ onStateChange(noble.state);
497
498
  });
498
499
 
499
500
  assertBleActive();
@@ -508,7 +509,7 @@ async function initializeNoble(): Promise<void> {
508
509
  logger?.info('[NobleBLE] Noble initialized successfully');
509
510
  } catch (error) {
510
511
  logger?.error('[NobleBLE] Failed to initialize Noble:', error);
511
- bluetoothState.unsupported = true;
512
+ bluetoothState.unsupported = noble?.state === 'unsupported';
512
513
  bluetoothState.initialized = true;
513
514
  throw error;
514
515
  }