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

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,6 +1524,34 @@ 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
+ };
1527
1555
  class ElectronBleTransport {
1528
1556
  constructor() {
1529
1557
  this.name = 'ElectronBleTransport';
@@ -1537,6 +1565,11 @@ class ElectronBleTransport {
1537
1565
  this.stopped = false;
1538
1566
  this.deviceProtocol = new Map();
1539
1567
  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;
1540
1573
  this.deviceMtus = new Map();
1541
1574
  this.devicePacketCapacities = new Map();
1542
1575
  this.v1Buffers = new Map();
@@ -1619,6 +1652,7 @@ class ElectronBleTransport {
1619
1652
  this.devicePacketCapacities.delete(deviceId);
1620
1653
  this.v1Buffers.delete(deviceId);
1621
1654
  this.v2Assemblers.delete(deviceId);
1655
+ this.lastV1ProbeFailedWithoutTimeout.delete(deviceId);
1622
1656
  this.resetProtocolV2Frames(deviceId);
1623
1657
  this.notificationTokens.delete(deviceId);
1624
1658
  if (this.runPromise && this.runPromiseDeviceId === deviceId) {
@@ -1678,7 +1712,10 @@ class ElectronBleTransport {
1678
1712
  ]);
1679
1713
  yield Promise.all(Array.from(trackedDeviceIds, deviceId => this.releaseNative(deviceId)));
1680
1714
  this.acquiringDevices.clear();
1715
+ this.acquireGenerations.clear();
1716
+ this.lastV1ProbeFailedWithoutTimeout.clear();
1681
1717
  this.protocolV2CallCounts.clear();
1718
+ this.silentDetections.clear();
1682
1719
  yield this.protocolV2Links
1683
1720
  .dispose('Electron BLE transport stopped')
1684
1721
  .catch(error => { var _a; return (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] link dispose failed:', error); });
@@ -1745,12 +1782,26 @@ class ElectronBleTransport {
1745
1782
  });
1746
1783
  }
1747
1784
  acquire(input) {
1748
- var _a, _b, _c, _d, _e, _f, _g;
1785
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1749
1786
  return __awaiter(this, void 0, void 0, function* () {
1750
1787
  const { uuid, forceCleanRunPromise, expectedProtocol, forceProtocolDetection } = input;
1751
1788
  if (!uuid) {
1752
1789
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleRequiredUUID);
1753
1790
  }
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
+ };
1754
1805
  const retainedToken = this.retainedDevices.has(uuid) &&
1755
1806
  !forceProtocolDetection &&
1756
1807
  (!expectedProtocol || expectedProtocol === 'V2') &&
@@ -1761,21 +1812,21 @@ class ElectronBleTransport {
1761
1812
  if (this.connectedDevices.has(uuid) && retainedToken === undefined) {
1762
1813
  yield this.release(uuid);
1763
1814
  }
1815
+ assertAcquireActive();
1764
1816
  if (forceCleanRunPromise && this.runPromise) {
1765
1817
  const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleForceCleanRunPromise);
1766
1818
  this.runPromise.reject(error);
1767
1819
  this.runPromise = null;
1768
1820
  this.runPromiseDeviceId = null;
1769
1821
  }
1770
- this.assertRunning();
1771
1822
  this.acquiringDevices.add(uuid);
1772
1823
  let connectAttempted = false;
1773
1824
  try {
1774
- if (!((_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle)) {
1825
+ if (!((_b = window.desktopApi) === null || _b === void 0 ? void 0 : _b.nobleBle)) {
1775
1826
  throw new Error('Noble BLE API not available');
1776
1827
  }
1777
1828
  const device = yield invokeNobleBle(window.desktopApi.nobleBle.getDevice(uuid));
1778
- this.assertRunning();
1829
+ assertAcquireActive();
1779
1830
  if (!device) {
1780
1831
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Device ${uuid} not found`);
1781
1832
  }
@@ -1787,19 +1838,20 @@ class ElectronBleTransport {
1787
1838
  }
1788
1839
  const protocolHint = expectedProtocol
1789
1840
  ? undefined
1790
- : (_b = input.protocolHint) !== null && _b !== void 0 ? _b : this.deviceProtocolHints.get(uuid);
1841
+ : (_c = input.protocolHint) !== null && _c !== void 0 ? _c : this.deviceProtocolHints.get(uuid);
1791
1842
  if (protocolHint) {
1792
1843
  this.deviceProtocolHints.set(uuid, protocolHint);
1793
1844
  }
1794
1845
  try {
1795
1846
  connectAttempted = true;
1796
1847
  yield invokeNobleBle(window.desktopApi.nobleBle.connect(uuid));
1848
+ assertAcquireActive();
1797
1849
  this.connectedDevices.add(uuid);
1798
1850
  }
1799
1851
  catch (error) {
1800
1852
  this.handleBluetoothError(error);
1801
1853
  }
1802
- this.assertRunning();
1854
+ assertAcquireActive();
1803
1855
  const mtuCleanup = this.createMtuSubscription(uuid);
1804
1856
  if (mtuCleanup) {
1805
1857
  this.mtuCleanups.set(uuid, mtuCleanup);
@@ -1812,43 +1864,53 @@ class ElectronBleTransport {
1812
1864
  catch (error) {
1813
1865
  this.handleBluetoothError(error);
1814
1866
  }
1815
- yield this.refreshBlePacketCapacity(uuid);
1816
- this.assertRunning();
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;
1817
1871
  const cleanup = this.createNotificationSubscription(uuid);
1818
1872
  this.notificationCleanups.set(uuid, cleanup);
1819
- const protocolType = yield this.detectProtocol(uuid, expectedProtocol, protocolHint);
1820
- this.assertRunning();
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();
1821
1879
  if (protocolType === 'V2') {
1822
- (_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug('[Electron BLE] Protocol V2 write configured', {
1880
+ (_d = this.Log) === null || _d === void 0 ? void 0 : _d.debug('[Electron BLE] Protocol V2 write configured', {
1823
1881
  writeMode: 'withoutResponse',
1824
1882
  negotiatedMtu: this.deviceMtus.get(uuid),
1825
- packetCapacity: (_d = this.devicePacketCapacities.get(uuid)) !== null && _d !== void 0 ? _d : BLE_PACKET_SIZE_FALLBACK,
1883
+ packetCapacity: (_e = this.devicePacketCapacities.get(uuid)) !== null && _e !== void 0 ? _e : BLE_PACKET_SIZE_FALLBACK,
1826
1884
  });
1827
1885
  }
1828
- return Object.assign(Object.assign({}, toBleDescriptor({ id: device.id, name: device.name }, protocolType)), { uuid });
1886
+ return Object.assign(Object.assign({}, toBleDescriptor({ id: device.id, name: resolvedDeviceName }, protocolType)), { uuid });
1829
1887
  }
1830
1888
  catch (error) {
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
- });
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));
1840
1901
  }
1841
- yield invokeNobleBle(nobleBle.disconnect(uuid));
1842
1902
  }
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);
1843
1907
  }
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);
1908
+ throw this.normalizeBluetoothError(error);
1849
1909
  }
1850
1910
  finally {
1851
- this.acquiringDevices.delete(uuid);
1911
+ if (isCurrentAcquire()) {
1912
+ this.acquiringDevices.delete(uuid);
1913
+ }
1852
1914
  }
1853
1915
  });
1854
1916
  }
@@ -1943,18 +2005,21 @@ class ElectronBleTransport {
1943
2005
  this.deviceProtocol.delete(uuid);
1944
2006
  }
1945
2007
  }
1946
- detectProtocol(uuid, expectedProtocol, protocolHint) {
1947
- var _a, _b, _c;
2008
+ detectProtocol(uuid, expectedProtocol, protocolHint, options = {}) {
2009
+ var _a, _b, _c, _d;
1948
2010
  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
+ }
1949
2014
  if (expectedProtocol === 'V1') {
1950
2015
  this.deviceProtocol.set(uuid, 'V1');
1951
- (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V1 (expected, no probe)`);
2016
+ (_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V1 (expected, no probe)`);
1952
2017
  return 'V1';
1953
2018
  }
1954
2019
  if (expectedProtocol === 'V2') {
1955
2020
  if (yield this.probeProtocolV2(uuid, expectedProtocol)) {
1956
2021
  this.deviceProtocol.set(uuid, 'V2');
1957
- (_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V2 (expected)`);
2022
+ (_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug(`[Electron BLE] detectProtocol: uuid=${uuid} -> V2 (expected)`);
1958
2023
  return 'V2';
1959
2024
  }
1960
2025
  throw this.createProtocolMismatchError(expectedProtocol);
@@ -1967,18 +2032,83 @@ class ElectronBleTransport {
1967
2032
  yield this.resetProbeStateAfterProtocolProbe(uuid, probeOrder[i - 1]);
1968
2033
  this.assertRunning();
1969
2034
  }
1970
- const detected = protocol === 'V1' ? yield this.probeProtocolV1(uuid) : yield this.probeProtocolV2(uuid);
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
+ }
1971
2040
  this.assertRunning();
1972
2041
  if (detected) {
1973
2042
  this.deviceProtocol.set(uuid, protocol);
1974
- (_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug(`[Electron BLE] detectProtocol: uuid=${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}`);
1975
2045
  return protocol;
1976
2046
  }
1977
2047
  }
2048
+ if (!this.silentDetections.has(uuid)) {
2049
+ this.silentDetections.set(uuid, 'silent');
2050
+ }
1978
2051
  this.deviceProtocol.delete(uuid);
1979
2052
  throw this.createProtocolDetectionError();
1980
2053
  });
1981
2054
  }
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
+ }
1982
2112
  createNotificationSubscription(uuid) {
1983
2113
  var _a;
1984
2114
  if (!((_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle)) {
@@ -2020,15 +2150,19 @@ class ElectronBleTransport {
2020
2150
  }
2021
2151
  try {
2022
2152
  this.deviceProtocol.set(uuid, 'V1');
2023
- yield this.callProtocolV1(uuid, 'GetFeatures', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS });
2153
+ this.lastV1ProbeFailedWithoutTimeout.delete(uuid);
2154
+ yield this.callProtocolV1(uuid, 'GetFeatures', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS }, { oneShot: true }, true);
2024
2155
  return true;
2025
2156
  }
2026
2157
  catch (error) {
2027
2158
  this.clearProbeProtocol(uuid, 'V1');
2028
2159
  (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[Electron BLE] Protocol V1 GetFeatures probe failed:', error);
2029
- if (transport.isProtocolV2LinkDisabledError(error)) {
2160
+ if (shouldRethrowElectronProtocolProbeError(error)) {
2030
2161
  throw error;
2031
2162
  }
2163
+ if (!(error instanceof Error && this.probeResponseTimeoutErrors.has(error))) {
2164
+ this.lastV1ProbeFailedWithoutTimeout.add(uuid);
2165
+ }
2032
2166
  return false;
2033
2167
  }
2034
2168
  });
@@ -2082,6 +2216,7 @@ class ElectronBleTransport {
2082
2216
  const nobleBle = (_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle;
2083
2217
  const device = nobleBle ? yield invokeNobleBle(nobleBle.getDevice(uuid)) : undefined;
2084
2218
  this.updateBlePacketCapacity(uuid, device === null || device === void 0 ? void 0 : device.mtu);
2219
+ return device;
2085
2220
  });
2086
2221
  }
2087
2222
  updateBlePacketCapacity(uuid, mtu) {
@@ -2273,7 +2408,7 @@ class ElectronBleTransport {
2273
2408
  yield this.callProtocolV1(uuid, name, data);
2274
2409
  });
2275
2410
  }
2276
- callProtocolV1(uuid, name, data, options) {
2411
+ callProtocolV1(uuid, name, data, options, writeOptions, isProtocolProbe = false) {
2277
2412
  var _a, _b;
2278
2413
  return __awaiter(this, void 0, void 0, function* () {
2279
2414
  if (!this._messages) {
@@ -2290,6 +2425,7 @@ class ElectronBleTransport {
2290
2425
  const messages = this._messages;
2291
2426
  const buffers = ProtocolV1.encodeTransportPackets(messages, name, data);
2292
2427
  let timeout;
2428
+ let responseTimedOut = false;
2293
2429
  try {
2294
2430
  if (!((_a = window.desktopApi) === null || _a === void 0 ? void 0 : _a.nobleBle)) {
2295
2431
  throw new Error('Noble BLE write API not available');
@@ -2303,13 +2439,16 @@ class ElectronBleTransport {
2303
2439
  if (hexString.length === 0) {
2304
2440
  throw new Error(`Buffer ${i + 1} is empty`);
2305
2441
  }
2306
- yield invokeNobleBle(window.desktopApi.nobleBle.write(uuid, hexString));
2442
+ yield invokeNobleBle(writeOptions
2443
+ ? window.desktopApi.nobleBle.write(uuid, hexString, writeOptions)
2444
+ : window.desktopApi.nobleBle.write(uuid, hexString));
2307
2445
  }
2308
2446
  const response = yield Promise.race([
2309
2447
  runPromise.promise,
2310
2448
  new Promise((_, reject) => {
2311
2449
  if (options === null || options === void 0 ? void 0 : options.timeoutMs) {
2312
2450
  timeout = setTimeout(() => {
2451
+ responseTimedOut = true;
2313
2452
  const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, `BLE response timeout after ${options.timeoutMs}ms for ${name}`);
2314
2453
  runPromise.reject(error);
2315
2454
  reject(error);
@@ -2325,18 +2464,21 @@ class ElectronBleTransport {
2325
2464
  }
2326
2465
  catch (e) {
2327
2466
  (_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;
2329
2467
  if ((e === null || e === void 0 ? void 0 : e.errorCode) === hdShared.HardwareErrorCode.BleTimeoutError) {
2330
2468
  this.v1Buffers.set(uuid, { buffer: [], bufferLength: 0 });
2331
2469
  const notifyCleanup = this.notificationCleanups.get(uuid);
2332
2470
  notifyCleanup === null || notifyCleanup === void 0 ? void 0 : notifyCleanup();
2333
2471
  this.notificationCleanups.delete(uuid);
2334
2472
  this.notificationTokens.delete(uuid);
2335
- if (!isProbeTimeout) {
2473
+ if (!isProtocolProbe) {
2336
2474
  yield this.releaseNative(uuid, { forceNative: true });
2337
2475
  }
2338
2476
  }
2339
- throw this.normalizeBluetoothError(e);
2477
+ const normalized = this.normalizeBluetoothError(e);
2478
+ if (isProtocolProbe && responseTimedOut && normalized instanceof Error) {
2479
+ this.probeResponseTimeoutErrors.add(normalized);
2480
+ }
2481
+ throw normalized;
2340
2482
  }
2341
2483
  finally {
2342
2484
  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.20",
3
+ "version": "1.2.11-alpha.21",
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.20",
25
- "@onekeyfe/hd-transport": "1.2.11-alpha.20",
24
+ "@onekeyfe/hd-shared": "1.2.11-alpha.21",
25
+ "@onekeyfe/hd-transport": "1.2.11-alpha.21",
26
26
  "bytebuffer": "^5.0.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@onekeyfe/hd-transport-electron": "1.2.11-alpha.20",
29
+ "@onekeyfe/hd-transport-electron": "1.2.11-alpha.21",
30
30
  "@types/w3c-web-usb": "^1.0.6",
31
31
  "@types/web-bluetooth": "^0.0.17"
32
32
  },
33
- "gitHead": "32db23ffce1a306da3292732503b6afc4b5ac332"
33
+ "gitHead": "3f09b63248967f5b5b18eca9cdd2ad3bceabf23e"
34
34
  }