hardware-example 1.0.34-alpha.0 → 1.0.34
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 +0 -2
- package/src/index.ts +10 -9
- package/src/preload.ts +2 -99
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.34
|
|
5
|
+
"version": "1.0.34",
|
|
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": "3172095f33c4637dd76b36fee3ea0cfa0bd3ae40"
|
|
41
41
|
}
|
package/src/config.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
screen,
|
|
3
|
+
app,
|
|
4
|
+
BrowserWindow,
|
|
5
|
+
session,
|
|
6
|
+
ipcMain,
|
|
7
|
+
USBDevice,
|
|
8
|
+
SerialPort,
|
|
9
|
+
HIDDevice,
|
|
10
|
+
} from 'electron';
|
|
2
11
|
import path from 'path';
|
|
3
12
|
import isDevelopment from 'electron-is-dev';
|
|
4
13
|
import { format as formatUrl } from 'url';
|
|
5
14
|
import log from 'electron-log';
|
|
6
15
|
import { autoUpdater } from 'electron-updater';
|
|
7
|
-
import { initElectronBleBridge } from '@onekeyfe/hd-transport-electron';
|
|
8
16
|
import initProcess, { restartBridge } from './process';
|
|
9
17
|
import { ipcMessageKeys } from './config';
|
|
10
18
|
|
|
@@ -80,7 +88,6 @@ function createMainWindow() {
|
|
|
80
88
|
spellcheck: false,
|
|
81
89
|
webviewTag: true,
|
|
82
90
|
webSecurity: !isDevelopment,
|
|
83
|
-
// @ts-expect-error
|
|
84
91
|
nativeWindowOpen: true,
|
|
85
92
|
allowRunningInsecureContent: isDevelopment,
|
|
86
93
|
// webview injected js needs isolation=false, because property can not be exposeInMainWorld() when isolation enabled.
|
|
@@ -256,12 +263,6 @@ function createMainWindow() {
|
|
|
256
263
|
}
|
|
257
264
|
});
|
|
258
265
|
|
|
259
|
-
initElectronBleBridge(browserWindow.webContents);
|
|
260
|
-
|
|
261
|
-
ipcMain.on(ipcMessageKeys.APP_RESTART, () => {
|
|
262
|
-
browserWindow?.reload();
|
|
263
|
-
});
|
|
264
|
-
|
|
265
266
|
return browserWindow;
|
|
266
267
|
}
|
|
267
268
|
|
package/src/preload.ts
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
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 } from 'electron';
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
6
|
-
ElectronBleAPI,
|
|
7
|
-
BluetoothPairingDetails,
|
|
8
|
-
BluetoothPairingResponse,
|
|
9
|
-
} from '@onekeyfe/hd-transport-electron';
|
|
3
|
+
import { ipcRenderer, contextBridge } from 'electron';
|
|
4
|
+
import { off } from 'process';
|
|
10
5
|
import { ipcMessageKeys } from './config';
|
|
11
6
|
|
|
12
7
|
export type DesktopAPI = {
|
|
13
|
-
restart: () => void;
|
|
14
8
|
reloadBridgeProcess: () => void;
|
|
15
9
|
};
|
|
16
|
-
|
|
17
10
|
declare global {
|
|
18
11
|
interface Window {
|
|
19
12
|
desktopApi: DesktopAPI;
|
|
20
13
|
INJECT_PATH: string;
|
|
21
|
-
electronBleAPI: ElectronBleAPI;
|
|
22
14
|
}
|
|
23
15
|
}
|
|
24
16
|
|
|
@@ -40,101 +32,12 @@ const desktopApi = {
|
|
|
40
32
|
ipcRenderer.on(channel, (_, ...args) => func(...args));
|
|
41
33
|
}
|
|
42
34
|
},
|
|
43
|
-
restart: () => {
|
|
44
|
-
ipcRenderer.send(ipcMessageKeys.APP_RESTART);
|
|
45
|
-
},
|
|
46
35
|
updateReload: () => {
|
|
47
36
|
ipcRenderer.send(ipcMessageKeys.UPDATE_RESTART);
|
|
48
37
|
},
|
|
49
38
|
reloadBridgeProcess: () => {
|
|
50
39
|
ipcRenderer.send(ipcMessageKeys.APP_RELOAD_BRIDGE_PROCESS);
|
|
51
40
|
},
|
|
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
|
-
},
|
|
138
41
|
};
|
|
139
42
|
|
|
140
43
|
window.desktopApi = desktopApi;
|