diff --git a/tabby-serial/src/profiles.ts b/tabby-serial/src/profiles.ts index 8b00ab122..bf16a3dfb 100644 --- a/tabby-serial/src/profiles.ts +++ b/tabby-serial/src/profiles.ts @@ -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 { +export class SerialProfilesService extends QuickConnectProfileProvider { id = 'serial' name = _('Serial') settingsComponent = SerialProfileSettingsComponent @@ -104,4 +104,35 @@ export class SerialProfilesService extends ConnectableProfileProvider { + 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 + } } diff --git a/tabby-serial/src/services/serial.service.ts b/tabby-serial/src/services/serial.service.ts index 6794f213f..38ffaa4f7 100644 --- a/tabby-serial/src/services/serial.service.ts +++ b/tabby-serial/src/services/serial.service.ts @@ -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 { - let path = query - let baudrate = 115200 - if (query.includes('@')) { - baudrate = parseInt(path.split('@')[1]) - path = path.split('@')[0] - } - const profile: PartialProfile = { - name: query, - type: 'serial', - options: { - port: path, - baudrate: baudrate, - }, - } - window.localStorage.lastSerialConnection = JSON.stringify(profile) - return this.injector.get(ProfilesService).openNewTabForProfile(profile) as Promise - } }