@onekeyfe/hd-transport-electron 1.2.0-alpha.157 → 1.2.0-alpha.159
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-fe6d3919.js → index-b37d926c.js} +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1 -1
- package/dist/{noble-ble-handler-c88e98df.js → noble-ble-handler-e8b87173.js} +4 -2
- package/dist/noble-ble-handler.d.ts.map +1 -1
- package/dist/types/desktop-api.d.ts +2 -0
- package/dist/types/desktop-api.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/noble-ble-handler.ts +14 -0
- package/src/types/desktop-api.ts +11 -1
|
@@ -32,7 +32,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
32
32
|
|
|
33
33
|
function initNobleBleSupport(webContents) {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-
|
|
35
|
+
const { setupNobleBleHandlers } = yield Promise.resolve().then(function () { return require('./noble-ble-handler-e8b87173.js'); });
|
|
36
36
|
setupNobleBleHandlers(webContents);
|
|
37
37
|
});
|
|
38
38
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WebContents } from 'electron';
|
|
2
2
|
import { Characteristic, Peripheral } from '@stoprocent/noble';
|
|
3
3
|
import { OneKeyDeviceInfoBase } from '@onekeyfe/hd-transport';
|
|
4
|
+
import { EBleDisconnectReason } from '@onekeyfe/hd-shared';
|
|
4
5
|
|
|
5
6
|
interface DeviceInfo extends OneKeyDeviceInfoBase {
|
|
6
7
|
id: string;
|
|
@@ -31,6 +32,7 @@ interface Logger {
|
|
|
31
32
|
* Desktop API types for Electron preload script
|
|
32
33
|
* These types define the core interface for Noble BLE communication
|
|
33
34
|
*/
|
|
35
|
+
|
|
34
36
|
interface NobleBleWriteOptions {
|
|
35
37
|
pacingDelayMs?: number;
|
|
36
38
|
}
|
|
@@ -55,9 +57,16 @@ interface NobleBleAPI {
|
|
|
55
57
|
id: string;
|
|
56
58
|
mtu: number;
|
|
57
59
|
}) => void) => () => void;
|
|
60
|
+
/**
|
|
61
|
+
* Fires whenever a BLE link drops. `reason` distinguishes a real peripheral
|
|
62
|
+
* drop from the main process freeing an idle link on its keep-alive timer;
|
|
63
|
+
* it is optional so an older host bridge that omits it still type-checks
|
|
64
|
+
* (absent is treated as a real drop by consumers).
|
|
65
|
+
*/
|
|
58
66
|
onDeviceDisconnected: (callback: (device: {
|
|
59
67
|
id: string;
|
|
60
68
|
name: string;
|
|
69
|
+
reason?: EBleDisconnectReason;
|
|
61
70
|
}) => void) => () => void;
|
|
62
71
|
checkAvailability: () => Promise<{
|
|
63
72
|
available: boolean;
|
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-b37d926c.js');
|
|
4
4
|
var hdShared = require('@onekeyfe/hd-shared');
|
|
5
5
|
var pRetry = require('p-retry');
|
|
6
6
|
|
|
@@ -341,6 +341,7 @@ function armIdleDisconnect(deviceId, ms = BLE_IDLE_DISCONNECT_MS, reason = 'idle
|
|
|
341
341
|
broadcastToAllWebContents(hdShared.EOneKeyBleMessageKeys.BLE_DEVICE_DISCONNECTED, {
|
|
342
342
|
id: deviceId,
|
|
343
343
|
name: deviceName,
|
|
344
|
+
reason: hdShared.EBleDisconnectReason.IdleKeepAlive,
|
|
344
345
|
});
|
|
345
346
|
})
|
|
346
347
|
.catch(error => {
|
|
@@ -356,7 +357,7 @@ function armIdleDisconnect(deviceId, ms = BLE_IDLE_DISCONNECT_MS, reason = 'idle
|
|
|
356
357
|
}
|
|
357
358
|
function cleanupDevice(deviceId, webContents, options = {}) {
|
|
358
359
|
var _a;
|
|
359
|
-
const { cleanupConnection = true, cleanupDiscoveredCache = false, sendDisconnectEvent = false, cancelOperations = true, reason = 'unknown', } = options;
|
|
360
|
+
const { cleanupConnection = true, cleanupDiscoveredCache = false, sendDisconnectEvent = false, cancelOperations = true, reason = 'unknown', disconnectReason = hdShared.EBleDisconnectReason.DeviceDisconnected, } = options;
|
|
360
361
|
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Starting device cleanup', {
|
|
361
362
|
deviceId,
|
|
362
363
|
reason,
|
|
@@ -393,6 +394,7 @@ function cleanupDevice(deviceId, webContents, options = {}) {
|
|
|
393
394
|
broadcastToAllWebContents(hdShared.EOneKeyBleMessageKeys.BLE_DEVICE_DISCONNECTED, {
|
|
394
395
|
id: deviceId,
|
|
395
396
|
name: deviceName,
|
|
397
|
+
reason: disconnectReason,
|
|
396
398
|
});
|
|
397
399
|
}
|
|
398
400
|
logger === null || logger === void 0 ? void 0 : logger.info('[NobleBLE] Device cleanup completed', { deviceId, reason });
|
|
@@ -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":"AA+BA,OAAO,KAAK,EAA+B,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AA0EhE,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE,oBAAoB,UAI7E;AA2mDD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAgMpE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EBleDisconnectReason } from '@onekeyfe/hd-shared';
|
|
1
2
|
export interface NobleBleWriteOptions {
|
|
2
3
|
pacingDelayMs?: number;
|
|
3
4
|
}
|
|
@@ -25,6 +26,7 @@ export interface NobleBleAPI {
|
|
|
25
26
|
onDeviceDisconnected: (callback: (device: {
|
|
26
27
|
id: string;
|
|
27
28
|
name: string;
|
|
29
|
+
reason?: EBleDisconnectReason;
|
|
28
30
|
}) => void) => () => void;
|
|
29
31
|
checkAvailability: () => Promise<{
|
|
30
32
|
available: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"desktop-api.d.ts","sourceRoot":"","sources":["../../src/types/desktop-api.ts"],"names":[],"mappings":"
|
|
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,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC,CAAC;IACzD,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IACxF,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAGzC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrF,cAAc,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;IACnF,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;IAOvF,oBAAoB,EAAE,CACpB,QAAQ,EAAE,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,oBAAoB,CAAA;KAAE,KAAK,IAAI,KACpF,MAAM,IAAI,CAAC;IAChB,iBAAiB,EAAE,MAAM,OAAO,CAAC;QAC/B,SAAS,EAAE,OAAO,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,OAAO,CAAC;QACrB,WAAW,EAAE,OAAO,CAAC;KACtB,CAAC,CAAC;CACJ;AAGD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,WAAW,CAAC;CACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-electron",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.159",
|
|
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.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
30
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-core": "1.2.0-alpha.159",
|
|
29
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.159",
|
|
30
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.159",
|
|
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": "302f9ff916b3769cdb0cf79d58d09a87eeac68c2"
|
|
40
40
|
}
|
package/src/noble-ble-handler.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
/* eslint-disable @typescript-eslint/no-var-requires, import/no-extraneous-dependencies */
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
|
+
EBleDisconnectReason,
|
|
9
10
|
EOneKeyBleMessageKeys,
|
|
10
11
|
ERRORS,
|
|
11
12
|
HardwareErrorCode,
|
|
@@ -336,6 +337,12 @@ interface DeviceCleanupOptions {
|
|
|
336
337
|
cleanupDiscoveredCache?: boolean;
|
|
337
338
|
/** Whether to send disconnect event */
|
|
338
339
|
sendDisconnectEvent?: boolean;
|
|
340
|
+
/**
|
|
341
|
+
* Why the link went down, forwarded to renderers on BLE_DEVICE_DISCONNECTED.
|
|
342
|
+
* Defaults to a real peripheral drop; the keep-alive path overrides it so
|
|
343
|
+
* consumers can tell an internal idle release from a device that left.
|
|
344
|
+
*/
|
|
345
|
+
disconnectReason?: EBleDisconnectReason;
|
|
339
346
|
/** Whether to cancel ongoing operations */
|
|
340
347
|
cancelOperations?: boolean;
|
|
341
348
|
/** Cleanup reason (for logging) */
|
|
@@ -394,9 +401,14 @@ function armIdleDisconnect(
|
|
|
394
401
|
const pending = disconnectDevice(deviceId)
|
|
395
402
|
.then(() => {
|
|
396
403
|
// A call is still in flight here; it must reject, not hang.
|
|
404
|
+
// Both 'idle' and 'busy-backstop' report IdleKeepAlive on purpose:
|
|
405
|
+
// we reclaimed the link ourselves and have no evidence the device
|
|
406
|
+
// left, so consumers must not mark it disconnected. The in-flight
|
|
407
|
+
// call still fails, via the renderer dropping its device state.
|
|
397
408
|
broadcastToAllWebContents(EOneKeyBleMessageKeys.BLE_DEVICE_DISCONNECTED, {
|
|
398
409
|
id: deviceId,
|
|
399
410
|
name: deviceName,
|
|
411
|
+
reason: EBleDisconnectReason.IdleKeepAlive,
|
|
400
412
|
});
|
|
401
413
|
})
|
|
402
414
|
.catch(error => {
|
|
@@ -426,6 +438,7 @@ function cleanupDevice(
|
|
|
426
438
|
sendDisconnectEvent = false,
|
|
427
439
|
cancelOperations = true,
|
|
428
440
|
reason = 'unknown',
|
|
441
|
+
disconnectReason = EBleDisconnectReason.DeviceDisconnected,
|
|
429
442
|
} = options;
|
|
430
443
|
|
|
431
444
|
logger?.info('[NobleBLE] Starting device cleanup', {
|
|
@@ -475,6 +488,7 @@ function cleanupDevice(
|
|
|
475
488
|
broadcastToAllWebContents(EOneKeyBleMessageKeys.BLE_DEVICE_DISCONNECTED, {
|
|
476
489
|
id: deviceId,
|
|
477
490
|
name: deviceName,
|
|
491
|
+
reason: disconnectReason,
|
|
478
492
|
});
|
|
479
493
|
}
|
|
480
494
|
|
package/src/types/desktop-api.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* These types define the core interface for Noble BLE communication
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import type { EBleDisconnectReason } from '@onekeyfe/hd-shared';
|
|
7
|
+
|
|
6
8
|
// Noble BLE API interface - core BLE functionality
|
|
7
9
|
export interface NobleBleWriteOptions {
|
|
8
10
|
pacingDelayMs?: number;
|
|
@@ -21,7 +23,15 @@ export interface NobleBleAPI {
|
|
|
21
23
|
write: (uuid: string, data: string, options?: NobleBleWriteOptions) => Promise<void>;
|
|
22
24
|
onNotification: (callback: (deviceId: string, data: string) => void) => () => void;
|
|
23
25
|
onMtuChanged?: (callback: (device: { id: string; mtu: number }) => void) => () => void;
|
|
24
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Fires whenever a BLE link drops. `reason` distinguishes a real peripheral
|
|
28
|
+
* drop from the main process freeing an idle link on its keep-alive timer;
|
|
29
|
+
* it is optional so an older host bridge that omits it still type-checks
|
|
30
|
+
* (absent is treated as a real drop by consumers).
|
|
31
|
+
*/
|
|
32
|
+
onDeviceDisconnected: (
|
|
33
|
+
callback: (device: { id: string; name: string; reason?: EBleDisconnectReason }) => void
|
|
34
|
+
) => () => void;
|
|
25
35
|
checkAvailability: () => Promise<{
|
|
26
36
|
available: boolean;
|
|
27
37
|
state: string;
|