mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-05 06:24:56 +00:00
fixed serial opening ports
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { SerialPort } from 'serialport'
|
||||
import { PartialProfile, ProfilesService } from 'tabby-core'
|
||||
import WSABinding from 'serialport-binding-webserialapi'
|
||||
import AbstractBinding from '@serialport/binding-abstract'
|
||||
import { autoDetect } from '@serialport/bindings-cpp'
|
||||
import { HostAppService, PartialProfile, Platform, ProfilesService } from 'tabby-core'
|
||||
import { SerialPortInfo, SerialProfile } from '../api'
|
||||
import { SerialTabComponent } from '../components/serialTab.component'
|
||||
|
||||
@@ -8,13 +10,23 @@ import { SerialTabComponent } from '../components/serialTab.component'
|
||||
export class SerialService {
|
||||
private constructor (
|
||||
private profilesService: ProfilesService,
|
||||
private hostApp: HostAppService,
|
||||
) { }
|
||||
|
||||
detectBinding (): typeof AbstractBinding {
|
||||
return this.hostApp.platform === Platform.Web ? WSABinding : autoDetect()
|
||||
}
|
||||
|
||||
async listPorts (): Promise<SerialPortInfo[]> {
|
||||
return (await SerialPort.list()).map(x => ({
|
||||
name: x.path,
|
||||
description: `${x.manufacturer ?? ''} ${x.serialNumber ?? ''}`.trim() || undefined,
|
||||
}))
|
||||
try {
|
||||
return (await this.detectBinding().list()).map(x => ({
|
||||
name: x.path,
|
||||
description: `${x.manufacturer ?? ''} ${x.serialNumber ?? ''}`.trim() || undefined,
|
||||
}))
|
||||
} catch (err) {
|
||||
console.error('Failed to list serial ports', err)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
quickConnect (query: string): Promise<SerialTabComponent|null> {
|
||||
|
Reference in New Issue
Block a user