feat: tauri serial polyfill

This commit is contained in:
2023-08-03 00:27:03 +02:00
parent 5014e1e8e8
commit 9c1918e683
280 changed files with 262 additions and 3222564 deletions

View File

@@ -0,0 +1,22 @@
import {invoke} from "@tauri-apps/api"
// @ts-expect-error polyfill
// noinspection JSConstantReassignment
navigator.serial = {
getPorts(): Promise<SerialPort[]> {
return invoke<any[]>("plugin:serial|get_serial_ports").then(ports =>
ports.map<Partial<SerialPort>>(port => ({
getInfo() {
return {
name: port["name"],
usbVendorId: port["vendor_id"],
usbProductId: port["product_id"],
serialNumber: port["serial_number"],
manufacturer: port["manufacturer"],
product: port["product"],
} as SerialPortInfo
},
})),
) as Promise<SerialPort[]>
},
}