@onekeyfe/hd-transport-electron 1.2.8-alpha.108 → 1.2.8-alpha.109
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-7ebbf8b8.js → index-21e34fdb.js} +2 -2
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -1
- package/dist/{noble-ble-handler-e0817284.js → noble-ble-handler-c4530a1b.js} +3 -22
- package/dist/noble-ble-handler.d.ts.map +1 -1
- package/dist/types/desktop-api.d.ts +0 -1
- package/dist/types/desktop-api.d.ts.map +1 -1
- package/dist/types/noble-extended.d.ts +2 -2
- package/dist/types/noble-extended.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/noble-ble-handler.test.ts +0 -161
- package/src/noble-ble-handler.ts +1 -28
- package/src/types/desktop-api.ts +1 -1
- package/src/types/noble-extended.ts +2 -4
|
@@ -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-
|
|
58
|
+
const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-c4530a1b.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-
|
|
64
|
+
const handler = yield Promise.resolve().then(function () { return require('./noble-ble-handler-c4530a1b.js'); });
|
|
65
65
|
yield handler.disposeNobleBleSupport(releaseNoble);
|
|
66
66
|
});
|
|
67
67
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { WebContents } from 'electron';
|
|
2
2
|
import { Characteristic, Peripheral } from '@stoprocent/noble';
|
|
3
|
-
import { OneKeyDeviceInfoBase
|
|
3
|
+
import { OneKeyDeviceInfoBase } from '@onekeyfe/hd-transport';
|
|
4
4
|
import { EBleDisconnectReason } from '@onekeyfe/hd-shared';
|
|
5
5
|
|
|
6
|
-
interface DeviceInfo extends OneKeyDeviceInfoBase
|
|
6
|
+
interface DeviceInfo extends OneKeyDeviceInfoBase {
|
|
7
7
|
id: string;
|
|
8
8
|
name: string;
|
|
9
9
|
state: string;
|
|
@@ -60,7 +60,6 @@ interface NobleBleAPI {
|
|
|
60
60
|
enumerate: () => Promise<{
|
|
61
61
|
id: string;
|
|
62
62
|
name: string;
|
|
63
|
-
bleColorCode?: string;
|
|
64
63
|
}[]>;
|
|
65
64
|
getDevice: (uuid: string) => Promise<{
|
|
66
65
|
id: string;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-21e34fdb.js');
|
|
4
4
|
var hdShared = require('@onekeyfe/hd-shared');
|
|
5
5
|
var pRetry = require('p-retry');
|
|
6
6
|
|
|
@@ -771,18 +771,6 @@ function rememberBleName(deviceId, name) {
|
|
|
771
771
|
bleNamesById.set(deviceId, trimmed);
|
|
772
772
|
}
|
|
773
773
|
}
|
|
774
|
-
const bleColorCodesById = new Map();
|
|
775
|
-
function rememberBleColorCode(peripheral) {
|
|
776
|
-
var _a;
|
|
777
|
-
const colorCode = hdShared.parseOnekeyBleColorCode((_a = peripheral.advertisement) === null || _a === void 0 ? void 0 : _a.manufacturerData);
|
|
778
|
-
if (colorCode && bleColorCodesById.get(peripheral.id) !== colorCode) {
|
|
779
|
-
bleColorCodesById.set(peripheral.id, colorCode);
|
|
780
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('[NobleBLE] BLE color code', {
|
|
781
|
-
deviceId: peripheral.id,
|
|
782
|
-
bleColorCode: colorCode,
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
774
|
function resolveBleName(deviceId) {
|
|
787
775
|
var _a, _b, _c, _d, _e, _f;
|
|
788
776
|
const live = ((_c = (_b = (_a = connectedDevices.get(deviceId)) === null || _a === void 0 ? void 0 : _a.advertisement) === null || _b === void 0 ? void 0 : _b.localName) === null || _c === void 0 ? void 0 : _c.trim()) ||
|
|
@@ -793,21 +781,18 @@ function shouldConnectByIdFirst(deviceId) {
|
|
|
793
781
|
return hdShared.isPro2FamilyBleName(resolveBleName(deviceId));
|
|
794
782
|
}
|
|
795
783
|
function handleDeviceDiscovered(peripheral) {
|
|
796
|
-
var _a, _b, _c
|
|
784
|
+
var _a, _b, _c;
|
|
797
785
|
if (!isOneKeyPeripheral(peripheral)) {
|
|
798
786
|
return;
|
|
799
787
|
}
|
|
800
788
|
const isNewDevice = !discoveredDevices.has(peripheral.id);
|
|
801
789
|
discoveredDevices.set(peripheral.id, peripheral);
|
|
802
790
|
rememberBleName(peripheral.id, (_a = peripheral.advertisement) === null || _a === void 0 ? void 0 : _a.localName);
|
|
803
|
-
rememberBleColorCode(peripheral);
|
|
804
791
|
if (isNewDevice) {
|
|
805
792
|
logger === null || logger === void 0 ? void 0 : logger.debug('[NobleBLE] OneKey BLE device discovered', {
|
|
806
793
|
deviceId: peripheral.id,
|
|
807
794
|
name: ((_b = peripheral.advertisement) === null || _b === void 0 ? void 0 : _b.localName) || 'Unknown Device',
|
|
808
795
|
serviceUUIDs: ((_c = peripheral.advertisement) === null || _c === void 0 ? void 0 : _c.serviceUuids) || [],
|
|
809
|
-
manufacturerDataLength: (_f = (_e = (_d = peripheral.advertisement) === null || _d === void 0 ? void 0 : _d.manufacturerData) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0,
|
|
810
|
-
bleColorCode: bleColorCodesById.get(peripheral.id),
|
|
811
796
|
});
|
|
812
797
|
}
|
|
813
798
|
}
|
|
@@ -933,10 +918,6 @@ function enumerateDevices(isWindowDestroyed) {
|
|
|
933
918
|
state: peripheral.state || 'disconnected',
|
|
934
919
|
});
|
|
935
920
|
};
|
|
936
|
-
const withBleColorCode = (device) => {
|
|
937
|
-
const bleColorCode = bleColorCodesById.get(device.id);
|
|
938
|
-
return bleColorCode ? Object.assign(Object.assign({}, device), { bleColorCode }) : device;
|
|
939
|
-
};
|
|
940
921
|
const checkDevices = () => {
|
|
941
922
|
discoveredDevices.forEach(pushDevice);
|
|
942
923
|
connectedDevices.forEach(pushDevice);
|
|
@@ -947,7 +928,7 @@ function enumerateDevices(isWindowDestroyed) {
|
|
|
947
928
|
checkDevices();
|
|
948
929
|
yield cleanup();
|
|
949
930
|
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Scan completed, found devices:', devices.length);
|
|
950
|
-
resolve(devices
|
|
931
|
+
resolve(devices);
|
|
951
932
|
}), DEVICE_SCAN_TIMEOUT);
|
|
952
933
|
const cancel = () => cleanup().then(() => resolve([]), reject);
|
|
953
934
|
pendingCancellations.add(cancel);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"
|
|
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;AAkzDD,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"desktop-api.d.ts","sourceRoot":"","sources":["../../src/types/desktop-api.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAGhE,MAAM,WAAW,oBAAoB;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,uBAAuB,CAAC;CAChC,CAAC;AAEF,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,OAAO,GAChB,QAAQ,IAAI,wBAAwB,CAatC;AAMD,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,OAAO,EAAE,OAAO,CAAC,CAAC,GAAG,wBAAwB,CAAC,GAC7C,OAAO,CAAC,CAAC,CAAC,CAMZ;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"desktop-api.d.ts","sourceRoot":"","sources":["../../src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
|
2
|
+
import type { OneKeyDeviceInfoBase } from '@onekeyfe/hd-transport';
|
|
3
|
+
export interface DeviceInfo extends OneKeyDeviceInfoBase {
|
|
4
4
|
id: string;
|
|
5
5
|
name: string;
|
|
6
6
|
state: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noble-extended.d.ts","sourceRoot":"","sources":["../../src/types/noble-extended.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"noble-extended.d.ts","sourceRoot":"","sources":["../../src/types/noble-extended.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAGnE,MAAM,WAAW,UAAW,SAAQ,oBAAoB;IACtD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAGD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,cAAc,CAAC;CACxB;AAGD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CACX,YAAY,EAAE,MAAM,EAAE,EACtB,eAAe,EAAE,OAAO,EACxB,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,GACjC,IAAI,CAAC;IACR,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC1C,IAAI,IAAI,IAAI,CAAC;IACb,aAAa,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;IAClE,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,GAAG,IAAI,CAAC;IACxE,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;IAC9E,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,GAAG,IAAI,CAAC;CACrF;AAGD,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC7C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CAC9C;AAGD,wBAAgB,OAAO,CACrB,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,EACjC,OAAO,EAAE,MAAM,EACf,GAAG,IAAI,EAAE,GAAG,EAAE,GACb,IAAI,CAMN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-electron",
|
|
3
|
-
"version": "1.2.8-alpha.
|
|
3
|
+
"version": "1.2.8-alpha.109",
|
|
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.
|
|
29
|
-
"@onekeyfe/hd-shared": "1.2.8-alpha.
|
|
30
|
-
"@onekeyfe/hd-transport": "1.2.8-alpha.
|
|
28
|
+
"@onekeyfe/hd-core": "1.2.8-alpha.109",
|
|
29
|
+
"@onekeyfe/hd-shared": "1.2.8-alpha.109",
|
|
30
|
+
"@onekeyfe/hd-transport": "1.2.8-alpha.109",
|
|
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": "
|
|
39
|
+
"gitHead": "302d4744489bf33f4db51ddeb7bd0835e6974fe0"
|
|
40
40
|
}
|
|
@@ -1211,164 +1211,3 @@ describe('Noble BLE process shutdown', () => {
|
|
|
1211
1211
|
await sdk.disposeNobleBleSupport();
|
|
1212
1212
|
});
|
|
1213
1213
|
});
|
|
1214
|
-
|
|
1215
|
-
describe('Electron Noble BLE advertisement color', () => {
|
|
1216
|
-
afterEach(() => {
|
|
1217
|
-
jest.useRealTimers();
|
|
1218
|
-
jest.resetModules();
|
|
1219
|
-
jest.clearAllMocks();
|
|
1220
|
-
});
|
|
1221
|
-
|
|
1222
|
-
test('applies a color that arrives after the device was listed in the same scan', async () => {
|
|
1223
|
-
jest.useFakeTimers({ doNotFake: ['performance'] });
|
|
1224
|
-
|
|
1225
|
-
const handlers = new Map<string, IpcHandler>();
|
|
1226
|
-
const ipcMain = {
|
|
1227
|
-
handle: jest.fn((channel: string, handler: IpcHandler) => {
|
|
1228
|
-
handlers.set(channel, handler);
|
|
1229
|
-
}),
|
|
1230
|
-
removeHandler: jest.fn((channel: string) => {
|
|
1231
|
-
handlers.delete(channel);
|
|
1232
|
-
}),
|
|
1233
|
-
};
|
|
1234
|
-
const noble = new EventEmitter() as EventEmitter & {
|
|
1235
|
-
state: string;
|
|
1236
|
-
startScanning: jest.Mock;
|
|
1237
|
-
stopScanning: jest.Mock;
|
|
1238
|
-
};
|
|
1239
|
-
let resolveScanStarted = () => undefined;
|
|
1240
|
-
const scanStarted = new Promise<void>(resolve => {
|
|
1241
|
-
resolveScanStarted = resolve;
|
|
1242
|
-
});
|
|
1243
|
-
const peripheral = createPeripheral('late-color-device', 'Neo 1A2B');
|
|
1244
|
-
noble.state = 'poweredOn';
|
|
1245
|
-
noble.startScanning = jest.fn((_services, _duplicates, callback) => {
|
|
1246
|
-
callback?.();
|
|
1247
|
-
Object.assign(peripheral.advertisement, { manufacturerData: Buffer.from([0, 0, 0, 0, 0]) });
|
|
1248
|
-
noble.emit('discover', peripheral);
|
|
1249
|
-
resolveScanStarted();
|
|
1250
|
-
});
|
|
1251
|
-
noble.stopScanning = jest.fn(callback => callback?.());
|
|
1252
|
-
|
|
1253
|
-
jest.doMock('@stoprocent/noble', () => noble);
|
|
1254
|
-
jest.doMock('electron', () => ({ ipcMain }));
|
|
1255
|
-
jest.doMock('electron-log', () => ({
|
|
1256
|
-
info: jest.fn(),
|
|
1257
|
-
debug: jest.fn(),
|
|
1258
|
-
error: jest.fn(),
|
|
1259
|
-
}));
|
|
1260
|
-
|
|
1261
|
-
const { setupNobleBleHandlers } = await import('../noble-ble-handler');
|
|
1262
|
-
setupNobleBleHandlers({
|
|
1263
|
-
on: jest.fn(),
|
|
1264
|
-
send: jest.fn(),
|
|
1265
|
-
} as unknown as WebContents);
|
|
1266
|
-
|
|
1267
|
-
const enumerate = handlers.get(EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE);
|
|
1268
|
-
if (!enumerate) {
|
|
1269
|
-
throw new Error('Electron Noble BLE enumerate handler was not registered');
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
const devicesPromise = Promise.resolve(enumerate());
|
|
1273
|
-
await scanStarted;
|
|
1274
|
-
// The first periodic check lists the device before its color is advertised.
|
|
1275
|
-
jest.advanceTimersByTime(600);
|
|
1276
|
-
Object.assign(peripheral.advertisement, {
|
|
1277
|
-
manufacturerData: Buffer.from([0x45, 0, 0, 0, 0]),
|
|
1278
|
-
});
|
|
1279
|
-
noble.emit('discover', peripheral);
|
|
1280
|
-
jest.advanceTimersByTime(5000);
|
|
1281
|
-
|
|
1282
|
-
await expect(devicesPromise).resolves.toEqual([
|
|
1283
|
-
{
|
|
1284
|
-
commType: 'electron-ble',
|
|
1285
|
-
id: 'late-color-device',
|
|
1286
|
-
name: 'Neo 1A2B',
|
|
1287
|
-
state: 'disconnected',
|
|
1288
|
-
bleColorCode: 'E',
|
|
1289
|
-
},
|
|
1290
|
-
]);
|
|
1291
|
-
});
|
|
1292
|
-
|
|
1293
|
-
test('keeps the advertised color after Noble overwrites the manufacturer data', async () => {
|
|
1294
|
-
jest.useFakeTimers({ doNotFake: ['performance'] });
|
|
1295
|
-
|
|
1296
|
-
const handlers = new Map<string, IpcHandler>();
|
|
1297
|
-
const ipcMain = {
|
|
1298
|
-
handle: jest.fn((channel: string, handler: IpcHandler) => {
|
|
1299
|
-
handlers.set(channel, handler);
|
|
1300
|
-
}),
|
|
1301
|
-
removeHandler: jest.fn((channel: string) => {
|
|
1302
|
-
handlers.delete(channel);
|
|
1303
|
-
}),
|
|
1304
|
-
};
|
|
1305
|
-
const noble = new EventEmitter() as EventEmitter & {
|
|
1306
|
-
state: string;
|
|
1307
|
-
startScanning: jest.Mock;
|
|
1308
|
-
stopScanning: jest.Mock;
|
|
1309
|
-
};
|
|
1310
|
-
let resolveScanStarted = () => undefined;
|
|
1311
|
-
const scanStarted = new Promise<void>(resolve => {
|
|
1312
|
-
resolveScanStarted = resolve;
|
|
1313
|
-
});
|
|
1314
|
-
const coloredPeripheral = createPeripheral('colored-device', 'Pro 2 A1B2');
|
|
1315
|
-
const legacyPeripheral = createPeripheral('legacy-device', 'Pro 2 C3D4');
|
|
1316
|
-
noble.state = 'poweredOn';
|
|
1317
|
-
noble.startScanning = jest.fn((_services, _duplicates, callback) => {
|
|
1318
|
-
callback?.();
|
|
1319
|
-
Object.assign(coloredPeripheral.advertisement, {
|
|
1320
|
-
manufacturerData: Buffer.from([0x44, 0, 0, 0, 0]),
|
|
1321
|
-
});
|
|
1322
|
-
noble.emit('discover', coloredPeripheral);
|
|
1323
|
-
// macOS and Windows replace the stored payload with an empty buffer when a
|
|
1324
|
-
// later event carries no 0xFF section.
|
|
1325
|
-
Object.assign(coloredPeripheral.advertisement, { manufacturerData: Buffer.alloc(0) });
|
|
1326
|
-
noble.emit('discover', coloredPeripheral);
|
|
1327
|
-
Object.assign(legacyPeripheral.advertisement, {
|
|
1328
|
-
manufacturerData: Buffer.from([0, 0, 0, 0]),
|
|
1329
|
-
});
|
|
1330
|
-
noble.emit('discover', legacyPeripheral);
|
|
1331
|
-
resolveScanStarted();
|
|
1332
|
-
});
|
|
1333
|
-
noble.stopScanning = jest.fn(callback => callback?.());
|
|
1334
|
-
|
|
1335
|
-
jest.doMock('@stoprocent/noble', () => noble);
|
|
1336
|
-
jest.doMock('electron', () => ({ ipcMain }));
|
|
1337
|
-
jest.doMock('electron-log', () => ({
|
|
1338
|
-
info: jest.fn(),
|
|
1339
|
-
debug: jest.fn(),
|
|
1340
|
-
error: jest.fn(),
|
|
1341
|
-
}));
|
|
1342
|
-
|
|
1343
|
-
const { setupNobleBleHandlers } = await import('../noble-ble-handler');
|
|
1344
|
-
setupNobleBleHandlers({
|
|
1345
|
-
on: jest.fn(),
|
|
1346
|
-
send: jest.fn(),
|
|
1347
|
-
} as unknown as WebContents);
|
|
1348
|
-
|
|
1349
|
-
const enumerate = handlers.get(EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE);
|
|
1350
|
-
if (!enumerate) {
|
|
1351
|
-
throw new Error('Electron Noble BLE enumerate handler was not registered');
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
const devicesPromise = Promise.resolve(enumerate());
|
|
1355
|
-
await scanStarted;
|
|
1356
|
-
jest.advanceTimersByTime(5000);
|
|
1357
|
-
|
|
1358
|
-
await expect(devicesPromise).resolves.toEqual([
|
|
1359
|
-
{
|
|
1360
|
-
commType: 'electron-ble',
|
|
1361
|
-
id: 'colored-device',
|
|
1362
|
-
name: 'Pro 2 A1B2',
|
|
1363
|
-
state: 'disconnected',
|
|
1364
|
-
bleColorCode: 'D',
|
|
1365
|
-
},
|
|
1366
|
-
{
|
|
1367
|
-
commType: 'electron-ble',
|
|
1368
|
-
id: 'legacy-device',
|
|
1369
|
-
name: 'Pro 2 C3D4',
|
|
1370
|
-
state: 'disconnected',
|
|
1371
|
-
},
|
|
1372
|
-
]);
|
|
1373
|
-
});
|
|
1374
|
-
});
|
package/src/noble-ble-handler.ts
CHANGED
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
isOnekeyBluetoothDevice,
|
|
20
20
|
isPro2FamilyBleName,
|
|
21
21
|
matchesKnownBleUuid,
|
|
22
|
-
parseOnekeyBleColorCode,
|
|
23
22
|
wait,
|
|
24
23
|
} from '@onekeyfe/hd-shared';
|
|
25
24
|
import pRetry from 'p-retry';
|
|
@@ -1013,22 +1012,6 @@ function rememberBleName(deviceId: string, name?: string | null): void {
|
|
|
1013
1012
|
}
|
|
1014
1013
|
}
|
|
1015
1014
|
|
|
1016
|
-
// Noble reuses one Peripheral per id, and on macOS/Windows an event without 0xFF data
|
|
1017
|
-
// replaces manufacturerData with an empty buffer. Snapshot the color when the OneKey
|
|
1018
|
-
// advertisement is seen; it is kept like the name because a linked device stops advertising.
|
|
1019
|
-
const bleColorCodesById = new Map<string, string>();
|
|
1020
|
-
|
|
1021
|
-
function rememberBleColorCode(peripheral: Peripheral): void {
|
|
1022
|
-
const colorCode = parseOnekeyBleColorCode(peripheral.advertisement?.manufacturerData);
|
|
1023
|
-
if (colorCode && bleColorCodesById.get(peripheral.id) !== colorCode) {
|
|
1024
|
-
bleColorCodesById.set(peripheral.id, colorCode);
|
|
1025
|
-
logger?.debug('[NobleBLE] BLE color code', {
|
|
1026
|
-
deviceId: peripheral.id,
|
|
1027
|
-
bleColorCode: colorCode,
|
|
1028
|
-
});
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
1015
|
function resolveBleName(deviceId: string): string | undefined {
|
|
1033
1016
|
const live =
|
|
1034
1017
|
connectedDevices.get(deviceId)?.advertisement?.localName?.trim() ||
|
|
@@ -1057,15 +1040,11 @@ function handleDeviceDiscovered(peripheral: Peripheral): void {
|
|
|
1057
1040
|
const isNewDevice = !discoveredDevices.has(peripheral.id);
|
|
1058
1041
|
discoveredDevices.set(peripheral.id, peripheral);
|
|
1059
1042
|
rememberBleName(peripheral.id, peripheral.advertisement?.localName);
|
|
1060
|
-
rememberBleColorCode(peripheral);
|
|
1061
1043
|
if (isNewDevice) {
|
|
1062
1044
|
logger?.debug('[NobleBLE] OneKey BLE device discovered', {
|
|
1063
1045
|
deviceId: peripheral.id,
|
|
1064
1046
|
name: peripheral.advertisement?.localName || 'Unknown Device',
|
|
1065
1047
|
serviceUUIDs: peripheral.advertisement?.serviceUuids || [],
|
|
1066
|
-
// 5 = advertises a color slot; 4 = BLE firmware before 1.0.23.
|
|
1067
|
-
manufacturerDataLength: peripheral.advertisement?.manufacturerData?.length ?? 0,
|
|
1068
|
-
bleColorCode: bleColorCodesById.get(peripheral.id),
|
|
1069
1048
|
});
|
|
1070
1049
|
}
|
|
1071
1050
|
}
|
|
@@ -1221,12 +1200,6 @@ async function enumerateDevices(isWindowDestroyed: () => boolean): Promise<Devic
|
|
|
1221
1200
|
state: peripheral.state || 'disconnected',
|
|
1222
1201
|
});
|
|
1223
1202
|
};
|
|
1224
|
-
// A device kept from an earlier round is pushed before this round's
|
|
1225
|
-
// advertisements arrive, so apply colors when the scan resolves.
|
|
1226
|
-
const withBleColorCode = (device: DeviceInfo): DeviceInfo => {
|
|
1227
|
-
const bleColorCode = bleColorCodesById.get(device.id);
|
|
1228
|
-
return bleColorCode ? { ...device, bleColorCode } : device;
|
|
1229
|
-
};
|
|
1230
1203
|
const checkDevices = () => {
|
|
1231
1204
|
discoveredDevices.forEach(pushDevice);
|
|
1232
1205
|
// A linked device stops advertising, so the scan never rediscovers it.
|
|
@@ -1240,7 +1213,7 @@ async function enumerateDevices(isWindowDestroyed: () => boolean): Promise<Devic
|
|
|
1240
1213
|
checkDevices();
|
|
1241
1214
|
await cleanup();
|
|
1242
1215
|
logger?.info('[NobleBLE] Scan completed, found devices:', devices.length);
|
|
1243
|
-
resolve(devices
|
|
1216
|
+
resolve(devices);
|
|
1244
1217
|
}, DEVICE_SCAN_TIMEOUT);
|
|
1245
1218
|
|
|
1246
1219
|
const cancel = () => cleanup().then(() => resolve([]), reject);
|
package/src/types/desktop-api.ts
CHANGED
|
@@ -55,7 +55,7 @@ export async function invokeNobleBleIpc<T>(
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export interface NobleBleAPI {
|
|
58
|
-
enumerate: () => Promise<{ id: string; name: string
|
|
58
|
+
enumerate: () => Promise<{ id: string; name: string }[]>;
|
|
59
59
|
getDevice: (uuid: string) => Promise<{ id: string; name: string; mtu?: number } | null>;
|
|
60
60
|
connect: (uuid: string) => Promise<void>;
|
|
61
61
|
// Logical end-of-operation: link stays up, idle countdown starts. Optional —
|
|
@@ -4,12 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { Characteristic, Peripheral } from '@stoprocent/noble';
|
|
7
|
-
import type { OneKeyDeviceInfoBase
|
|
7
|
+
import type { OneKeyDeviceInfoBase } from '@onekeyfe/hd-transport';
|
|
8
8
|
|
|
9
9
|
// Device info interface for our API
|
|
10
|
-
export interface DeviceInfo
|
|
11
|
-
extends OneKeyDeviceInfoBase,
|
|
12
|
-
Pick<OneKeyMobileDeviceInfo, 'bleColorCode'> {
|
|
10
|
+
export interface DeviceInfo extends OneKeyDeviceInfoBase {
|
|
13
11
|
id: string;
|
|
14
12
|
name: string;
|
|
15
13
|
state: string;
|