strongly typed partial profiles wip

This commit is contained in:
Eugene Pankov 2021-07-13 23:44:23 +02:00
parent 5ddf36d4c1
commit 2f13f3a401
16 changed files with 118 additions and 107 deletions

View file

@ -16,7 +16,7 @@ export { BootstrapData, PluginInfo, BOOTSTRAP_DATA } from './mainProcess'
export { HostWindowService } from './hostWindow'
export { HostAppService, Platform } from './hostApp'
export { FileProvider } from './fileProvider'
export { ProfileProvider, Profile, ProfileSettingsComponent } from './profileProvider'
export { ProfileProvider, Profile, PartialProfile, ProfileSettingsComponent } from './profileProvider'
export { PromptModalComponent } from '../components/promptModal.component'
export { AppService } from '../services/app.service'

View file

@ -1,45 +1,56 @@
/* eslint-disable @typescript-eslint/no-type-alias */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-empty-function */
import { BaseTabComponent } from '../components/baseTab.component'
import { NewTabParameters } from '../services/tabs.service'
export interface Profile {
id?: string
id: string
type: string
name: string
group?: string
options: Record<string, any>
options: any
icon?: string
color?: string
disableDynamicTitle?: boolean
disableDynamicTitle: boolean
weight?: number
isBuiltin?: boolean
isTemplate?: boolean
weight: number
isBuiltin: boolean
isTemplate: boolean
}
export interface ProfileSettingsComponent {
profile: Profile
export type PartialProfile<T extends Profile> = Omit<Omit<Omit<{
[K in keyof T]?: T[K]
}, 'options'>, 'type'>, 'name'> & {
type: string
name: string
options?: {
[K in keyof T['options']]?: T['options'][K]
}
}
export interface ProfileSettingsComponent<P extends Profile> {
profile: P
save?: () => void
}
export abstract class ProfileProvider {
export abstract class ProfileProvider<P extends Profile> {
id: string
name: string
supportsQuickConnect = false
settingsComponent?: new (...args: any[]) => ProfileSettingsComponent
settingsComponent?: new (...args: any[]) => ProfileSettingsComponent<P>
configDefaults = {}
abstract getBuiltinProfiles (): Promise<Profile[]>
abstract getBuiltinProfiles (): Promise<PartialProfile<P>[]>
abstract getNewTabParameters (profile: Profile): Promise<NewTabParameters<BaseTabComponent>>
abstract getNewTabParameters (profile: PartialProfile<P>): Promise<NewTabParameters<BaseTabComponent>>
abstract getDescription (profile: Profile): string
abstract getDescription (profile: PartialProfile<P>): string
quickConnect (query: string): Profile|null {
quickConnect (query: string): PartialProfile<P>|null {
return null
}
deleteProfile (profile: Profile): void { }
deleteProfile (profile: P): void { }
}

View file

@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'
import { ToolbarButton, ToolbarButtonProvider } from './api/toolbarButtonProvider'
import { HostAppService, Platform } from './api/hostApp'
import { Profile } from './api/profileProvider'
import { PartialProfile, Profile } from './api/profileProvider'
import { ConfigService } from './services/config.service'
import { HotkeysService } from './services/hotkeys.service'
import { ProfilesService } from './services/profiles.service'
@ -32,7 +32,7 @@ export class ButtonProvider extends ToolbarButtonProvider {
}
}
async launchProfile (profile: Profile) {
async launchProfile (profile: PartialProfile<Profile>) {
await this.profilesService.openNewTabForProfile(profile)
let recentProfiles = this.config.store.recentProfiles

View file

@ -1,7 +1,7 @@
import slugify from 'slugify'
import { v4 as uuidv4 } from 'uuid'
import { Injectable } from '@angular/core'
import { ConfigService, NewTabParameters, Profile, ProfileProvider } from './api'
import { ConfigService, NewTabParameters, PartialProfile, Profile, ProfileProvider } from './api'
import { SplitTabComponent, SplitTabRecoveryProvider } from './components/splitTab.component'
export interface SplitLayoutProfileOptions {
@ -13,7 +13,7 @@ export interface SplitLayoutProfile extends Profile {
}
@Injectable({ providedIn: 'root' })
export class SplitLayoutProfilesService extends ProfileProvider {
export class SplitLayoutProfilesService extends ProfileProvider<SplitLayoutProfile> {
id = 'split-layout'
name = 'Saved layout'
configDefaults = {
@ -29,7 +29,7 @@ export class SplitLayoutProfilesService extends ProfileProvider {
super()
}
async getBuiltinProfiles (): Promise<Profile[]> {
async getBuiltinProfiles (): Promise<PartialProfile<SplitLayoutProfile>[]> {
return []
}
@ -43,7 +43,7 @@ export class SplitLayoutProfilesService extends ProfileProvider {
async createProfile (tab: SplitTabComponent, name: string): Promise<void> {
const token = await tab.getRecoveryToken()
const profile: SplitLayoutProfile = {
const profile: PartialProfile<SplitLayoutProfile> = {
id: `${this.id}:custom:${slugify(name)}:${uuidv4()}`,
type: this.id,
name,

View file

@ -1,8 +1,8 @@
import { Injectable, Inject } from '@angular/core'
import { NewTabParameters } from './tabs.service'
import { BaseTabComponent } from '../components/baseTab.component'
import { Profile, ProfileProvider } from '../api/profileProvider'
import { SelectorOption } from '../api/selector'
import { PartialProfile, Profile, ProfileProvider } from '../api/profileProvider'
;import { SelectorOption } from '../api/selector'
import { AppService } from './app.service'
import { configMerge, ConfigProxy, ConfigService } from './config.service'
import { NotificationsService } from './notifications.service'
@ -29,15 +29,18 @@ export class ProfilesService {
private config: ConfigService,
private notifications: NotificationsService,
private selector: SelectorService,
@Inject(ProfileProvider) private profileProviders: ProfileProvider[],
@Inject(ProfileProvider) private profileProviders: ProfileProvider<Profile>[],
) { }
async openNewTabForProfile (profile: Profile): Promise<BaseTabComponent|null> {
async openNewTabForProfile <P extends Profile> (profile: PartialProfile<P>): Promise<BaseTabComponent|null> {
const params = await this.newTabParametersForProfile(profile)
if (params) {
const tab = this.app.openNewTab(params)
;(this.app.getParentTab(tab) ?? tab).color = profile.color ?? null
tab.setTitle(profile.name)
if (profile.name) {
tab.setTitle(profile.name)
}
if (profile.disableDynamicTitle) {
tab['enableDynamicTitle'] = false
}
@ -46,16 +49,16 @@ export class ProfilesService {
return null
}
async newTabParametersForProfile (profile: Profile): Promise<NewTabParameters<BaseTabComponent>|null> {
profile = this.getConfigProxyForProfile(profile)
return this.providerForProfile(profile)?.getNewTabParameters(profile) ?? null
async newTabParametersForProfile <P extends Profile> (profile: PartialProfile<P>): Promise<NewTabParameters<BaseTabComponent>|null> {
const fullProfile = this.getConfigProxyForProfile(profile)
return this.providerForProfile(fullProfile)?.getNewTabParameters(fullProfile) ?? null
}
getProviders (): ProfileProvider[] {
getProviders (): ProfileProvider<Profile>[] {
return [...this.profileProviders]
}
async getProfiles (): Promise<Profile[]> {
async getProfiles (): Promise<PartialProfile<Profile>[]> {
const lists = await Promise.all(this.config.enabledServices(this.profileProviders).map(x => x.getBuiltinProfiles()))
let list = lists.reduce((a, b) => a.concat(b), [])
list = [
@ -68,28 +71,29 @@ export class ProfilesService {
return list
}
providerForProfile (profile: Profile): ProfileProvider|null {
return this.profileProviders.find(x => x.id === profile.type) ?? null
providerForProfile <T extends Profile> (profile: PartialProfile<T>): ProfileProvider<T>|null {
const provider = this.profileProviders.find(x => x.id === profile.type) ?? null
return provider as unknown as ProfileProvider<T>|null
}
getDescription (profile: Profile): string|null {
getDescription <P extends Profile> (profile: PartialProfile<P>): string|null {
profile = this.getConfigProxyForProfile(profile)
return this.providerForProfile(profile)?.getDescription(profile) ?? null
}
selectorOptionForProfile <T> (profile: Profile): SelectorOption<T> {
profile = this.getConfigProxyForProfile(profile)
selectorOptionForProfile <P extends Profile, T> (profile: PartialProfile<P>): SelectorOption<T> {
const fullProfile = this.getConfigProxyForProfile(profile)
return {
icon: profile.icon,
name: profile.group ? `${profile.group} / ${profile.name}` : profile.name,
description: this.providerForProfile(profile)?.getDescription(profile),
name: profile.group ? `${fullProfile.group} / ${fullProfile.name}` : fullProfile.name,
description: this.providerForProfile(fullProfile)?.getDescription(fullProfile),
}
}
showProfileSelector (): Promise<Profile|null> {
return new Promise<Profile|null>(async (resolve, reject) => {
showProfileSelector (): Promise<PartialProfile<Profile>|null> {
return new Promise<PartialProfile<Profile>|null>(async (resolve, reject) => {
try {
const recentProfiles: Profile[] = this.config.store.recentProfiles
const recentProfiles: PartialProfile<Profile>[] = this.config.store.recentProfiles
let options: SelectorOption<void>[] = recentProfiles.map(p => ({
...this.selectorOptionForProfile(p),
@ -159,7 +163,7 @@ export class ProfilesService {
})
}
async quickConnect (query: string): Promise<Profile|null> {
async quickConnect (query: string): Promise<PartialProfile<Profile>|null> {
for (const provider of this.getProviders()) {
if (provider.supportsQuickConnect) {
const profile = provider.quickConnect(query)
@ -172,9 +176,9 @@ export class ProfilesService {
return null
}
getConfigProxyForProfile (profile: Profile): Profile {
getConfigProxyForProfile <T extends Profile> (profile: PartialProfile<T>): T {
const provider = this.providerForProfile(profile)
const defaults = configMerge(this.profileDefaults, provider?.configDefaults ?? {})
return new ConfigProxy(profile, defaults) as unknown as Profile
return new ConfigProxy(profile, defaults) as unknown as T
}
}

View file

@ -10,7 +10,7 @@ import { ProfileSettingsComponent } from 'tabby-core'
@Component({
template: require('./localProfileSettings.component.pug'),
})
export class LocalProfileSettingsComponent implements ProfileSettingsComponent {
export class LocalProfileSettingsComponent implements ProfileSettingsComponent<LocalProfile> {
profile: LocalProfile
constructor (

View file

@ -1,12 +1,12 @@
import deepClone from 'clone-deep'
import { Injectable, Inject } from '@angular/core'
import { ProfileProvider, Profile, NewTabParameters, ConfigService, SplitTabComponent, AppService } from 'tabby-core'
import { ProfileProvider, NewTabParameters, ConfigService, SplitTabComponent, AppService, PartialProfile } from 'tabby-core'
import { TerminalTabComponent } from './components/terminalTab.component'
import { LocalProfileSettingsComponent } from './components/localProfileSettings.component'
import { ShellProvider, Shell, SessionOptions } from './api'
import { ShellProvider, Shell, SessionOptions, LocalProfile } from './api'
@Injectable({ providedIn: 'root' })
export class LocalProfilesService extends ProfileProvider {
export class LocalProfilesService extends ProfileProvider<LocalProfile> {
id = 'local'
name = 'Local'
settingsComponent = LocalProfileSettingsComponent
@ -34,7 +34,7 @@ export class LocalProfilesService extends ProfileProvider {
super()
}
async getBuiltinProfiles (): Promise<Profile[]> {
async getBuiltinProfiles (): Promise<PartialProfile<LocalProfile>[]> {
return (await this.getShells()).map(shell => ({
id: `local:${shell.id}`,
type: 'local',
@ -45,20 +45,20 @@ export class LocalProfilesService extends ProfileProvider {
}))
}
async getNewTabParameters (profile: Profile): Promise<NewTabParameters<TerminalTabComponent>> {
async getNewTabParameters (profile: PartialProfile<LocalProfile>): Promise<NewTabParameters<TerminalTabComponent>> {
profile = deepClone(profile)
if (!profile.options?.cwd) {
if (this.app.activeTab instanceof TerminalTabComponent && this.app.activeTab.session) {
profile.options ??= {}
profile.options.cwd = await this.app.activeTab.session.getWorkingDirectory()
profile.options.cwd = await this.app.activeTab.session.getWorkingDirectory() ?? undefined
}
if (this.app.activeTab instanceof SplitTabComponent) {
const focusedTab = this.app.activeTab.getFocusedTab()
if (focusedTab instanceof TerminalTabComponent && focusedTab.session) {
profile.options ??= {}
profile.options.cwd = await focusedTab.session.getWorkingDirectory()
profile.options!.cwd = await focusedTab.session.getWorkingDirectory() ?? undefined
}
}
}
@ -84,7 +84,7 @@ export class LocalProfilesService extends ProfileProvider {
}
}
getDescription (profile: Profile): string {
return profile.options?.command
getDescription (profile: PartialProfile<LocalProfile>): string {
return profile.options?.command ?? ''
}
}

View file

@ -1,6 +1,6 @@
import * as fs from 'mz/fs'
import { Injectable } from '@angular/core'
import { Logger, LogService, ConfigService, ProfilesService } from 'tabby-core'
import { Logger, LogService, ConfigService, ProfilesService, PartialProfile } from 'tabby-core'
import { TerminalTabComponent } from '../components/terminalTab.component'
import { LocalProfile } from '../api'
@ -17,40 +17,42 @@ export class TerminalService {
this.logger = log.create('terminal')
}
async getDefaultProfile (): Promise<LocalProfile> {
async getDefaultProfile (): Promise<PartialProfile<LocalProfile>> {
const profiles = await this.profilesService.getProfiles()
let profile = profiles.find(x => x.id === this.config.store.terminal.profile)
if (!profile) {
profile = profiles.filter(x => x.type === 'local' && x.isBuiltin)[0]
}
return profile as LocalProfile
return profile as PartialProfile<LocalProfile>
}
/**
* Launches a new terminal with a specific shell and CWD
* @param pause Wait for a keypress when the shell exits
*/
async openTab (profile?: LocalProfile|null, cwd?: string|null, pause?: boolean): Promise<TerminalTabComponent> {
async openTab (profile?: PartialProfile<LocalProfile>|null, cwd?: string|null, pause?: boolean): Promise<TerminalTabComponent> {
if (!profile) {
profile = await this.getDefaultProfile()
}
cwd = cwd ?? profile.options.cwd
const fullProfile = this.profilesService.getConfigProxyForProfile(profile)
cwd = cwd ?? fullProfile.options.cwd
if (cwd && !fs.existsSync(cwd)) {
console.warn('Ignoring non-existent CWD:', cwd)
cwd = null
}
this.logger.info(`Starting profile ${profile.name}`, profile)
this.logger.info(`Starting profile ${fullProfile.name}`, fullProfile)
const options = {
...profile.options,
...fullProfile.options,
pauseAfterExit: pause,
cwd: cwd ?? undefined,
}
return (await this.profilesService.openNewTabForProfile({
...profile,
...fullProfile,
options,
})) as TerminalTabComponent
}

View file

@ -9,7 +9,7 @@ import { SerialService } from '../services/serial.service'
@Component({
template: require('./serialProfileSettings.component.pug'),
})
export class SerialProfileSettingsComponent implements ProfileSettingsComponent {
export class SerialProfileSettingsComponent implements ProfileSettingsComponent<SerialProfile> {
profile: SerialProfile
foundPorts: SerialPortInfo[]
Platform = Platform

View file

@ -10,7 +10,7 @@ import { SerialService } from './services/serial.service'
import { BAUD_RATES, SerialProfile } from './api'
@Injectable({ providedIn: 'root' })
export class SerialProfilesService extends ProfileProvider {
export class SerialProfilesService extends ProfileProvider<SerialProfile> {
id = 'serial'
name = 'Serial'
settingsComponent = SerialProfileSettingsComponent

View file

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core'
import SerialPort from 'serialport'
import { ProfilesService } from 'tabby-core'
import { PartialProfile, ProfilesService } from 'tabby-core'
import { SerialPortInfo, SerialProfile } from '../api'
import { SerialTabComponent } from '../components/serialTab.component'
@ -24,19 +24,12 @@ export class SerialService {
baudrate = parseInt(path.split('@')[1])
path = path.split('@')[0]
}
const profile: SerialProfile = {
const profile: PartialProfile<SerialProfile> = {
name: query,
type: 'serial',
options: {
port: path,
baudrate: baudrate,
databits: 8,
parity: 'none',
rtscts: false,
stopbits: 1,
xany: false,
xoff: false,
xon: false,
},
}
window.localStorage.lastSerialConnection = JSON.stringify(profile)

View file

@ -15,15 +15,15 @@ const iconsClassList = Object.keys(iconsData).map(
@Component({
template: require('./editProfileModal.component.pug'),
})
export class EditProfileModalComponent {
@Input() profile: Profile & ConfigProxy
@Input() profileProvider: ProfileProvider
@Input() settingsComponent: new () => ProfileSettingsComponent
export class EditProfileModalComponent<P extends Profile> {
@Input() profile: P & ConfigProxy
@Input() profileProvider: ProfileProvider<P>
@Input() settingsComponent: new () => ProfileSettingsComponent<P>
groupNames: string[]
@ViewChild('placeholder', { read: ViewContainerRef }) placeholder: ViewContainerRef
private _profile: Profile
private settingsComponentInstance: ProfileSettingsComponent
private settingsComponentInstance: ProfileSettingsComponent<P>
constructor (
private injector: Injector,

View file

@ -3,12 +3,12 @@ import slugify from 'slugify'
import deepClone from 'clone-deep'
import { Component } from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { ConfigService, HostAppService, Profile, SelectorService, ProfilesService, PromptModalComponent, PlatformService, BaseComponent } from 'tabby-core'
import { ConfigService, HostAppService, Profile, SelectorService, ProfilesService, PromptModalComponent, PlatformService, BaseComponent, PartialProfile } from 'tabby-core'
import { EditProfileModalComponent } from './editProfileModal.component'
interface ProfileGroup {
name?: string
profiles: Profile[]
profiles: PartialProfile<Profile>[]
editable: boolean
collapsed: boolean
}
@ -19,9 +19,9 @@ interface ProfileGroup {
styles: [require('./profilesSettingsTab.component.scss')],
})
export class ProfilesSettingsTabComponent extends BaseComponent {
profiles: Profile[] = []
builtinProfiles: Profile[] = []
templateProfiles: Profile[] = []
profiles: PartialProfile<Profile>[] = []
builtinProfiles: PartialProfile<Profile>[] = []
templateProfiles: PartialProfile<Profile>[] = []
profileGroups: ProfileGroup[]
filter = ''
@ -45,11 +45,11 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
this.subscribeUntilDestroyed(this.config.changed$, () => this.refresh())
}
launchProfile (profile: Profile): void {
launchProfile (profile: PartialProfile<Profile>): void {
this.profilesService.openNewTabForProfile(profile)
}
async newProfile (base?: Profile): Promise<void> {
async newProfile (base?: PartialProfile<Profile>): Promise<void> {
if (!base) {
const profiles = [...this.templateProfiles, ...this.builtinProfiles, ...this.profiles]
profiles.sort((a, b) => (a.weight ?? 0) - (b.weight ?? 0))
@ -57,7 +57,7 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
'Select a base profile to use as a template',
profiles.map(p => ({
icon: p.icon,
description: this.profilesService.providerForProfile(p)?.getDescription(p),
description: this.profilesService.getDescription(p) ?? undefined,
name: p.group ? `${p.group} / ${p.name}` : p.name,
result: p,
})),
@ -74,7 +74,7 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
await this.config.save()
}
async editProfile (profile: Profile): Promise<void> {
async editProfile (profile: PartialProfile<Profile>): Promise<void> {
const modal = this.ngbModal.open(
EditProfileModalComponent,
{ size: 'lg' },
@ -93,7 +93,7 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
await this.config.save()
}
async deleteProfile (profile: Profile): Promise<void> {
async deleteProfile (profile: PartialProfile<Profile>): Promise<void> {
if ((await this.platform.showMessageBox(
{
type: 'warning',
@ -102,7 +102,8 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
defaultId: 0,
}
)).response === 1) {
this.profilesService.providerForProfile(profile)?.deleteProfile(profile)
this.profilesService.providerForProfile(profile)?.deleteProfile(
this.profilesService.getConfigProxyForProfile(profile))
this.config.store.profiles = this.config.store.profiles.filter(x => x !== profile)
await this.config.save()
}
@ -181,7 +182,7 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
return !this.filter || group.profiles.some(x => this.isProfileVisible(x))
}
isProfileVisible (profile: Profile): boolean {
isProfileVisible (profile: PartialProfile<Profile>): boolean {
return !this.filter || profile.name.toLowerCase().includes(this.filter.toLowerCase())
}
@ -189,11 +190,11 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
return icon?.startsWith('<') ?? false
}
getDescription (profile: Profile): string|null {
getDescription (profile: PartialProfile<Profile>): string|null {
return this.profilesService.getDescription(profile)
}
getTypeLabel (profile: Profile): string {
getTypeLabel (profile: PartialProfile<Profile>): string {
const name = this.profilesService.providerForProfile(profile)?.name
if (name === 'Local') {
return ''
@ -201,7 +202,7 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
return name ?? 'Unknown'
}
getTypeColorClass (profile: Profile): string {
getTypeColorClass (profile: PartialProfile<Profile>): string {
return {
ssh: 'secondary',
serial: 'success',

View file

@ -1,5 +1,5 @@
import { Injectable } from '@angular/core'
import { ProfileProvider, Profile, NewTabParameters } from 'tabby-core'
import { ProfileProvider, NewTabParameters, PartialProfile } from 'tabby-core'
import { SSHProfileSettingsComponent } from './components/sshProfileSettings.component'
import { SSHTabComponent } from './components/sshTab.component'
import { PasswordStorageService } from './services/passwordStorage.service'
@ -8,7 +8,7 @@ import { ALGORITHM_BLACKLIST, SSHAlgorithmType, SSHProfile } from './api'
import * as ALGORITHMS from 'ssh2/lib/protocol/constants'
@Injectable({ providedIn: 'root' })
export class SSHProfilesService extends ProfileProvider {
export class SSHProfilesService extends ProfileProvider<SSHProfile> {
id = 'ssh'
name = 'SSH'
supportsQuickConnect = true
@ -66,7 +66,7 @@ export class SSHProfilesService extends ProfileProvider {
}
}
async getBuiltinProfiles (): Promise<Profile[]> {
async getBuiltinProfiles (): Promise<PartialProfile<SSHProfile>[]> {
return [{
id: `ssh:template`,
type: 'ssh',
@ -83,22 +83,22 @@ export class SSHProfilesService extends ProfileProvider {
}]
}
async getNewTabParameters (profile: Profile): Promise<NewTabParameters<SSHTabComponent>> {
async getNewTabParameters (profile: PartialProfile<SSHProfile>): Promise<NewTabParameters<SSHTabComponent>> {
return {
type: SSHTabComponent,
inputs: { profile },
}
}
getDescription (profile: SSHProfile): string {
return profile.options.host
getDescription (profile: PartialProfile<SSHProfile>): string {
return profile.options?.host ?? ''
}
deleteProfile (profile: SSHProfile): void {
this.passwordStorage.deletePassword(profile)
}
quickConnect (query: string): SSHProfile {
quickConnect (query: string): PartialProfile<SSHProfile> {
let user = 'root'
let host = query
let port = 22

View file

@ -8,6 +8,6 @@ import { TelnetProfile } from '../session'
@Component({
template: require('./telnetProfileSettings.component.pug'),
})
export class TelnetProfileSettingsComponent implements ProfileSettingsComponent {
export class TelnetProfileSettingsComponent implements ProfileSettingsComponent<TelnetProfile> {
profile: TelnetProfile
}

View file

@ -1,11 +1,11 @@
import { Injectable } from '@angular/core'
import { ProfileProvider, Profile, NewTabParameters } from 'tabby-core'
import { ProfileProvider, NewTabParameters, PartialProfile } from 'tabby-core'
import { TelnetProfileSettingsComponent } from './components/telnetProfileSettings.component'
import { TelnetTabComponent } from './components/telnetTab.component'
import { TelnetProfile } from './session'
@Injectable({ providedIn: 'root' })
export class TelnetProfilesService extends ProfileProvider {
export class TelnetProfilesService extends ProfileProvider<TelnetProfile> {
id = 'telnet'
name = 'Telnet'
supportsQuickConnect = false
@ -22,7 +22,7 @@ export class TelnetProfilesService extends ProfileProvider {
},
}
async getBuiltinProfiles (): Promise<TelnetProfile[]> {
async getBuiltinProfiles (): Promise<PartialProfile<TelnetProfile>[]> {
return [
{
id: `telnet:template`,
@ -55,7 +55,7 @@ export class TelnetProfilesService extends ProfileProvider {
]
}
async getNewTabParameters (profile: Profile): Promise<NewTabParameters<TelnetTabComponent>> {
async getNewTabParameters (profile: PartialProfile<TelnetProfile>): Promise<NewTabParameters<TelnetTabComponent>> {
return {
type: TelnetTabComponent,
inputs: { profile },
@ -66,7 +66,7 @@ export class TelnetProfilesService extends ProfileProvider {
return profile.options.host ? `${profile.options.host}:${profile.options.port}` : ''
}
quickConnect (query: string): TelnetProfile {
quickConnect (query: string): PartialProfile<TelnetProfile> {
let host = query
let port = 23
if (host.includes('[')) {