hardware-example 1.2.2-alpha.8 → 1.2.3-alpha.1
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/package.json +3 -3
- package/src/preload.ts +22 -8
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "hardware-example",
|
|
3
3
|
"productName": "HardwareExample",
|
|
4
4
|
"executableName": "onekey-hardware-example",
|
|
5
|
-
"version": "1.2.
|
|
5
|
+
"version": "1.2.3-alpha.1",
|
|
6
6
|
"author": "OneKey",
|
|
7
7
|
"description": "OneKey Hardware SDK Electron BLE example",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"ts:check": "yarn tsc --noEmit"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@onekeyfe/hd-transport-electron": "1.2.
|
|
24
|
+
"@onekeyfe/hd-transport-electron": "1.2.3-alpha.1",
|
|
25
25
|
"@stoprocent/noble": "2.3.16",
|
|
26
26
|
"debug": "4.3.4",
|
|
27
27
|
"electron-is-dev": "^3.0.1",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"**/node-gyp": "^10.0.1",
|
|
43
43
|
"tmp": "0.2.4"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "fd4221863c00240fc4870fc50f8c517d97426de2"
|
|
46
46
|
}
|
package/src/preload.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/require-await */
|
|
3
3
|
import { contextBridge, ipcRenderer } from 'electron';
|
|
4
4
|
import { EOneKeyBleMessageKeys } from '@onekeyfe/hd-shared';
|
|
5
|
+
import { invokeNobleBleIpc } from '@onekeyfe/hd-transport-electron';
|
|
5
6
|
|
|
6
7
|
import { ipcMessageKeys } from './config';
|
|
7
8
|
|
|
@@ -47,6 +48,9 @@ const validChannels = [
|
|
|
47
48
|
ipcMessageKeys.UPDATE_DOWNLOADED,
|
|
48
49
|
];
|
|
49
50
|
|
|
51
|
+
const invokeNobleBle = <T>(channel: string, ...args: unknown[]) =>
|
|
52
|
+
invokeNobleBleIpc<T>(ipcRenderer.invoke(channel, ...args));
|
|
53
|
+
|
|
50
54
|
const desktopApi = {
|
|
51
55
|
// Generic IPC methods
|
|
52
56
|
invoke: (channel: string, ...args: any[]) => ipcRenderer.invoke(channel, ...args),
|
|
@@ -69,18 +73,22 @@ const desktopApi = {
|
|
|
69
73
|
},
|
|
70
74
|
// Noble BLE specific methods
|
|
71
75
|
nobleBle: {
|
|
72
|
-
enumerate: () =>
|
|
76
|
+
enumerate: () =>
|
|
77
|
+
invokeNobleBle<{ id: string; name: string }[]>(EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE),
|
|
73
78
|
getDevice: (uuid: string) =>
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
invokeNobleBle<{ id: string; name: string; mtu?: number } | null>(
|
|
80
|
+
EOneKeyBleMessageKeys.NOBLE_BLE_GET_DEVICE,
|
|
81
|
+
uuid
|
|
82
|
+
),
|
|
83
|
+
connect: (uuid: string) => invokeNobleBle<void>(EOneKeyBleMessageKeys.NOBLE_BLE_CONNECT, uuid),
|
|
76
84
|
disconnect: (uuid: string) =>
|
|
77
|
-
|
|
85
|
+
invokeNobleBle<void>(EOneKeyBleMessageKeys.NOBLE_BLE_DISCONNECT, uuid),
|
|
78
86
|
subscribe: (uuid: string) =>
|
|
79
|
-
|
|
87
|
+
invokeNobleBle<void>(EOneKeyBleMessageKeys.NOBLE_BLE_SUBSCRIBE, uuid),
|
|
80
88
|
unsubscribe: (uuid: string) =>
|
|
81
|
-
|
|
89
|
+
invokeNobleBle<void>(EOneKeyBleMessageKeys.NOBLE_BLE_UNSUBSCRIBE, uuid),
|
|
82
90
|
write: (uuid: string, data: string, options?: NobleBleWriteOptions) =>
|
|
83
|
-
|
|
91
|
+
invokeNobleBle<void>(EOneKeyBleMessageKeys.NOBLE_BLE_WRITE, uuid, data, options),
|
|
84
92
|
onNotification: (callback: (deviceId: string, data: string) => void) => {
|
|
85
93
|
const subscription = (_: unknown, deviceId: string, data: string) => {
|
|
86
94
|
callback(deviceId, data);
|
|
@@ -108,7 +116,13 @@ const desktopApi = {
|
|
|
108
116
|
ipcRenderer.removeListener(EOneKeyBleMessageKeys.BLE_DEVICE_DISCONNECTED, subscription);
|
|
109
117
|
};
|
|
110
118
|
},
|
|
111
|
-
checkAvailability: () =>
|
|
119
|
+
checkAvailability: () =>
|
|
120
|
+
invokeNobleBle<{
|
|
121
|
+
available: boolean;
|
|
122
|
+
state: string;
|
|
123
|
+
unsupported: boolean;
|
|
124
|
+
initialized: boolean;
|
|
125
|
+
}>(EOneKeyBleMessageKeys.BLE_AVAILABILITY_CHECK),
|
|
112
126
|
},
|
|
113
127
|
|
|
114
128
|
// Simplified Bluetooth system management
|