hardware-example 1.0.32 → 1.0.34-alpha.0
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 +2 -2
- package/src/config.ts +2 -0
- package/src/index.ts +9 -10
- package/src/preload.ts +99 -2
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.0.
|
|
5
|
+
"version": "1.0.34-alpha.0",
|
|
6
6
|
"author": "OneKey",
|
|
7
7
|
"description": "End-to-end encrypted workspaces for teams",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"webpack": "^5.90.2",
|
|
38
38
|
"webpack-node-externals": "^3.0.0"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "a910879dea6198bd96016aec81429f31b9692bf1"
|
|
41
41
|
}
|
package/src/config.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
screen,
|
|
3
|
-
app,
|
|
4
|
-
BrowserWindow,
|
|
5
|
-
session,
|
|
6
|
-
ipcMain,
|
|
7
|
-
USBDevice,
|
|
8
|
-
SerialPort,
|
|
9
|
-
HIDDevice,
|
|
10
|
-
} from 'electron';
|
|
1
|
+
import { screen, app, BrowserWindow, session, ipcMain } from 'electron';
|
|
11
2
|
import path from 'path';
|
|
12
3
|
import isDevelopment from 'electron-is-dev';
|
|
13
4
|
import { format as formatUrl } from 'url';
|
|
14
5
|
import log from 'electron-log';
|
|
15
6
|
import { autoUpdater } from 'electron-updater';
|
|
7
|
+
import { initElectronBleBridge } from '@onekeyfe/hd-transport-electron';
|
|
16
8
|
import initProcess, { restartBridge } from './process';
|
|
17
9
|
import { ipcMessageKeys } from './config';
|
|
18
10
|
|
|
@@ -88,6 +80,7 @@ function createMainWindow() {
|
|
|
88
80
|
spellcheck: false,
|
|
89
81
|
webviewTag: true,
|
|
90
82
|
webSecurity: !isDevelopment,
|
|
83
|
+
// @ts-expect-error
|
|
91
84
|
nativeWindowOpen: true,
|
|
92
85
|
allowRunningInsecureContent: isDevelopment,
|
|
93
86
|
// webview injected js needs isolation=false, because property can not be exposeInMainWorld() when isolation enabled.
|
|
@@ -263,6 +256,12 @@ function createMainWindow() {
|
|
|
263
256
|
}
|
|
264
257
|
});
|
|
265
258
|
|
|
259
|
+
initElectronBleBridge(browserWindow.webContents);
|
|
260
|
+
|
|
261
|
+
ipcMain.on(ipcMessageKeys.APP_RESTART, () => {
|
|
262
|
+
browserWindow?.reload();
|
|
263
|
+
});
|
|
264
|
+
|
|
266
265
|
return browserWindow;
|
|
267
266
|
}
|
|
268
267
|
|
package/src/preload.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/require-await */
|
|
3
|
-
import { ipcRenderer
|
|
4
|
-
import {
|
|
3
|
+
import { ipcRenderer } from 'electron';
|
|
4
|
+
import { EOneKeyBleMessageKeys } from '@onekeyfe/hd-shared';
|
|
5
|
+
import type {
|
|
6
|
+
ElectronBleAPI,
|
|
7
|
+
BluetoothPairingDetails,
|
|
8
|
+
BluetoothPairingResponse,
|
|
9
|
+
} from '@onekeyfe/hd-transport-electron';
|
|
5
10
|
import { ipcMessageKeys } from './config';
|
|
6
11
|
|
|
7
12
|
export type DesktopAPI = {
|
|
13
|
+
restart: () => void;
|
|
8
14
|
reloadBridgeProcess: () => void;
|
|
9
15
|
};
|
|
16
|
+
|
|
10
17
|
declare global {
|
|
11
18
|
interface Window {
|
|
12
19
|
desktopApi: DesktopAPI;
|
|
13
20
|
INJECT_PATH: string;
|
|
21
|
+
electronBleAPI: ElectronBleAPI;
|
|
14
22
|
}
|
|
15
23
|
}
|
|
16
24
|
|
|
@@ -32,12 +40,101 @@ const desktopApi = {
|
|
|
32
40
|
ipcRenderer.on(channel, (_, ...args) => func(...args));
|
|
33
41
|
}
|
|
34
42
|
},
|
|
43
|
+
restart: () => {
|
|
44
|
+
ipcRenderer.send(ipcMessageKeys.APP_RESTART);
|
|
45
|
+
},
|
|
35
46
|
updateReload: () => {
|
|
36
47
|
ipcRenderer.send(ipcMessageKeys.UPDATE_RESTART);
|
|
37
48
|
},
|
|
38
49
|
reloadBridgeProcess: () => {
|
|
39
50
|
ipcRenderer.send(ipcMessageKeys.APP_RELOAD_BRIDGE_PROCESS);
|
|
40
51
|
},
|
|
52
|
+
|
|
53
|
+
// Bluetooth api
|
|
54
|
+
onBleSelect: (callback: (devices: Array<{ id: string; name: string }>) => void) => {
|
|
55
|
+
// console.log('[Preload] Setting up onBleSelect listener');
|
|
56
|
+
const subscription = (_: unknown, devices: Array<{ id: string; name: string }>) => {
|
|
57
|
+
// console.log('[Preload] Received devices in onBleSelect:', devices);
|
|
58
|
+
callback(devices);
|
|
59
|
+
};
|
|
60
|
+
ipcRenderer.on(EOneKeyBleMessageKeys.BLE_SELECT, subscription);
|
|
61
|
+
return () => {
|
|
62
|
+
// console.log('[Preload] Removing onBleSelect listener');
|
|
63
|
+
ipcRenderer.removeListener(EOneKeyBleMessageKeys.BLE_SELECT, subscription);
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
selectBleDevice: (deviceId: string) => {
|
|
67
|
+
// console.log('[Preload] Sending selectBleDevice:', deviceId);
|
|
68
|
+
ipcRenderer.send(EOneKeyBleMessageKeys.BLE_SELECT_RESULT, deviceId);
|
|
69
|
+
},
|
|
70
|
+
cancelBleRequest: () => {
|
|
71
|
+
// console.log('[Preload] Sending cancel-bluetooth-request');
|
|
72
|
+
ipcRenderer.send('cancel-bluetooth-request');
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
// 配对相关
|
|
76
|
+
onBlePairingRequest: (callback: (details: BluetoothPairingDetails) => void) => {
|
|
77
|
+
// console.log('[Preload] Setting up onBlePairingRequest listener');
|
|
78
|
+
const subscription = (_: unknown, details: BluetoothPairingDetails) => {
|
|
79
|
+
// console.log('[Preload] Received pairing request:', details);
|
|
80
|
+
callback(details);
|
|
81
|
+
};
|
|
82
|
+
ipcRenderer.on(EOneKeyBleMessageKeys.BLE_PAIRING_REQUEST, subscription);
|
|
83
|
+
return () => {
|
|
84
|
+
// console.log('[Preload] Removing onBlePairingRequest listener');
|
|
85
|
+
ipcRenderer.removeListener(EOneKeyBleMessageKeys.BLE_PAIRING_REQUEST, subscription);
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
respondToPairing: (response: BluetoothPairingResponse) => {
|
|
89
|
+
// console.log('[Preload] Sending pairing response:', response);
|
|
90
|
+
ipcRenderer.send(EOneKeyBleMessageKeys.BLE_PAIRING_RESPONSE, response);
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
// Add method to stop BLE scanning
|
|
94
|
+
stopBleScan: () => {
|
|
95
|
+
// console.log('[Preload] Sending stop BLE scan request');
|
|
96
|
+
ipcRenderer.send(EOneKeyBleMessageKeys.BLE_STOP_SCAN);
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
// 设备预选相关
|
|
100
|
+
preSelectDevice: (uuid: string) => {
|
|
101
|
+
// console.log('[Preload] Pre-selecting device:', uuid);
|
|
102
|
+
ipcRenderer.send(EOneKeyBleMessageKeys.BLE_PRE_SELECT, uuid);
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
clearPreSelect: () => {
|
|
106
|
+
// console.log('[Preload] Clearing pre-selected device');
|
|
107
|
+
ipcRenderer.send(EOneKeyBleMessageKeys.BLE_CLEAR_PRE_SELECT);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
enumerate: () =>
|
|
111
|
+
new Promise(resolve => {
|
|
112
|
+
// 1. 监听结果
|
|
113
|
+
const handleResult = (_: any, devices: Array<{ id: string; name: string }>) => {
|
|
114
|
+
ipcRenderer.removeListener(EOneKeyBleMessageKeys.BLE_ENUMERATE_RESULT, handleResult);
|
|
115
|
+
resolve(devices);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// 2. 注册一次性监听
|
|
119
|
+
ipcRenderer.once(EOneKeyBleMessageKeys.BLE_ENUMERATE_RESULT, handleResult);
|
|
120
|
+
|
|
121
|
+
// 3. 发送枚举请求
|
|
122
|
+
ipcRenderer.send(EOneKeyBleMessageKeys.BLE_ENUMERATE);
|
|
123
|
+
}),
|
|
124
|
+
|
|
125
|
+
// 设备断开连接处理
|
|
126
|
+
onBleDeviceDisconnected: (callback: (device: { id: string; name: string | null }) => void) => {
|
|
127
|
+
// console.log('[Preload] Setting up onBleDeviceDisconnected listener');
|
|
128
|
+
const subscription = (_: unknown, device: { id: string; name: string | null }) => {
|
|
129
|
+
// console.log('[Preload] Device disconnected:', device);
|
|
130
|
+
callback(device);
|
|
131
|
+
};
|
|
132
|
+
ipcRenderer.on(EOneKeyBleMessageKeys.BLE_DEVICE_DISCONNECTED, subscription);
|
|
133
|
+
return () => {
|
|
134
|
+
// console.log('[Preload] Removing onBleDeviceDisconnected listener');
|
|
135
|
+
ipcRenderer.removeListener(EOneKeyBleMessageKeys.BLE_DEVICE_DISCONNECTED, subscription);
|
|
136
|
+
};
|
|
137
|
+
},
|
|
41
138
|
};
|
|
42
139
|
|
|
43
140
|
window.desktopApi = desktopApi;
|