mirror of
https://github.com/eugeny/tabby
synced 2026-09-25 14:36:01 +00:00
fix(serial): fix serial quickConnect not working (#11384)
Co-authored-by: Eugene <inbox@null.page>
This commit is contained in:
@@ -2,14 +2,14 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'
|
||||
import slugify from 'slugify'
|
||||
import deepClone from 'clone-deep'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { NewTabParameters, SelectorService, HostAppService, Platform, TranslateService, ConnectableProfileProvider } from 'tabby-core'
|
||||
import { NewTabParameters, PartialProfile, SelectorService, HostAppService, Platform, TranslateService, QuickConnectProfileProvider } from 'tabby-core'
|
||||
import { SerialProfileSettingsComponent } from './components/serialProfileSettings.component'
|
||||
import { SerialTabComponent } from './components/serialTab.component'
|
||||
import { SerialService } from './services/serial.service'
|
||||
import { BAUD_RATES, SerialProfile } from './api'
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class SerialProfilesService extends ConnectableProfileProvider<SerialProfile> {
|
||||
export class SerialProfilesService extends QuickConnectProfileProvider<SerialProfile> {
|
||||
id = 'serial'
|
||||
name = _('Serial')
|
||||
settingsComponent = SerialProfileSettingsComponent
|
||||
@@ -104,4 +104,35 @@ export class SerialProfilesService extends ConnectableProfileProvider<SerialProf
|
||||
getDescription (profile: SerialProfile): string {
|
||||
return profile.options.port
|
||||
}
|
||||
|
||||
quickConnect (query: string): PartialProfile<SerialProfile> {
|
||||
let port = query
|
||||
let baudrate = 115200
|
||||
if (query.includes('@')) {
|
||||
baudrate = parseInt(port.split('@')[1]) || baudrate
|
||||
port = port.split('@')[0]
|
||||
} else if (query.includes(':')) {
|
||||
baudrate = parseInt(port.split(':')[1]) || baudrate
|
||||
port = port.split(':')[0]
|
||||
}
|
||||
|
||||
return {
|
||||
name: query,
|
||||
type: 'serial',
|
||||
options: {
|
||||
port,
|
||||
baudrate,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
intoQuickConnectString (profile: SerialProfile): string|null {
|
||||
if (!profile.options.port) {
|
||||
return null
|
||||
}
|
||||
// baudrate defaults to null ("not chosen yet"), unlike ssh/telnet's real port
|
||||
// defaults - so null and 115200 both render bare, and both parse back to 115200
|
||||
const { port, baudrate } = profile.options
|
||||
return baudrate && baudrate !== 115200 ? `${port}@${baudrate}` : port
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import { Injectable, Injector } from '@angular/core'
|
||||
import { Injectable } from '@angular/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'
|
||||
import { HostAppService, Platform } from 'tabby-core'
|
||||
import { SerialPortInfo } from '../api'
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class SerialService {
|
||||
private constructor (
|
||||
private injector: Injector,
|
||||
private hostApp: HostAppService,
|
||||
) { }
|
||||
|
||||
@@ -28,23 +26,4 @@ export class SerialService {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
quickConnect (query: string): Promise<SerialTabComponent|null> {
|
||||
let path = query
|
||||
let baudrate = 115200
|
||||
if (query.includes('@')) {
|
||||
baudrate = parseInt(path.split('@')[1])
|
||||
path = path.split('@')[0]
|
||||
}
|
||||
const profile: PartialProfile<SerialProfile> = {
|
||||
name: query,
|
||||
type: 'serial',
|
||||
options: {
|
||||
port: path,
|
||||
baudrate: baudrate,
|
||||
},
|
||||
}
|
||||
window.localStorage.lastSerialConnection = JSON.stringify(profile)
|
||||
return this.injector.get(ProfilesService).openNewTabForProfile(profile) as Promise<SerialTabComponent|null>
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user