hardware-example 1.0.24-alpha.4 → 1.0.24-alpha.6
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/index.ts +72 -1
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.24-alpha.
|
|
5
|
+
"version": "1.0.24-alpha.6",
|
|
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": "4a1e7ef50f159a44d0592e0d4e8f91e3c35823e5"
|
|
41
41
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
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';
|
|
@@ -144,6 +153,67 @@ function createMainWindow() {
|
|
|
144
153
|
callback({ cancel: false, requestHeaders: details.requestHeaders });
|
|
145
154
|
});
|
|
146
155
|
|
|
156
|
+
// 记录已授权的设备
|
|
157
|
+
let grantedDeviceThroughPermHandler = null;
|
|
158
|
+
|
|
159
|
+
browserWindow.webContents.session.setPermissionCheckHandler(
|
|
160
|
+
(webContents, permission, requestingOrigin, details) => {
|
|
161
|
+
log.debug('WebUSB: 权限检查被调用:', {
|
|
162
|
+
permission,
|
|
163
|
+
requestingOrigin,
|
|
164
|
+
details: JSON.stringify(details, null, 2),
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// 允许所有 USB 权限请求
|
|
168
|
+
if (permission === 'usb') {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
browserWindow.webContents.session.setDevicePermissionHandler(details => {
|
|
176
|
+
log.debug('WebUSB: 设备权限请求被调用:', {
|
|
177
|
+
deviceType: details.deviceType,
|
|
178
|
+
origin: details.origin,
|
|
179
|
+
device: JSON.stringify(details, null, 2),
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// 允许所有 USB 设备请求
|
|
183
|
+
if (details.deviceType === 'usb') {
|
|
184
|
+
log.debug('WebUSB: 记录已授权的设备');
|
|
185
|
+
grantedDeviceThroughPermHandler = details.device;
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
return false;
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
browserWindow.webContents.session.setUSBProtectedClassesHandler(details =>
|
|
192
|
+
details.protectedClasses.filter(
|
|
193
|
+
usbClass =>
|
|
194
|
+
// Exclude classes except for audio classes
|
|
195
|
+
usbClass.indexOf('audio') === -1
|
|
196
|
+
)
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
// 添加设备选择处理程序
|
|
200
|
+
browserWindow.webContents.session.on('select-usb-device', (event, details, callback) => {
|
|
201
|
+
log.debug('WebUSB: select-usb-device 事件触发');
|
|
202
|
+
log.debug('WebUSB: 可用设备列表:', JSON.stringify(details.deviceList, null, 2));
|
|
203
|
+
|
|
204
|
+
// 阻止默认行为,以便我们可以自定义设备选择
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
|
|
207
|
+
// 直接选择第一个设备
|
|
208
|
+
if (details.deviceList && details.deviceList.length > 0) {
|
|
209
|
+
console.debug(`WebUSB: 选择了第一个设备:`, JSON.stringify(details.deviceList[0], null, 2));
|
|
210
|
+
callback(details.deviceList[0].deviceId);
|
|
211
|
+
} else {
|
|
212
|
+
console.debug('WebUSB: 没有设备可选择,返回空');
|
|
213
|
+
callback();
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
147
217
|
if (!isDevelopment) {
|
|
148
218
|
const PROTOCOL = 'file';
|
|
149
219
|
session.defaultSession.protocol.interceptFileProtocol(PROTOCOL, (request, callback) => {
|
|
@@ -215,6 +285,7 @@ if (!singleInstance && !process.mas) {
|
|
|
215
285
|
}
|
|
216
286
|
initChildProcess();
|
|
217
287
|
showMainWindow();
|
|
288
|
+
console.log('日志文件位置:', log.transports.file.getFile().path);
|
|
218
289
|
});
|
|
219
290
|
}
|
|
220
291
|
|