forked from EdgeTX/buddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.ts
27 lines (23 loc) · 871 Bytes
/
functions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { createCrossBoundryFunction } from "./utils";
export const requestDevice = createCrossBoundryFunction<
(
...params: Parameters<typeof navigator.usb.requestDevice>
) => Promise<Pick<USBDevice, "vendorId" | "productId">>
>("usb.requestDevice", async (options) => {
const device = await navigator.usb.requestDevice(options);
return {
vendorId: device.vendorId,
productId: device.productId,
};
});
export const showDirectoryPicker = createCrossBoundryFunction<
typeof window.showDirectoryPicker
>("showDirectoryPicker", async (options) => {
const handle = await window.showDirectoryPicker(options);
// We can't request permission in the worker context, so do that here
await handle.getFileHandle(".edgetxbuddypermissions.txt", {
create: true,
});
await handle.removeEntry(".edgetxbuddypermissions.txt");
return handle;
});