@onekeyfe/hd-transport-web-device 1.2.11-alpha.19 → 1.2.11-alpha.20

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.
package/dist/index.js CHANGED
@@ -1524,34 +1524,6 @@ const BLE_PACKET_SIZE_MAXIMUM = 244;
1524
1524
  const BLE_WRITE_DELAY_MS = 5;
1525
1525
  const PROTOCOL_PROBE_TIMEOUT_MS = 3000;
1526
1526
  const PROTOCOL_V2_PROBE_TIMEOUT_MS = 5000;
1527
- const shouldRethrowElectronProtocolProbeError = (error) => {
1528
- if (transport.isProtocolV2LinkDisabledError(error)) {
1529
- return true;
1530
- }
1531
- const code = error === null || error === void 0 ? void 0 : error.errorCode;
1532
- return (code === hdShared.HardwareErrorCode.TransportCallInProgress ||
1533
- code === hdShared.HardwareErrorCode.BleConnectedError ||
1534
- code === hdShared.HardwareErrorCode.BleDeviceNotBonded ||
1535
- code === hdShared.HardwareErrorCode.BleDeviceBondedCanceled ||
1536
- code === hdShared.HardwareErrorCode.BleDeviceDisconnected ||
1537
- code === hdShared.HardwareErrorCode.BleCharacteristicNotFound ||
1538
- code === hdShared.HardwareErrorCode.BleCharacteristicNotifyError ||
1539
- code === hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure ||
1540
- code === hdShared.HardwareErrorCode.BleServiceNotFound ||
1541
- code === hdShared.HardwareErrorCode.BlePoweredOff ||
1542
- code === hdShared.HardwareErrorCode.BleUnsupported ||
1543
- code === hdShared.HardwareErrorCode.BleLocationError);
1544
- };
1545
- const isUnstartedElectronWakeError = (error) => {
1546
- var _a;
1547
- const candidate = error;
1548
- const code = candidate === null || candidate === void 0 ? void 0 : candidate.errorCode;
1549
- return (((_a = candidate === null || candidate === void 0 ? void 0 : candidate.params) === null || _a === void 0 ? void 0 : _a.writeRejected) === true ||
1550
- code === hdShared.HardwareErrorCode.BleCharacteristicNotFound ||
1551
- code === hdShared.HardwareErrorCode.BlePoweredOff ||
1552
- code === hdShared.HardwareErrorCode.BleUnsupported ||
1553
- code === hdShared.HardwareErrorCode.BleLocationError);
1554
- };
1555
1527
  class ElectronBleTransport {
1556
1528
  constructor() {
1557
1529
  this.name = 'ElectronBleTransport';
@@ -1565,11 +1537,6 @@ class ElectronBleTransport {
1565
1537
  this.stopped = false;
1566
1538
  this.deviceProtocol = new Map();
1567
1539
  this.deviceProtocolHints = new Map();
1568
- this.silentDetections = new Map();
1569
- this.probeResponseTimeoutErrors = new WeakSet();
1570
- this.lastV1ProbeFailedWithoutTimeout = new Set();
1571
- this.acquireGenerations = new Map();
1572
- this.nextAcquireGeneration = 1;
1573
1540
  this.deviceMtus = new Map();
1574
1541
  this.devicePacketCapacities = new Map();
1575
1542
  this.v1Buffers = new Map();
@@ -1652,7 +1619,6 @@ class ElectronBleTransport {
1652
1619
  this.devicePacketCapacities.delete(deviceId);
1653
1620
  this.v1Buffers.delete(deviceId);
1654
1621
  this.v2Assemblers.delete(deviceId);
1655
- this.lastV1ProbeFailedWithoutTimeout.delete(deviceId);
1656
1622
  this.resetProtocolV2Frames(deviceId);
1657
1623
  this.notificationTokens.delete(deviceId);
1658
1624
  if (this.runPromise && this.runPromiseDeviceId === deviceId) {
@@ -1712,10 +1678,7 @@ class ElectronBleTransport {
1712
1678
  ]);
1713
1679
  yield Promise.all(Array.from(trackedDeviceIds, deviceId => this.releaseNative(deviceId)));
1714
1680
  this.acquiringDevices.clear();
1715
- this.acquireGenerations.clear();
1716
- this.lastV1ProbeFailedWithoutTimeout.clear();
1717
1681
  this.protocolV2CallCounts.clear();
1718
- this.silentDetections.clear();
1719
1682
  yield this.protocolV2Links
1720
1683
  .dispose('Electron BLE transport stopped')
1721
1684
  .catch(error => { var _a; return (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] link dispose failed:', error); });
@@ -1782,26 +1745,12 @@ class ElectronBleTransport {
1782
1745
  });
1783
1746
  }
1784
1747
  acquire(input) {
1785
- var _a, _b, _c, _d, _e, _f, _g, _h;
1748
+ var _a, _b, _c, _d, _e, _f, _g;
1786
1749
  return __awaiter(this, void 0, void 0, function* () {
1787
1750
  const { uuid, forceCleanRunPromise, expectedProtocol, forceProtocolDetection } = input;
1788
1751
  if (!uuid) {
1789
1752
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleRequiredUUID);
1790
1753
  }
1791
- if ((_a = input.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) {
1792
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
1793
- }
1794
- const acquireGeneration = this.nextAcquireGeneration;
1795
- this.nextAcquireGeneration += 1;
1796
- this.acquireGenerations.set(uuid, acquireGeneration);
1797
- const isCurrentAcquire = () => this.acquireGenerations.get(uuid) === acquireGeneration;
1798
- const assertAcquireActive = () => {
1799
- var _a;
1800
- this.assertRunning();
1801
- if (((_a = input.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) || !isCurrentAcquire()) {
1802
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
1803
- }
1804
- };
1805
1754
  const retainedToken = this.retainedDevices.has(uuid) &&
1806
1755
  !forceProtocolDetection &&
1807
1756
  (!expectedProtocol || expectedProtocol === 'V2') &&
@@ -1812,21 +1761,21 @@ class ElectronBleTransport {
1812
1761
  if (this.connectedDevices.has(uuid) && retainedToken === undefined) {
1813
1762
  yield this.release(uuid);
1814
1763
  }
1815
- assertAcquireActive();
1816
1764
  if (forceCleanRunPromise && this.runPromise) {
1817
1765
  const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleForceCleanRunPromise);
1818
1766
  this.runPromise.reject(error);
1819
1767
  this.runPromise = null;
1820
1768
  this.runPromiseDeviceId = null;
1821
1769
  }
1770
+ this.assertRunning();
1822
1771
  this.acquiringDevices.add(uuid);
1823
1772
  let connectAttempted = false;
1824
1773
  try {
1825
- if (!((_b = window.desktopApi) === null || _b === void 0 ? void 0 : _b.nobleBle)) {
1774
+ if (!((_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle)) {
1826
1775
  throw new Error('Noble BLE API not available');
1827
1776
  }
1828
1777
  const device = yield invokeNobleBle(window.desktopApi.nobleBle.getDevice(uuid));
1829
- assertAcquireActive();
1778
+ this.assertRunning();
1830
1779
  if (!device) {
1831
1780
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Device ${uuid} not found`);
1832
1781
  }
@@ -1838,20 +1787,19 @@ class ElectronBleTransport {
1838
1787
  }
1839
1788
  const protocolHint = expectedProtocol
1840
1789
  ? undefined
1841
- : (_c = input.protocolHint) !== null && _c !== void 0 ? _c : this.deviceProtocolHints.get(uuid);
1790
+ : (_b = input.protocolHint) !== null && _b !== void 0 ? _b : this.deviceProtocolHints.get(uuid);
1842
1791
  if (protocolHint) {
1843
1792
  this.deviceProtocolHints.set(uuid, protocolHint);
1844
1793
  }
1845
1794
  try {
1846
1795
  connectAttempted = true;
1847
1796
  yield invokeNobleBle(window.desktopApi.nobleBle.connect(uuid));
1848
- assertAcquireActive();
1849
1797
  this.connectedDevices.add(uuid);
1850
1798
  }
1851
1799
  catch (error) {
1852
1800
  this.handleBluetoothError(error);
1853
1801
  }
1854
- assertAcquireActive();
1802
+ this.assertRunning();
1855
1803
  const mtuCleanup = this.createMtuSubscription(uuid);
1856
1804
  if (mtuCleanup) {
1857
1805
  this.mtuCleanups.set(uuid, mtuCleanup);
@@ -1864,61 +1812,51 @@ class ElectronBleTransport {
1864
1812
  catch (error) {
1865
1813
  this.handleBluetoothError(error);
1866
1814
  }
1867
- assertAcquireActive();
1868
- const connectedDevice = yield this.refreshBlePacketCapacity(uuid);
1869
- assertAcquireActive();
1870
- const resolvedDeviceName = (connectedDevice === null || connectedDevice === void 0 ? void 0 : connectedDevice.name) || device.name;
1815
+ yield this.refreshBlePacketCapacity(uuid);
1816
+ this.assertRunning();
1871
1817
  const cleanup = this.createNotificationSubscription(uuid);
1872
1818
  this.notificationCleanups.set(uuid, cleanup);
1873
- const protocolType = yield this.detectProtocol(uuid, expectedProtocol, protocolHint, {
1874
- isKnownLegacyV1Device: hdShared.isLegacyProtocolV1BleName(resolvedDeviceName),
1875
- onlyConnectBleDevice: input.onlyConnectBleDevice,
1876
- abortSignal: input.abortSignal,
1877
- });
1878
- assertAcquireActive();
1819
+ const protocolType = yield this.detectProtocol(uuid, expectedProtocol, protocolHint);
1820
+ this.assertRunning();
1879
1821
  if (protocolType === 'V2') {
1880
- (_d = this.Log) === null || _d === void 0 ? void 0 : _d.debug('[Electron BLE] Protocol V2 write configured', {
1822
+ (_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug('[Electron BLE] Protocol V2 write configured', {
1881
1823
  writeMode: 'withoutResponse',
1882
1824
  negotiatedMtu: this.deviceMtus.get(uuid),
1883
- packetCapacity: (_e = this.devicePacketCapacities.get(uuid)) !== null && _e !== void 0 ? _e : BLE_PACKET_SIZE_FALLBACK,
1825
+ packetCapacity: (_d = this.devicePacketCapacities.get(uuid)) !== null && _d !== void 0 ? _d : BLE_PACKET_SIZE_FALLBACK,
1884
1826
  });
1885
1827
  }
1886
- return Object.assign(Object.assign({}, toBleDescriptor({ id: device.id, name: resolvedDeviceName }, protocolType)), { uuid });
1828
+ return Object.assign(Object.assign({}, toBleDescriptor({ id: device.id, name: device.name }, protocolType)), { uuid });
1887
1829
  }
1888
1830
  catch (error) {
1889
- (_f = this.Log) === null || _f === void 0 ? void 0 : _f.error('[Electron BLE] acquire failed:', error);
1890
- if (isCurrentAcquire()) {
1891
- try {
1892
- const nobleBle = (_g = window.desktopApi) === null || _g === void 0 ? void 0 : _g.nobleBle;
1893
- if (nobleBle && !this.stopped && (connectAttempted || this.connectedDevices.has(uuid))) {
1894
- if (this.connectedDevices.has(uuid)) {
1895
- yield invokeNobleBle(nobleBle.unsubscribe(uuid)).catch(cleanupError => {
1896
- var _a;
1897
- (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] acquire unsubscribe failed:', cleanupError);
1898
- });
1899
- }
1900
- yield invokeNobleBle(nobleBle.disconnect(uuid));
1831
+ (_e = this.Log) === null || _e === void 0 ? void 0 : _e.error('[Electron BLE] acquire failed:', error);
1832
+ try {
1833
+ const nobleBle = (_f = window.desktopApi) === null || _f === void 0 ? void 0 : _f.nobleBle;
1834
+ if (nobleBle && !this.stopped && (connectAttempted || this.connectedDevices.has(uuid))) {
1835
+ if (this.connectedDevices.has(uuid)) {
1836
+ yield invokeNobleBle(nobleBle.unsubscribe(uuid)).catch(cleanupError => {
1837
+ var _a;
1838
+ (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] acquire unsubscribe failed:', cleanupError);
1839
+ });
1901
1840
  }
1841
+ yield invokeNobleBle(nobleBle.disconnect(uuid));
1902
1842
  }
1903
- catch (cleanupError) {
1904
- (_h = this.Log) === null || _h === void 0 ? void 0 : _h.debug('[Electron BLE] acquire cleanup failed:', cleanupError);
1905
- }
1906
- this.cleanupDeviceState(uuid);
1907
1843
  }
1908
- throw this.normalizeBluetoothError(error);
1844
+ catch (cleanupError) {
1845
+ (_g = this.Log) === null || _g === void 0 ? void 0 : _g.debug('[Electron BLE] acquire cleanup failed:', cleanupError);
1846
+ }
1847
+ this.cleanupDeviceState(uuid);
1848
+ this.handleBluetoothError(error);
1909
1849
  }
1910
1850
  finally {
1911
- if (isCurrentAcquire()) {
1912
- this.acquiringDevices.delete(uuid);
1913
- }
1851
+ this.acquiringDevices.delete(uuid);
1914
1852
  }
1915
1853
  });
1916
1854
  }
1917
- release(id, onclose, keepSession) {
1855
+ release(id, onclose, keepSession, options) {
1918
1856
  var _a;
1919
1857
  return __awaiter(this, void 0, void 0, function* () {
1920
1858
  try {
1921
- const retainLink = keepSession === true &&
1859
+ const retainLink = (keepSession === true || (options === null || options === void 0 ? void 0 : options.retainLink) === true) &&
1922
1860
  !onclose &&
1923
1861
  this.connectedDevices.has(id) &&
1924
1862
  this.deviceProtocol.get(id) === 'V2' &&
@@ -2005,21 +1943,18 @@ class ElectronBleTransport {
2005
1943
  this.deviceProtocol.delete(uuid);
2006
1944
  }
2007
1945
  }
2008
- detectProtocol(uuid, expectedProtocol, protocolHint, options = {}) {
2009
- var _a, _b, _c, _d;
1946
+ detectProtocol(uuid, expectedProtocol, protocolHint) {
1947
+ var _a, _b, _c;
2010
1948
  return __awaiter(this, void 0, void 0, function* () {
2011
- if ((_a = options.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) {
2012
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
2013
- }
2014
1949
  if (expectedProtocol === 'V1') {
2015
1950
  this.deviceProtocol.set(uuid, 'V1');
2016
- (_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V1 (expected, no probe)`);
1951
+ (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V1 (expected, no probe)`);
2017
1952
  return 'V1';
2018
1953
  }
2019
1954
  if (expectedProtocol === 'V2') {
2020
1955
  if (yield this.probeProtocolV2(uuid, expectedProtocol)) {
2021
1956
  this.deviceProtocol.set(uuid, 'V2');
2022
- (_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V2 (expected)`);
1957
+ (_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V2 (expected)`);
2023
1958
  return 'V2';
2024
1959
  }
2025
1960
  throw this.createProtocolMismatchError(expectedProtocol);
@@ -2032,83 +1967,18 @@ class ElectronBleTransport {
2032
1967
  yield this.resetProbeStateAfterProtocolProbe(uuid, probeOrder[i - 1]);
2033
1968
  this.assertRunning();
2034
1969
  }
2035
- this.lastV1ProbeFailedWithoutTimeout.delete(uuid);
2036
- let detected = protocol === 'V1' ? yield this.probeProtocolV1(uuid) : yield this.probeProtocolV2(uuid);
2037
- if (!detected && protocol === 'V1' && !this.lastV1ProbeFailedWithoutTimeout.has(uuid)) {
2038
- detected = yield this.wakeSilentProtocolV1Device(uuid, probeOrder, options);
2039
- }
1970
+ const detected = protocol === 'V1' ? yield this.probeProtocolV1(uuid) : yield this.probeProtocolV2(uuid);
2040
1971
  this.assertRunning();
2041
1972
  if (detected) {
2042
1973
  this.deviceProtocol.set(uuid, protocol);
2043
- this.silentDetections.delete(uuid);
2044
- (_d = this.Log) === null || _d === void 0 ? void 0 : _d.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> ${protocol}`);
1974
+ (_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> ${protocol}`);
2045
1975
  return protocol;
2046
1976
  }
2047
1977
  }
2048
- if (!this.silentDetections.has(uuid)) {
2049
- this.silentDetections.set(uuid, 'silent');
2050
- }
2051
1978
  this.deviceProtocol.delete(uuid);
2052
1979
  throw this.createProtocolDetectionError();
2053
1980
  });
2054
1981
  }
2055
- wakeSilentProtocolV1Device(uuid, probeOrder, options = {}) {
2056
- var _a, _b, _c, _d, _e;
2057
- return __awaiter(this, void 0, void 0, function* () {
2058
- if (options.onlyConnectBleDevice ||
2059
- probeOrder[0] !== 'V1' ||
2060
- this.silentDetections.get(uuid) === 'woken' ||
2061
- (!options.isKnownLegacyV1Device && this.silentDetections.get(uuid) !== 'silent')) {
2062
- return false;
2063
- }
2064
- if ((_a = options.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) {
2065
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
2066
- }
2067
- this.assertRunning();
2068
- yield this.resetProbeStateAfterProtocolProbe(uuid, 'V1');
2069
- if ((_b = options.abortSignal) === null || _b === void 0 ? void 0 : _b.aborted) {
2070
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
2071
- }
2072
- this.assertRunning();
2073
- const previousSilentState = this.silentDetections.get(uuid);
2074
- this.silentDetections.set(uuid, 'woken');
2075
- (_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug('[Electron BLE] sending Protocol V1 Initialize wake', {
2076
- connectIdSuffix: uuid.slice(-8),
2077
- source: options.isKnownLegacyV1Device ? 'legacy-v1-name' : 'silent-retry',
2078
- });
2079
- let answeredV1 = false;
2080
- try {
2081
- this.deviceProtocol.set(uuid, 'V1');
2082
- const response = yield this.callProtocolV1(uuid, 'Initialize', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS }, { oneShot: true }, true);
2083
- answeredV1 = typeof (response === null || response === void 0 ? void 0 : response.type) === 'string';
2084
- }
2085
- catch (error) {
2086
- this.clearProbeProtocol(uuid, 'V1');
2087
- if (isUnstartedElectronWakeError(error)) {
2088
- if (previousSilentState) {
2089
- this.silentDetections.set(uuid, previousSilentState);
2090
- }
2091
- else {
2092
- this.silentDetections.delete(uuid);
2093
- }
2094
- }
2095
- (_d = this.Log) === null || _d === void 0 ? void 0 : _d.debug('[Electron BLE] Protocol V1 Initialize wake failed:', error);
2096
- if (shouldRethrowElectronProtocolProbeError(error)) {
2097
- throw error;
2098
- }
2099
- }
2100
- if (answeredV1) {
2101
- return true;
2102
- }
2103
- if ((_e = options.abortSignal) === null || _e === void 0 ? void 0 : _e.aborted) {
2104
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
2105
- }
2106
- this.assertRunning();
2107
- yield this.resetProbeStateAfterProtocolProbe(uuid, 'V1');
2108
- this.assertRunning();
2109
- return this.probeProtocolV1(uuid);
2110
- });
2111
- }
2112
1982
  createNotificationSubscription(uuid) {
2113
1983
  var _a;
2114
1984
  if (!((_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle)) {
@@ -2150,19 +2020,15 @@ class ElectronBleTransport {
2150
2020
  }
2151
2021
  try {
2152
2022
  this.deviceProtocol.set(uuid, 'V1');
2153
- this.lastV1ProbeFailedWithoutTimeout.delete(uuid);
2154
- yield this.callProtocolV1(uuid, 'GetFeatures', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS }, { oneShot: true }, true);
2023
+ yield this.callProtocolV1(uuid, 'GetFeatures', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS });
2155
2024
  return true;
2156
2025
  }
2157
2026
  catch (error) {
2158
2027
  this.clearProbeProtocol(uuid, 'V1');
2159
2028
  (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] Protocol V1 GetFeatures probe failed:', error);
2160
- if (shouldRethrowElectronProtocolProbeError(error)) {
2029
+ if (transport.isProtocolV2LinkDisabledError(error)) {
2161
2030
  throw error;
2162
2031
  }
2163
- if (!(error instanceof Error && this.probeResponseTimeoutErrors.has(error))) {
2164
- this.lastV1ProbeFailedWithoutTimeout.add(uuid);
2165
- }
2166
2032
  return false;
2167
2033
  }
2168
2034
  });
@@ -2216,7 +2082,6 @@ class ElectronBleTransport {
2216
2082
  const nobleBle = (_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle;
2217
2083
  const device = nobleBle ? yield invokeNobleBle(nobleBle.getDevice(uuid)) : undefined;
2218
2084
  this.updateBlePacketCapacity(uuid, device === null || device === void 0 ? void 0 : device.mtu);
2219
- return device;
2220
2085
  });
2221
2086
  }
2222
2087
  updateBlePacketCapacity(uuid, mtu) {
@@ -2408,7 +2273,7 @@ class ElectronBleTransport {
2408
2273
  yield this.callProtocolV1(uuid, name, data);
2409
2274
  });
2410
2275
  }
2411
- callProtocolV1(uuid, name, data, options, writeOptions, isProtocolProbe = false) {
2276
+ callProtocolV1(uuid, name, data, options) {
2412
2277
  var _a, _b;
2413
2278
  return __awaiter(this, void 0, void 0, function* () {
2414
2279
  if (!this._messages) {
@@ -2425,7 +2290,6 @@ class ElectronBleTransport {
2425
2290
  const messages = this._messages;
2426
2291
  const buffers = ProtocolV1.encodeTransportPackets(messages, name, data);
2427
2292
  let timeout;
2428
- let responseTimedOut = false;
2429
2293
  try {
2430
2294
  if (!((_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle)) {
2431
2295
  throw new Error('Noble BLE write API not available');
@@ -2439,16 +2303,13 @@ class ElectronBleTransport {
2439
2303
  if (hexString.length === 0) {
2440
2304
  throw new Error(`Buffer ${i + 1} is empty`);
2441
2305
  }
2442
- yield invokeNobleBle(writeOptions
2443
- ? window.desktopApi.nobleBle.write(uuid, hexString, writeOptions)
2444
- : window.desktopApi.nobleBle.write(uuid, hexString));
2306
+ yield invokeNobleBle(window.desktopApi.nobleBle.write(uuid, hexString));
2445
2307
  }
2446
2308
  const response = yield Promise.race([
2447
2309
  runPromise.promise,
2448
2310
  new Promise((_, reject) => {
2449
2311
  if (options === null || options === void 0 ? void 0 : options.timeoutMs) {
2450
2312
  timeout = setTimeout(() => {
2451
- responseTimedOut = true;
2452
2313
  const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, `BLE response timeout after ${options.timeoutMs}ms for ${name}`);
2453
2314
  runPromise.reject(error);
2454
2315
  reject(error);
@@ -2464,21 +2325,18 @@ class ElectronBleTransport {
2464
2325
  }
2465
2326
  catch (e) {
2466
2327
  (_b = this.Log) === null || _b === void 0 ? void 0 : _b.error('[Electron BLE] Protocol V1 call error:', e);
2328
+ const isProbeTimeout = name === 'GetFeatures' && (options === null || options === void 0 ? void 0 : options.timeoutMs) === PROTOCOL_PROBE_TIMEOUT_MS;
2467
2329
  if ((e === null || e === void 0 ? void 0 : e.errorCode) === hdShared.HardwareErrorCode.BleTimeoutError) {
2468
2330
  this.v1Buffers.set(uuid, { buffer: [], bufferLength: 0 });
2469
2331
  const notifyCleanup = this.notificationCleanups.get(uuid);
2470
2332
  notifyCleanup === null || notifyCleanup === void 0 ? void 0 : notifyCleanup();
2471
2333
  this.notificationCleanups.delete(uuid);
2472
2334
  this.notificationTokens.delete(uuid);
2473
- if (!isProtocolProbe) {
2335
+ if (!isProbeTimeout) {
2474
2336
  yield this.releaseNative(uuid, { forceNative: true });
2475
2337
  }
2476
2338
  }
2477
- const normalized = this.normalizeBluetoothError(e);
2478
- if (isProtocolProbe && responseTimedOut && normalized instanceof Error) {
2479
- this.probeResponseTimeoutErrors.add(normalized);
2480
- }
2481
- throw normalized;
2339
+ throw this.normalizeBluetoothError(e);
2482
2340
  }
2483
2341
  finally {
2484
2342
  if (timeout)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-web-device",
3
- "version": "1.2.11-alpha.19",
3
+ "version": "1.2.11-alpha.20",
4
4
  "author": "OneKey",
5
5
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
6
6
  "license": "MIT",
@@ -21,14 +21,14 @@
21
21
  "lint:fix": "eslint . --fix"
22
22
  },
23
23
  "dependencies": {
24
- "@onekeyfe/hd-shared": "1.2.11-alpha.19",
25
- "@onekeyfe/hd-transport": "1.2.11-alpha.19",
24
+ "@onekeyfe/hd-shared": "1.2.11-alpha.20",
25
+ "@onekeyfe/hd-transport": "1.2.11-alpha.20",
26
26
  "bytebuffer": "^5.0.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@onekeyfe/hd-transport-electron": "1.2.11-alpha.19",
29
+ "@onekeyfe/hd-transport-electron": "1.2.11-alpha.20",
30
30
  "@types/w3c-web-usb": "^1.0.6",
31
31
  "@types/web-bluetooth": "^0.0.17"
32
32
  },
33
- "gitHead": "4e187534319627c54ad1822066369ede4ea57493"
33
+ "gitHead": "32db23ffce1a306da3292732503b6afc4b5ac332"
34
34
  }