mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-21 01:12:59 +00:00
feat: tauri serial polyfill
This commit is contained in:
22
src/lib/serial/tauri-serial.ts
Normal file
22
src/lib/serial/tauri-serial.ts
Normal 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[]>
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user