hardware-example 1.0.39-alpha.1 → 1.0.39-alpha.11
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 +54 -11
- package/src/preload.ts +93 -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.11",
|
|
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": "9117ce67ac257526c2067fbeee09489082a75237"
|
|
41
45
|
}
|
package/src/config.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
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, shell } 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 { exec } from 'child_process';
|
|
8
|
+
import { initNobleBleSupport } from '@onekeyfe/hd-transport-electron';
|
|
16
9
|
import initProcess, { restartBridge } from './process';
|
|
17
10
|
import { ipcMessageKeys } from './config';
|
|
18
11
|
|
|
@@ -88,6 +81,7 @@ function createMainWindow() {
|
|
|
88
81
|
spellcheck: false,
|
|
89
82
|
webviewTag: true,
|
|
90
83
|
webSecurity: !isDevelopment,
|
|
84
|
+
// @ts-expect-error
|
|
91
85
|
nativeWindowOpen: true,
|
|
92
86
|
allowRunningInsecureContent: isDevelopment,
|
|
93
87
|
// webview injected js needs isolation=false, because property can not be exposeInMainWorld() when isolation enabled.
|
|
@@ -263,6 +257,12 @@ function createMainWindow() {
|
|
|
263
257
|
}
|
|
264
258
|
});
|
|
265
259
|
|
|
260
|
+
initNobleBleSupport(browserWindow.webContents);
|
|
261
|
+
|
|
262
|
+
ipcMain.on(ipcMessageKeys.APP_RESTART, () => {
|
|
263
|
+
browserWindow?.reload();
|
|
264
|
+
});
|
|
265
|
+
|
|
266
266
|
return browserWindow;
|
|
267
267
|
}
|
|
268
268
|
|
|
@@ -298,6 +298,49 @@ ipcMain.on(ipcMessageKeys.APP_RELOAD_BRIDGE_PROCESS, () => {
|
|
|
298
298
|
restartBridge();
|
|
299
299
|
});
|
|
300
300
|
|
|
301
|
+
// Simplified Bluetooth System API Implementation
|
|
302
|
+
class BluetoothSystemManager {
|
|
303
|
+
openBluetoothSettings(): void {
|
|
304
|
+
try {
|
|
305
|
+
if (process.platform === 'darwin') {
|
|
306
|
+
exec('open "/System/Library/PreferencePanes/Bluetooth.prefPane"');
|
|
307
|
+
} else if (process.platform === 'win32') {
|
|
308
|
+
shell.openExternal('ms-settings:bluetooth');
|
|
309
|
+
} else {
|
|
310
|
+
log.warn('Opening Bluetooth settings not supported on this platform');
|
|
311
|
+
}
|
|
312
|
+
} catch (error) {
|
|
313
|
+
log.error('Failed to open Bluetooth settings:', error);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
openPrivacySettings(): void {
|
|
318
|
+
try {
|
|
319
|
+
if (process.platform === 'darwin') {
|
|
320
|
+
exec('open "x-apple.systempreferences:com.apple.preference.security?Privacy_Bluetooth"');
|
|
321
|
+
} else if (process.platform === 'win32') {
|
|
322
|
+
shell.openExternal('ms-settings:privacy-bluetooth');
|
|
323
|
+
} else {
|
|
324
|
+
log.warn('Opening privacy settings not supported on this platform');
|
|
325
|
+
}
|
|
326
|
+
} catch (error) {
|
|
327
|
+
log.error('Failed to open privacy settings:', error);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Create global instance
|
|
333
|
+
const bluetoothManager = new BluetoothSystemManager();
|
|
334
|
+
|
|
335
|
+
// Register simplified IPC handlers for Bluetooth system API
|
|
336
|
+
ipcMain.handle('bluetooth-open-bluetooth-settings', () => {
|
|
337
|
+
bluetoothManager.openBluetoothSettings();
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
ipcMain.handle('bluetooth-open-privacy-settings', () => {
|
|
341
|
+
bluetoothManager.openPrivacySettings();
|
|
342
|
+
});
|
|
343
|
+
|
|
301
344
|
// 配置 GitHub 发布提供者
|
|
302
345
|
autoUpdater.setFeedURL({
|
|
303
346
|
provider: 'github',
|
|
@@ -325,7 +368,7 @@ app.on('ready', () => {
|
|
|
325
368
|
}, 5000);
|
|
326
369
|
});
|
|
327
370
|
|
|
328
|
-
//
|
|
371
|
+
// quit when all windows are closed, except on macOS. There, it's common
|
|
329
372
|
// for applications and their menu bar to stay active until the user quits
|
|
330
373
|
// explicitly with Cmd + Q
|
|
331
374
|
app.on('window-all-closed', (event: Event) => {
|
package/src/preload.ts
CHANGED
|
@@ -1,12 +1,34 @@
|
|
|
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
|
+
// Simplified Bluetooth system API - only for opening settings
|
|
9
|
+
export interface BluetoothSystemAPI {
|
|
10
|
+
// System integration
|
|
11
|
+
openBluetoothSettings: () => void;
|
|
12
|
+
openPrivacySettings: () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Extend the base DesktopAPI with this specific application's needs
|
|
16
|
+
export interface DesktopAPI extends BaseDesktopAPI {
|
|
17
|
+
restart: () => void;
|
|
8
18
|
reloadBridgeProcess: () => void;
|
|
9
|
-
|
|
19
|
+
|
|
20
|
+
// Generic IPC methods
|
|
21
|
+
invoke: (channel: string, ...args: any[]) => Promise<any>;
|
|
22
|
+
on: (channel: string, callback: (...args: any[]) => void) => () => void;
|
|
23
|
+
off?: (channel: string, callback?: (...args: any[]) => void) => void;
|
|
24
|
+
|
|
25
|
+
// Make nobleBle required for this app
|
|
26
|
+
nobleBle: NobleBleAPI;
|
|
27
|
+
|
|
28
|
+
// Simplified Bluetooth system management
|
|
29
|
+
bluetoothSystem: BluetoothSystemAPI;
|
|
30
|
+
}
|
|
31
|
+
|
|
10
32
|
declare global {
|
|
11
33
|
interface Window {
|
|
12
34
|
desktopApi: DesktopAPI;
|
|
@@ -21,16 +43,30 @@ const validChannels = [
|
|
|
21
43
|
];
|
|
22
44
|
|
|
23
45
|
ipcRenderer.on(ipcMessageKeys.INJECT_ONEKEY_DESKTOP_GLOBALS, (_, globals) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
46
|
+
try {
|
|
47
|
+
contextBridge.exposeInMainWorld('ONEKEY_DESKTOP_GLOBALS', globals);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
// Fallback for development or when contextBridge is not available
|
|
50
|
+
console.warn('Failed to expose ONEKEY_DESKTOP_GLOBALS via contextBridge:', error);
|
|
51
|
+
}
|
|
27
52
|
});
|
|
28
53
|
|
|
29
54
|
const desktopApi = {
|
|
55
|
+
// Generic IPC methods
|
|
56
|
+
invoke: (channel: string, ...args: any[]) => ipcRenderer.invoke(channel, ...args),
|
|
30
57
|
on: (channel: string, func: (...args: any[]) => any) => {
|
|
31
58
|
if (validChannels.includes(channel)) {
|
|
32
59
|
ipcRenderer.on(channel, (_, ...args) => func(...args));
|
|
33
60
|
}
|
|
61
|
+
// For other channels, set up listener and return cleanup function
|
|
62
|
+
const listener = (_: any, ...args: any[]) => func(...args);
|
|
63
|
+
ipcRenderer.on(channel, listener);
|
|
64
|
+
return () => {
|
|
65
|
+
ipcRenderer.removeListener(channel, listener);
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
restart: () => {
|
|
69
|
+
ipcRenderer.send(ipcMessageKeys.APP_RESTART);
|
|
34
70
|
},
|
|
35
71
|
updateReload: () => {
|
|
36
72
|
ipcRenderer.send(ipcMessageKeys.UPDATE_RESTART);
|
|
@@ -38,7 +74,56 @@ const desktopApi = {
|
|
|
38
74
|
reloadBridgeProcess: () => {
|
|
39
75
|
ipcRenderer.send(ipcMessageKeys.APP_RELOAD_BRIDGE_PROCESS);
|
|
40
76
|
},
|
|
77
|
+
|
|
78
|
+
// Noble BLE specific methods
|
|
79
|
+
nobleBle: {
|
|
80
|
+
enumerate: () => ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_ENUMERATE),
|
|
81
|
+
getDevice: (uuid: string) =>
|
|
82
|
+
ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_GET_DEVICE, uuid),
|
|
83
|
+
connect: (uuid: string) => ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_CONNECT, uuid),
|
|
84
|
+
disconnect: (uuid: string) =>
|
|
85
|
+
ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_DISCONNECT, uuid),
|
|
86
|
+
subscribe: (uuid: string) =>
|
|
87
|
+
ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_SUBSCRIBE, uuid),
|
|
88
|
+
unsubscribe: (uuid: string) =>
|
|
89
|
+
ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_UNSUBSCRIBE, uuid),
|
|
90
|
+
write: (uuid: string, data: string) =>
|
|
91
|
+
ipcRenderer.invoke(EOneKeyBleMessageKeys.NOBLE_BLE_WRITE, uuid, data),
|
|
92
|
+
onNotification: (callback: (deviceId: string, data: string) => void) => {
|
|
93
|
+
const subscription = (_: unknown, deviceId: string, data: string) => {
|
|
94
|
+
callback(deviceId, data);
|
|
95
|
+
};
|
|
96
|
+
ipcRenderer.on(EOneKeyBleMessageKeys.NOBLE_BLE_NOTIFICATION, subscription);
|
|
97
|
+
return () => {
|
|
98
|
+
ipcRenderer.removeListener(EOneKeyBleMessageKeys.NOBLE_BLE_NOTIFICATION, subscription);
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
onDeviceDisconnected: (callback: (device: { id: string; name: string }) => void) => {
|
|
102
|
+
const subscription = (_: unknown, device: { id: string; name: string }) => {
|
|
103
|
+
callback(device);
|
|
104
|
+
};
|
|
105
|
+
ipcRenderer.on(EOneKeyBleMessageKeys.BLE_DEVICE_DISCONNECTED, subscription);
|
|
106
|
+
return () => {
|
|
107
|
+
ipcRenderer.removeListener(EOneKeyBleMessageKeys.BLE_DEVICE_DISCONNECTED, subscription);
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
checkAvailability: () => ipcRenderer.invoke(EOneKeyBleMessageKeys.BLE_AVAILABILITY_CHECK),
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
// Simplified Bluetooth system management
|
|
114
|
+
bluetoothSystem: {
|
|
115
|
+
// Open Bluetooth settings when Bluetooth is off
|
|
116
|
+
openBluetoothSettings: () => ipcRenderer.invoke('bluetooth-open-bluetooth-settings'),
|
|
117
|
+
// Open Privacy & Security settings for Bluetooth permission
|
|
118
|
+
openPrivacySettings: () => ipcRenderer.invoke('bluetooth-open-privacy-settings'),
|
|
119
|
+
},
|
|
41
120
|
};
|
|
42
121
|
|
|
43
|
-
|
|
44
|
-
|
|
122
|
+
// Use contextBridge to safely expose the API
|
|
123
|
+
try {
|
|
124
|
+
contextBridge.exposeInMainWorld('desktopApi', desktopApi);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
// Fallback for development or when contextBridge is not available
|
|
127
|
+
console.warn('Failed to expose desktopApi via contextBridge:', error);
|
|
128
|
+
(window as any).desktopApi = desktopApi;
|
|
129
|
+
}
|
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'),
|