@onekeyfe/hd-core 1.2.0-alpha.149 → 1.2.0-alpha.150
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.
|
@@ -498,6 +498,26 @@ describe('public device lifecycle events', () => {
|
|
|
498
498
|
expect(isRetryableBleConnectionError(method, error)).toBe(false);
|
|
499
499
|
});
|
|
500
500
|
|
|
501
|
+
test('keeps a user cancel across a later BLE poll iteration', async () => {
|
|
502
|
+
jest.spyOn(DataManager, 'getSettings').mockReturnValue('react-native' as never);
|
|
503
|
+
const device = createInitializedDevice('V2');
|
|
504
|
+
const disconnect = jest.fn().mockResolvedValue(undefined);
|
|
505
|
+
const acquire = jest.fn().mockResolvedValue({ uuid: 'poll-session', protocolType: 'V2' });
|
|
506
|
+
device.deviceConnector = { acquire, disconnect } as never;
|
|
507
|
+
|
|
508
|
+
// First ensureConnected poll iteration.
|
|
509
|
+
device.beginConnectionAttempt();
|
|
510
|
+
await device.interruptionFromUser();
|
|
511
|
+
expect(device.wasInterruptedByUser()).toBe(true);
|
|
512
|
+
|
|
513
|
+
// A later poll must not call beginConnectionAttempt() again.
|
|
514
|
+
await expect(device.acquire('V2')).rejects.toMatchObject({
|
|
515
|
+
errorCode: HardwareErrorCode.DeviceInterruptedFromUser,
|
|
516
|
+
});
|
|
517
|
+
expect(device.wasInterruptedByUser()).toBe(true);
|
|
518
|
+
expect(acquire).not.toHaveBeenCalled();
|
|
519
|
+
});
|
|
520
|
+
|
|
501
521
|
test('allows a new BLE connect after the previous attempt was cancelled', async () => {
|
|
502
522
|
jest.spyOn(DataManager, 'getSettings').mockReturnValue('react-native' as never);
|
|
503
523
|
const device = createInitializedDevice('V2');
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAoClC,OAAO,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,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IAEjD,MAAM,CAAC,OAAO,eAAsB;IAEpC,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC;IAElC,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,eAAe;WAIjC,UAAU,CACrB,cAAc,EAAE,gBAAgB,EAAE,EAClC,SAAS,CAAC,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,WAAW;;;;IAwD3B,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM;WAQ7B,aAAa,CACxB,UAAU,EAAE,gBAAgB,EAC5B,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,MAAM,CAAC;WA6BL,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW;WA0B9D,gCAAgC,CAAC,MAAM,EAAE,MAAM;WAa/C,gBAAgB,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,MAAM;WAK9D,mBAAmB,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,MAAM;IAY9E,MAAM,CAAC,sBAAsB;IAY7B,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,gBAAgB,EAAE;IAsCtD,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM;IAOnC,MAAM,CAAC,yBAAyB,CAAC,UAAU,EAAE,gBAAgB;IAU7D,MAAM,CAAC,8BAA8B,CAAC,IAAI,EAAE,MAAM;IAOlD,MAAM,CAAC,4BAA4B,CAAC,UAAU,EAAE,gBAAgB;IAUhE,MAAM,CAAC,UAAU;IAUjB,MAAM,CAAC,OAAO;CAIf"}
|
package/dist/index.js
CHANGED
|
@@ -43202,6 +43202,7 @@ class DevicePool extends events.exports {
|
|
|
43202
43202
|
}
|
|
43203
43203
|
}
|
|
43204
43204
|
static _createDevice(descriptor, initOptions) {
|
|
43205
|
+
var _a;
|
|
43205
43206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43206
43207
|
const cachedDevice = this.getDeviceByPath(descriptor.path);
|
|
43207
43208
|
const forceProtocolDetection = (initOptions === null || initOptions === void 0 ? void 0 : initOptions.forceProtocolDetection) === true;
|
|
@@ -43209,6 +43210,7 @@ class DevicePool extends events.exports {
|
|
|
43209
43210
|
const device = cachedDevice !== null && cachedDevice !== void 0 ? cachedDevice : Device.fromDescriptor(descriptor);
|
|
43210
43211
|
if (isNewDevice || forceProtocolDetection) {
|
|
43211
43212
|
device.deviceConnector = this.connector;
|
|
43213
|
+
(_a = device.beginConnectionAttempt) === null || _a === void 0 ? void 0 : _a.call(device);
|
|
43212
43214
|
if (forceProtocolDetection && !isNewDevice) {
|
|
43213
43215
|
yield device.acquire(initOptions === null || initOptions === void 0 ? void 0 : initOptions.connectProtocol, { forceProtocolDetection: true });
|
|
43214
43216
|
}
|
|
@@ -65593,9 +65595,6 @@ function connectDeviceForBle(method, device, retryCount = 0) {
|
|
|
65593
65595
|
var _a;
|
|
65594
65596
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65595
65597
|
try {
|
|
65596
|
-
if (retryCount === 0) {
|
|
65597
|
-
device.beginConnectionAttempt();
|
|
65598
|
-
}
|
|
65599
65598
|
if (device.wasInterruptedByUser()) {
|
|
65600
65599
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser);
|
|
65601
65600
|
}
|
|
@@ -65722,6 +65721,9 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
65722
65721
|
if (abort()) {
|
|
65723
65722
|
return;
|
|
65724
65723
|
}
|
|
65724
|
+
if (tryCount === 1) {
|
|
65725
|
+
device.beginConnectionAttempt();
|
|
65726
|
+
}
|
|
65725
65727
|
yield connectDeviceForBle(method, device);
|
|
65726
65728
|
}
|
|
65727
65729
|
resolve(device);
|
|
@@ -65762,6 +65764,8 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
65762
65764
|
hdShared.HardwareErrorCode.DeviceDetectInBootloaderMode,
|
|
65763
65765
|
hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure,
|
|
65764
65766
|
hdShared.HardwareErrorCode.BridgeNeedsPermission,
|
|
65767
|
+
hdShared.HardwareErrorCode.DeviceInterruptedFromUser,
|
|
65768
|
+
hdShared.HardwareErrorCode.CallQueueActionCancelled,
|
|
65765
65769
|
].includes(error.errorCode)) {
|
|
65766
65770
|
reject(error);
|
|
65767
65771
|
return;
|
|
@@ -65798,19 +65802,25 @@ const cancel = (context, connectId) => {
|
|
|
65798
65802
|
const requestIds = requestQueue.getRequestTasksId();
|
|
65799
65803
|
Log.debug(`Cancel Api connect requestQueues: length:${requestIds.length} requestIds:${requestIds.join(',')}`);
|
|
65800
65804
|
const canceledDevices = [];
|
|
65805
|
+
const interruptDevice = (device, deviceConnectId) => {
|
|
65806
|
+
if (!device || canceledDevices.includes(device)) {
|
|
65807
|
+
return;
|
|
65808
|
+
}
|
|
65809
|
+
setPrePendingCallPromise(deviceConnectId, device.interruptionFromUser());
|
|
65810
|
+
canceledDevices.push(device);
|
|
65811
|
+
};
|
|
65801
65812
|
for (const requestId of requestIds) {
|
|
65802
65813
|
const task = requestQueue.getTask(requestId);
|
|
65803
65814
|
Log.debug('Cancel Api connect task: ', task);
|
|
65804
|
-
if (task
|
|
65805
|
-
|
|
65806
|
-
|
|
65807
|
-
setPrePendingCallPromise((_b = task.method.connectId) !== null && _b !== void 0 ? _b : connectId, device.interruptionFromUser());
|
|
65808
|
-
canceledDevices.push(device);
|
|
65809
|
-
}
|
|
65815
|
+
if (task) {
|
|
65816
|
+
interruptDevice((_a = task.method) === null || _a === void 0 ? void 0 : _a.device, (_b = task.method.connectId) !== null && _b !== void 0 ? _b : connectId);
|
|
65817
|
+
interruptDevice(deviceCacheMap.get(connectId), connectId);
|
|
65810
65818
|
requestQueue.rejectRequest(requestId, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled));
|
|
65811
65819
|
}
|
|
65812
65820
|
}
|
|
65821
|
+
interruptDevice(deviceCacheMap.get(connectId), connectId);
|
|
65813
65822
|
requestQueue.abortRequestsByConnectId(connectId);
|
|
65823
|
+
pollingManager.stop(connectId);
|
|
65814
65824
|
}
|
|
65815
65825
|
catch (e) {
|
|
65816
65826
|
Log.error('Cancel API Error: ', e);
|
|
@@ -65821,18 +65831,28 @@ const cancel = (context, connectId) => {
|
|
|
65821
65831
|
if (DataManager.isBleConnect(env)) {
|
|
65822
65832
|
Log.debug('Cancel Api all _deviceList: ');
|
|
65823
65833
|
const canceledDevices = [];
|
|
65834
|
+
const interruptDevice = (device) => {
|
|
65835
|
+
if (!device || canceledDevices.includes(device)) {
|
|
65836
|
+
return;
|
|
65837
|
+
}
|
|
65838
|
+
device.interruptionFromUser().catch(() => undefined);
|
|
65839
|
+
canceledDevices.push(device);
|
|
65840
|
+
};
|
|
65824
65841
|
for (const requestId of requestQueue.getRequestTasksId()) {
|
|
65825
65842
|
const task = requestQueue.getTask(requestId);
|
|
65826
65843
|
Log.debug('Cancel Api connect task: ', task);
|
|
65827
|
-
if (task
|
|
65828
|
-
|
|
65829
|
-
|
|
65830
|
-
|
|
65831
|
-
|
|
65844
|
+
if (task) {
|
|
65845
|
+
interruptDevice((_c = task.method) === null || _c === void 0 ? void 0 : _c.device);
|
|
65846
|
+
if (task.method.connectId) {
|
|
65847
|
+
interruptDevice(deviceCacheMap.get(task.method.connectId));
|
|
65848
|
+
pollingManager.stop(task.method.connectId);
|
|
65832
65849
|
}
|
|
65833
65850
|
requestQueue.rejectRequest(requestId, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled));
|
|
65834
65851
|
}
|
|
65835
65852
|
}
|
|
65853
|
+
deviceCacheMap.forEach(interruptDevice);
|
|
65854
|
+
requestQueue.abortAllRequests();
|
|
65855
|
+
pollingManager.stopAll();
|
|
65836
65856
|
}
|
|
65837
65857
|
else {
|
|
65838
65858
|
_deviceList === null || _deviceList === void 0 ? void 0 : _deviceList.allDevices().forEach(device => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.150",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.150",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.150",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "08359528e71933964694eb49793e555635350104"
|
|
50
50
|
}
|
package/src/core/index.ts
CHANGED
|
@@ -956,9 +956,6 @@ export function isMissingDetectedProtocolV2Error(method: BaseMethod, error: unkn
|
|
|
956
956
|
*/
|
|
957
957
|
async function connectDeviceForBle(method: BaseMethod, device: Device, retryCount = 0) {
|
|
958
958
|
try {
|
|
959
|
-
if (retryCount === 0) {
|
|
960
|
-
device.beginConnectionAttempt();
|
|
961
|
-
}
|
|
962
959
|
if (device.wasInterruptedByUser()) {
|
|
963
960
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceInterruptedFromUser);
|
|
964
961
|
}
|
|
@@ -1118,6 +1115,11 @@ const ensureConnected = async (
|
|
|
1118
1115
|
if (abort()) {
|
|
1119
1116
|
return;
|
|
1120
1117
|
}
|
|
1118
|
+
// One generation per public ensureConnected() call, not per poll
|
|
1119
|
+
// iteration. A later poll must not clear a user cancel.
|
|
1120
|
+
if (tryCount === 1) {
|
|
1121
|
+
device.beginConnectionAttempt();
|
|
1122
|
+
}
|
|
1121
1123
|
await connectDeviceForBle(method, device);
|
|
1122
1124
|
}
|
|
1123
1125
|
resolve(device);
|
|
@@ -1160,6 +1162,8 @@ const ensureConnected = async (
|
|
|
1160
1162
|
HardwareErrorCode.DeviceDetectInBootloaderMode,
|
|
1161
1163
|
HardwareErrorCode.BleCharacteristicNotifyChangeFailure,
|
|
1162
1164
|
HardwareErrorCode.BridgeNeedsPermission,
|
|
1165
|
+
HardwareErrorCode.DeviceInterruptedFromUser,
|
|
1166
|
+
HardwareErrorCode.CallQueueActionCancelled,
|
|
1163
1167
|
].includes(error.errorCode)
|
|
1164
1168
|
) {
|
|
1165
1169
|
reject(error);
|
|
@@ -1217,25 +1221,31 @@ export const cancel = (context: CoreContext, connectId?: string) => {
|
|
|
1217
1221
|
)}`
|
|
1218
1222
|
);
|
|
1219
1223
|
const canceledDevices: Device[] = [];
|
|
1224
|
+
const interruptDevice = (device: Device | undefined, deviceConnectId: string) => {
|
|
1225
|
+
if (!device || canceledDevices.includes(device)) {
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
setPrePendingCallPromise(deviceConnectId, device.interruptionFromUser());
|
|
1229
|
+
canceledDevices.push(device);
|
|
1230
|
+
};
|
|
1220
1231
|
for (const requestId of requestIds) {
|
|
1221
1232
|
const task = requestQueue.getTask(requestId);
|
|
1222
1233
|
Log.debug('Cancel Api connect task: ', task);
|
|
1223
|
-
if (task
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
);
|
|
1230
|
-
canceledDevices.push(device);
|
|
1231
|
-
}
|
|
1234
|
+
if (task) {
|
|
1235
|
+
// During ensureConnected the method has a connectId but device is
|
|
1236
|
+
// assigned only after the poll succeeds. Interrupt the cached BLE
|
|
1237
|
+
// Device so an in-flight acquire/initialize cannot finish.
|
|
1238
|
+
interruptDevice(task.method?.device, task.method.connectId ?? connectId);
|
|
1239
|
+
interruptDevice(deviceCacheMap.get(connectId), connectId);
|
|
1232
1240
|
requestQueue.rejectRequest(
|
|
1233
1241
|
requestId,
|
|
1234
1242
|
ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)
|
|
1235
1243
|
);
|
|
1236
1244
|
}
|
|
1237
1245
|
}
|
|
1246
|
+
interruptDevice(deviceCacheMap.get(connectId), connectId);
|
|
1238
1247
|
requestQueue.abortRequestsByConnectId(connectId);
|
|
1248
|
+
pollingManager.stop(connectId);
|
|
1239
1249
|
} catch (e) {
|
|
1240
1250
|
Log.error('Cancel API Error: ', e);
|
|
1241
1251
|
}
|
|
@@ -1244,22 +1254,31 @@ export const cancel = (context: CoreContext, connectId?: string) => {
|
|
|
1244
1254
|
if (DataManager.isBleConnect(env)) {
|
|
1245
1255
|
Log.debug('Cancel Api all _deviceList: ');
|
|
1246
1256
|
const canceledDevices: Device[] = [];
|
|
1257
|
+
const interruptDevice = (device?: Device) => {
|
|
1258
|
+
if (!device || canceledDevices.includes(device)) {
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
device.interruptionFromUser().catch(() => undefined);
|
|
1262
|
+
canceledDevices.push(device);
|
|
1263
|
+
};
|
|
1247
1264
|
for (const requestId of requestQueue.getRequestTasksId()) {
|
|
1248
1265
|
const task = requestQueue.getTask(requestId);
|
|
1249
1266
|
Log.debug('Cancel Api connect task: ', task);
|
|
1250
|
-
if (task
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1267
|
+
if (task) {
|
|
1268
|
+
interruptDevice(task.method?.device);
|
|
1269
|
+
if (task.method.connectId) {
|
|
1270
|
+
interruptDevice(deviceCacheMap.get(task.method.connectId));
|
|
1271
|
+
pollingManager.stop(task.method.connectId);
|
|
1255
1272
|
}
|
|
1256
|
-
|
|
1257
1273
|
requestQueue.rejectRequest(
|
|
1258
1274
|
requestId,
|
|
1259
1275
|
ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled)
|
|
1260
1276
|
);
|
|
1261
1277
|
}
|
|
1262
1278
|
}
|
|
1279
|
+
deviceCacheMap.forEach(interruptDevice);
|
|
1280
|
+
requestQueue.abortAllRequests();
|
|
1281
|
+
pollingManager.stopAll();
|
|
1263
1282
|
} else {
|
|
1264
1283
|
_deviceList?.allDevices().forEach(device => {
|
|
1265
1284
|
Log.debug('device: ', device, ' device.hasDeviceAcquire: ', device.hasDeviceAcquire());
|
package/src/device/DevicePool.ts
CHANGED
|
@@ -172,6 +172,9 @@ export class DevicePool extends EventEmitter {
|
|
|
172
172
|
const device = cachedDevice ?? Device.fromDescriptor(descriptor);
|
|
173
173
|
if (isNewDevice || forceProtocolDetection) {
|
|
174
174
|
device.deviceConnector = this.connector;
|
|
175
|
+
// Search/discovery acquires outside Device.run(). Start a new attempt so
|
|
176
|
+
// a previous user cancel does not hide this device from later searches.
|
|
177
|
+
device.beginConnectionAttempt?.();
|
|
175
178
|
if (forceProtocolDetection && !isNewDevice) {
|
|
176
179
|
await device.acquire(initOptions?.connectProtocol, { forceProtocolDetection: true });
|
|
177
180
|
} else {
|