hardware-example 1.0.39-alpha.3 → 1.0.39-alpha.5
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 +6 -2
- package/src/config.ts +2 -0
- package/src/index.ts +9 -10
- package/src/preload.ts +74 -8
- package/webpack.config.ts +6 -0
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.39-alpha.
|
|
5
|
+
"version": "1.0.39-alpha.5",
|
|
6
6
|
"author": "OneKey",
|
|
7
7
|
"description": "End-to-end encrypted workspaces for teams",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"ts:check": "yarn tsc --noEmit"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"@abandonware/noble": "^1.9.2-26",
|
|
23
24
|
"debug": "4.3.4",
|
|
24
25
|
"electron-is-dev": "^3.0.1",
|
|
25
26
|
"electron-log": "^5.1.5",
|
|
@@ -37,5 +38,8 @@
|
|
|
37
38
|
"webpack": "^5.90.2",
|
|
38
39
|
"webpack-node-externals": "^3.0.0"
|
|
39
40
|
},
|
|
40
|
-
"
|
|
41
|
+
"resolutions": {
|
|
42
|
+
"**/node-gyp": "^10.0.1"
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "6c62185f4a620a760ee67a648003c7c1ee828d19"
|
|
41
45
|
}
|
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 { initNobleBleSupport } 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
|
+
initNobleBleSupport(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,12 +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
3
|
import { ipcRenderer, contextBridge } from 'electron';
|
|
4
|
-
import {
|
|
4
|
+
import { EOneKeyBleMessageKeys } from '@onekeyfe/hd-shared';
|
|
5
|
+
import type { DesktopAPI as BaseDesktopAPI, NobleBleAPI } from '@onekeyfe/hd-transport-electron';
|
|
5
6
|
import { ipcMessageKeys } from './config';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
// Extend the base DesktopAPI with this specific application's needs
|
|
9
|
+
export interface DesktopAPI extends BaseDesktopAPI {
|
|
10
|
+
restart: () => void;
|
|
8
11
|
reloadBridgeProcess: () => void;
|
|
9
|
-
|
|
12
|
+
|
|
13
|
+
// Generic IPC methods
|
|
14
|
+
invoke: (channel: string, ...args: any[]) => Promise<any>;
|
|
15
|
+
on: (channel: string, callback: (...args: any[]) => void) => () => void;
|
|
16
|
+
off?: (channel: string, callback?: (...args: any[]) => void) => void;
|
|
17
|
+
|
|
18
|
+
// Make nobleBle required for this app
|
|
19
|
+
nobleBle: NobleBleAPI;
|
|
20
|
+
}
|
|
21
|
+
|
|
10
22
|
declare global {
|
|
11
23
|
interface Window {
|
|
12
24
|
desktopApi: DesktopAPI;
|
|
@@ -21,16 +33,30 @@ const validChannels = [
|
|
|
21
33
|
];
|
|
22
34
|
|
|
23
35
|
ipcRenderer.on(ipcMessageKeys.INJECT_ONEKEY_DESKTOP_GLOBALS, (_, globals) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
try {
|
|
37
|
+
contextBridge.exposeInMainWorld('ONEKEY_DESKTOP_GLOBALS', globals);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
// Fallback for development or when contextBridge is not available
|
|
40
|
+
console.warn('Failed to expose ONEKEY_DESKTOP_GLOBALS via contextBridge:', error);
|
|
41
|
+
}
|
|
27
42
|
});
|
|
28
43
|
|
|
29
44
|
const desktopApi = {
|
|
45
|
+
// Generic IPC methods
|
|
46
|
+
invoke: (channel: string, ...args: any[]) => ipcRenderer.invoke(channel, ...args),
|
|
30
47
|
on: (channel: string, func: (...args: any[]) => any) => {
|
|
31
48
|
if (validChannels.includes(channel)) {
|
|
32
49
|
ipcRenderer.on(channel, (_, ...args) => func(...args));
|
|
33
50
|
}
|
|
51
|
+
// For other channels, set up listener and return cleanup function
|
|
52
|
+
const listener = (_: any, ...args: any[]) => func(...args);
|
|
53
|
+
ipcRenderer.on(channel, listener);
|
|
54
|
+
return () => {
|
|
55
|
+
ipcRenderer.removeListener(channel, listener);
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
restart: () => {
|
|
59
|
+
ipcRenderer.send(ipcMessageKeys.APP_RESTART);
|
|
34
60
|
},
|
|
35
61
|
updateReload: () => {
|
|
36
62
|
ipcRenderer.send(ipcMessageKeys.UPDATE_RESTART);
|
|
@@ -38,7 +64,47 @@ const desktopApi = {
|
|
|
38
64
|
reloadBridgeProcess: () => {
|
|
39
65
|
ipcRenderer.send(ipcMessageKeys.APP_RELOAD_BRIDGE_PROCESS);
|
|
40
66
|
},
|
|
67
|
+
|
|
68
|
+
// Noble BLE specific methods
|
|
69
|
+
nobleBle: {
|
|
70
|
+
enumerate: () => ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE),
|
|
71
|
+
getDevice: (uuid: string) =>
|
|
72
|
+
ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_GET_DEVICE, uuid),
|
|
73
|
+
connect: (uuid: string) => ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_CONNECT, uuid),
|
|
74
|
+
disconnect: (uuid: string) =>
|
|
75
|
+
ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_DISCONNECT, uuid),
|
|
76
|
+
subscribe: (uuid: string) =>
|
|
77
|
+
ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_SUBSCRIBE, uuid),
|
|
78
|
+
unsubscribe: (uuid: string) =>
|
|
79
|
+
ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_UNSUBSCRIBE, uuid),
|
|
80
|
+
write: (uuid: string, data: string) =>
|
|
81
|
+
ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_WRITE, uuid, data),
|
|
82
|
+
onNotification: (callback: (deviceId: string, data: string) => void) => {
|
|
83
|
+
const subscription = (_: unknown, deviceId: string, data: string) => {
|
|
84
|
+
callback(deviceId, data);
|
|
85
|
+
};
|
|
86
|
+
ipcRenderer.on(EOneKeyBleMessageKeys.NOBLE_BLE_NOTIFICATION, subscription);
|
|
87
|
+
return () => {
|
|
88
|
+
ipcRenderer.removeListener(EOneKeyBleMessageKeys.NOBLE_BLE_NOTIFICATION, subscription);
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
onDeviceDisconnected: (callback: (device: { id: string; name: string }) => void) => {
|
|
92
|
+
const subscription = (_: unknown, device: { id: string; name: string }) => {
|
|
93
|
+
callback(device);
|
|
94
|
+
};
|
|
95
|
+
ipcRenderer.on(EOneKeyBleMessageKeys.BLE_DEVICE_DISCONNECTED, subscription);
|
|
96
|
+
return () => {
|
|
97
|
+
ipcRenderer.removeListener(EOneKeyBleMessageKeys.BLE_DEVICE_DISCONNECTED, subscription);
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
},
|
|
41
101
|
};
|
|
42
102
|
|
|
43
|
-
|
|
44
|
-
|
|
103
|
+
// Use contextBridge to safely expose the API
|
|
104
|
+
try {
|
|
105
|
+
contextBridge.exposeInMainWorld('desktopApi', desktopApi);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
// Fallback for development or when contextBridge is not available
|
|
108
|
+
console.warn('Failed to expose desktopApi via contextBridge:', error);
|
|
109
|
+
(window as any).desktopApi = desktopApi;
|
|
110
|
+
}
|
package/webpack.config.ts
CHANGED
|
@@ -47,6 +47,12 @@ module.exports = {
|
|
|
47
47
|
...pkg.devDependencies,
|
|
48
48
|
}),
|
|
49
49
|
}),
|
|
50
|
+
{
|
|
51
|
+
'@abandonware/noble': 'commonjs @abandonware/noble',
|
|
52
|
+
'@abandonware/bluetooth-hci-socket': 'commonjs @abandonware/bluetooth-hci-socket',
|
|
53
|
+
bufferutil: 'commonjs bufferutil',
|
|
54
|
+
'utf-8-validate': 'commonjs utf-8-validate',
|
|
55
|
+
},
|
|
50
56
|
],
|
|
51
57
|
output: {
|
|
52
58
|
path: path.resolve(__dirname, 'dist'),
|