From 461cd2bec73b2b1fe6902ac7c68ca949e8d7f4a6 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Mon, 5 Jul 2021 22:52:32 +0200 Subject: [PATCH] deprecated matchedHotkey --- tabby-core/src/buttonProvider.ts | 16 +++--- .../src/components/appRoot.component.ts | 2 +- .../src/components/splitTab.component.ts | 2 +- .../src/components/tabHeader.component.ts | 2 +- tabby-core/src/index.ts | 2 +- tabby-core/src/services/hotkeys.service.ts | 2 + tabby-core/src/services/profiles.service.ts | 9 ++++ .../src/components/terminalTab.component.ts | 2 +- tabby-local/src/index.ts | 2 +- .../src/components/serialTab.component.ts | 2 +- tabby-settings/src/buttonProvider.ts | 2 +- tabby-ssh/src/components/sshTab.component.ts | 2 +- tabby-ssh/src/config.ts | 1 + tabby-ssh/src/hotkeys.ts | 4 ++ tabby-ssh/src/index.ts | 53 +++++++++++++++++-- .../src/components/telnetTab.component.ts | 2 +- tabby-telnet/src/config.ts | 1 + tabby-telnet/src/hotkeys.ts | 4 ++ tabby-telnet/src/index.ts | 52 ++++++++++++++++-- tabby-telnet/src/profiles.ts | 9 +--- .../src/api/baseTerminalTab.component.ts | 2 +- 21 files changed, 141 insertions(+), 32 deletions(-) diff --git a/tabby-core/src/buttonProvider.ts b/tabby-core/src/buttonProvider.ts index d4d7684a..c64d3b15 100644 --- a/tabby-core/src/buttonProvider.ts +++ b/tabby-core/src/buttonProvider.ts @@ -7,10 +7,10 @@ import { HostAppService, Platform } from './api/hostApp' import { Profile } from './api/profileProvider' import { ConfigService } from './services/config.service' import { SelectorOption } from './api/selector' +import { HotkeysService } from './services/hotkeys.service' import { ProfilesService } from './services/profiles.service' import { AppService } from './services/app.service' import { NotificationsService } from './services/notifications.service' -import { HotkeysService } from 'api' /** @hidden */ @Injectable() @@ -35,12 +35,14 @@ export class ButtonProvider extends ToolbarButtonProvider { async activate () { const recentProfiles: Profile[] = this.config.store.recentProfiles - const getProfileOptions = (profile): SelectorOption => ({ - icon: recentProfiles.includes(profile) ? 'fas fa-history' : profile.icon, - name: profile.group ? `${profile.group} / ${profile.name}` : profile.name, - description: this.profilesServices.providerForProfile(profile)?.getDescription(profile), - callback: () => this.launchProfile(profile), - }) + const getProfileOptions = (profile): SelectorOption => { + const result: SelectorOption = this.profilesServices.selectorOptionForProfile(profile) + if (recentProfiles.includes(profile)) { + result.icon = 'fas fa-history' + } + result.callback = () => this.launchProfile(profile) + return result + } let options = recentProfiles.map(getProfileOptions) if (recentProfiles.length) { diff --git a/tabby-core/src/components/appRoot.component.ts b/tabby-core/src/components/appRoot.component.ts index 3c0bbe83..92972cac 100644 --- a/tabby-core/src/components/appRoot.component.ts +++ b/tabby-core/src/components/appRoot.component.ts @@ -80,7 +80,7 @@ export class AppRootComponent { this.logger = log.create('main') this.logger.info('v', platform.getAppVersion()) - this.hotkeys.matchedHotkey.subscribe((hotkey: string) => { + this.hotkeys.hotkey$.subscribe((hotkey: string) => { if (hotkey.startsWith('tab-')) { const index = parseInt(hotkey.split('-')[1]) if (index <= this.app.tabs.length) { diff --git a/tabby-core/src/components/splitTab.component.ts b/tabby-core/src/components/splitTab.component.ts index 5d0370ad..221fac51 100644 --- a/tabby-core/src/components/splitTab.component.ts +++ b/tabby-core/src/components/splitTab.component.ts @@ -209,7 +209,7 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit }) this.blurred$.subscribe(() => this.getAllTabs().forEach(x => x.emitBlurred())) - this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, hotkey => { + this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => { if (!this.hasFocus || !this.focusedTab) { return } diff --git a/tabby-core/src/components/tabHeader.component.ts b/tabby-core/src/components/tabHeader.component.ts index c1414a0e..3e52352b 100644 --- a/tabby-core/src/components/tabHeader.component.ts +++ b/tabby-core/src/components/tabHeader.component.ts @@ -43,7 +43,7 @@ export class TabHeaderComponent extends BaseComponent { @Optional() @Inject(TabContextMenuItemProvider) protected contextMenuProviders: TabContextMenuItemProvider[], ) { super() - this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, (hotkey) => { + this.subscribeUntilDestroyed(this.hotkeys.hotkey$, (hotkey) => { if (this.app.activeTab === this.tab) { if (hotkey === 'rename-tab') { this.showRenameTabModal() diff --git a/tabby-core/src/index.ts b/tabby-core/src/index.ts index 550d5f8e..130bc159 100644 --- a/tabby-core/src/index.ts +++ b/tabby-core/src/index.ts @@ -135,7 +135,7 @@ export default class AppModule { // eslint-disable-line @typescript-eslint/no-ex console.error('Unhandled exception:', err) }) - hotkeys.matchedHotkey.subscribe(async (hotkey) => { + hotkeys.hotkey$.subscribe(async (hotkey) => { if (hotkey.startsWith('profile.')) { const id = hotkey.split('.')[1] const profile = (await profilesService.getProfiles()).find(x => x.id === id) diff --git a/tabby-core/src/services/hotkeys.service.ts b/tabby-core/src/services/hotkeys.service.ts index dd1af5a4..54fa3f2d 100644 --- a/tabby-core/src/services/hotkeys.service.ts +++ b/tabby-core/src/services/hotkeys.service.ts @@ -3,6 +3,7 @@ import { Observable, Subject } from 'rxjs' import { HotkeyDescription, HotkeyProvider } from '../api/hotkeyProvider' import { stringifyKeySequence, EventData } from './hotkeys.util' import { ConfigService } from './config.service' +import { deprecate } from 'util' export interface PartialHotkeyMatch { id: string @@ -53,6 +54,7 @@ export class HotkeysService { // deprecated this.hotkey$.subscribe(h => this.matchedHotkey.emit(h)) + this.matchedHotkey.subscribe = deprecate(this.matchedHotkey.subscribe, 'matchedHotkey is deprecated, use hotkey$') } /** diff --git a/tabby-core/src/services/profiles.service.ts b/tabby-core/src/services/profiles.service.ts index 4a4230cc..4fe56a01 100644 --- a/tabby-core/src/services/profiles.service.ts +++ b/tabby-core/src/services/profiles.service.ts @@ -2,6 +2,7 @@ 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 { AppService } from './app.service' import { ConfigService } from './config.service' @@ -51,4 +52,12 @@ export class ProfilesService { providerForProfile (profile: Profile): ProfileProvider|null { return this.profileProviders.find(x => x.id === profile.type) ?? null } + + selectorOptionForProfile (profile: Profile): SelectorOption { + return { + icon: profile.icon, + name: profile.group ? `${profile.group} / ${profile.name}` : profile.name, + description: this.providerForProfile(profile)?.getDescription(profile), + } + } } diff --git a/tabby-local/src/components/terminalTab.component.ts b/tabby-local/src/components/terminalTab.component.ts index 5cf55a45..9fe60427 100644 --- a/tabby-local/src/components/terminalTab.component.ts +++ b/tabby-local/src/components/terminalTab.component.ts @@ -30,7 +30,7 @@ export class TerminalTabComponent extends BaseTerminalTabComponent { const isConPTY = isWindowsBuild(WIN_BUILD_CONPTY_SUPPORTED) && this.config.store.terminal.useConPTY - this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, hotkey => { + this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => { if (!this.hasFocus) { return } diff --git a/tabby-local/src/index.ts b/tabby-local/src/index.ts index 070a2962..92fd7d7f 100644 --- a/tabby-local/src/index.ts +++ b/tabby-local/src/index.ts @@ -116,7 +116,7 @@ export default class LocalTerminalModule { // eslint-disable-line @typescript-es dockMenu: DockMenuService, config: ConfigService, ) { - hotkeys.matchedHotkey.subscribe(async (hotkey) => { + hotkeys.hotkey$.subscribe(async (hotkey) => { if (hotkey === 'new-tab') { terminal.openTab() } diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index 971868dc..32541fc5 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -29,7 +29,7 @@ export class SerialTabComponent extends BaseTerminalTabComponent { ngOnInit () { this.logger = this.log.create('terminalTab') - this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, hotkey => { + this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => { if (!this.hasFocus) { return } diff --git a/tabby-settings/src/buttonProvider.ts b/tabby-settings/src/buttonProvider.ts index c26c1709..9d342c73 100644 --- a/tabby-settings/src/buttonProvider.ts +++ b/tabby-settings/src/buttonProvider.ts @@ -14,7 +14,7 @@ export class ButtonProvider extends ToolbarButtonProvider { super() hostApp.settingsUIRequest$.subscribe(() => this.open()) - hotkeys.matchedHotkey.subscribe(async (hotkey) => { + hotkeys.hotkey$.subscribe(async (hotkey) => { if (hotkey === 'settings') { this.open() } diff --git a/tabby-ssh/src/components/sshTab.component.ts b/tabby-ssh/src/components/sshTab.component.ts index 15f04738..afe827b8 100644 --- a/tabby-ssh/src/components/sshTab.component.ts +++ b/tabby-ssh/src/components/sshTab.component.ts @@ -41,7 +41,7 @@ export class SSHTabComponent extends BaseTerminalTabComponent { this.logger = this.log.create('terminalTab') - this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, hotkey => { + this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => { if (!this.hasFocus) { return } diff --git a/tabby-ssh/src/config.ts b/tabby-ssh/src/config.ts index eea5b1e9..468e5d34 100644 --- a/tabby-ssh/src/config.ts +++ b/tabby-ssh/src/config.ts @@ -10,6 +10,7 @@ export class SSHConfigProvider extends ConfigProvider { agentPath: null, }, hotkeys: { + 'ssh-profile-selector': [], 'restart-ssh-session': [], 'launch-winscp': [], }, diff --git a/tabby-ssh/src/hotkeys.ts b/tabby-ssh/src/hotkeys.ts index 658d06c3..96e538bc 100644 --- a/tabby-ssh/src/hotkeys.ts +++ b/tabby-ssh/src/hotkeys.ts @@ -5,6 +5,10 @@ import { HotkeyDescription, HotkeyProvider } from 'tabby-core' @Injectable() export class SSHHotkeyProvider extends HotkeyProvider { hotkeys: HotkeyDescription[] = [ + { + id: 'ssh-profile-selector', + name: 'Show SSH profile selector', + }, { id: 'restart-ssh-session', name: 'Restart current SSH session', diff --git a/tabby-ssh/src/index.ts b/tabby-ssh/src/index.ts index 5ab66075..11ee7235 100644 --- a/tabby-ssh/src/index.ts +++ b/tabby-ssh/src/index.ts @@ -4,8 +4,8 @@ import { FormsModule } from '@angular/forms' import { NgbModule } from '@ng-bootstrap/ng-bootstrap' import { ToastrModule } from 'ngx-toastr' import { NgxFilesizeModule } from 'ngx-filesize' -import TabbyCoreModule, { ConfigProvider, TabRecoveryProvider, HotkeyProvider, TabContextMenuItemProvider, ProfileProvider } from 'tabby-core' -import { SettingsTabProvider } from 'tabby-settings' +import TabbyCoreModule, { ConfigProvider, TabRecoveryProvider, HotkeyProvider, TabContextMenuItemProvider, ProfileProvider, HotkeysService, ProfilesService, AppService, SelectorService, SelectorOption } from 'tabby-core' +import { SettingsTabComponent, SettingsTabProvider } from 'tabby-settings' import TabbyTerminalModule from 'tabby-terminal' import { SSHProfileSettingsComponent } from './components/sshProfileSettings.component' @@ -40,7 +40,7 @@ import { SSHProfilesService } from './profiles' { provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true }, { provide: HotkeyProvider, useClass: SSHHotkeyProvider, multi: true }, { provide: TabContextMenuItemProvider, useClass: SFTPContextMenu, multi: true }, - { provide: ProfileProvider, useClass: SSHProfilesService, multi: true }, + { provide: ProfileProvider, useExisting: SSHProfilesService, multi: true }, ], entryComponents: [ SSHProfileSettingsComponent, @@ -59,4 +59,49 @@ import { SSHProfilesService } from './profiles' SFTPPanelComponent, ], }) -export default class SSHModule { } // eslint-disable-line @typescript-eslint/no-extraneous-class +export default class SSHModule { + constructor ( + hotkeys: HotkeysService, + private app: AppService, + private selector: SelectorService, + private profilesService: ProfilesService, + private sshProfiles: SSHProfilesService, + ) { + hotkeys.hotkey$.subscribe(hotkey => { + if (hotkey === 'ssh-profile-selector') { + this.showSelector() + } + }) + } + + async showSelector (): Promise { + let profiles = await this.profilesService.getProfiles() + + profiles = profiles.filter(x => !x.isTemplate && x.type === 'ssh') + + const options: SelectorOption[] = profiles.map(p => ({ + ...this.profilesService.selectorOptionForProfile(p), + callback: () => this.profilesService.openNewTabForProfile(p), + })) + + options.push({ + name: 'Manage profiles', + icon: 'fas fa-window-restore', + callback: () => this.app.openNewTabRaw({ + type: SettingsTabComponent, + inputs: { activeTab: 'profiles' }, + }), + }) + + options.push({ + name: 'Quick connect', + freeInputPattern: 'Connect to "%s"...', + icon: 'fas fa-arrow-right', + callback: query => this.profilesService.openNewTabForProfile( + this.sshProfiles.quickConnect(query) + ), + }) + + await this.selector.show('Select an SSH profile', options) + } +} diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index 31902b35..710731c3 100644 --- a/tabby-telnet/src/components/telnetTab.component.ts +++ b/tabby-telnet/src/components/telnetTab.component.ts @@ -33,7 +33,7 @@ export class TelnetTabComponent extends BaseTerminalTabComponent { this.logger = this.log.create('telnetTab') - this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, hotkey => { + this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => { if (this.hasFocus && hotkey === 'restart-telnet-session') { this.reconnect() } diff --git a/tabby-telnet/src/config.ts b/tabby-telnet/src/config.ts index 6931a786..26293834 100644 --- a/tabby-telnet/src/config.ts +++ b/tabby-telnet/src/config.ts @@ -4,6 +4,7 @@ import { ConfigProvider } from 'tabby-core' export class TelnetConfigProvider extends ConfigProvider { defaults = { hotkeys: { + 'telnet-profile-selector': [], 'restart-telnet-session': [], }, } diff --git a/tabby-telnet/src/hotkeys.ts b/tabby-telnet/src/hotkeys.ts index 9e2bb6be..9898dc88 100644 --- a/tabby-telnet/src/hotkeys.ts +++ b/tabby-telnet/src/hotkeys.ts @@ -5,6 +5,10 @@ import { HotkeyDescription, HotkeyProvider } from 'tabby-core' @Injectable() export class TelnetHotkeyProvider extends HotkeyProvider { hotkeys: HotkeyDescription[] = [ + { + id: 'telnet-profile-selector', + name: 'Show Telnet profile selector', + }, { id: 'restart-telnet-session', name: 'Restart current Telnet session', diff --git a/tabby-telnet/src/index.ts b/tabby-telnet/src/index.ts index 8a18a7fc..1e970de1 100644 --- a/tabby-telnet/src/index.ts +++ b/tabby-telnet/src/index.ts @@ -4,8 +4,9 @@ import { FormsModule } from '@angular/forms' import { NgbModule } from '@ng-bootstrap/ng-bootstrap' import { ToastrModule } from 'ngx-toastr' import { NgxFilesizeModule } from 'ngx-filesize' -import TabbyCoreModule, { ConfigProvider, TabRecoveryProvider, HotkeyProvider, ProfileProvider } from 'tabby-core' +import TabbyCoreModule, { ConfigProvider, TabRecoveryProvider, HotkeyProvider, ProfileProvider, HotkeysService, AppService, SelectorService, ProfilesService, SelectorOption } from 'tabby-core' import TabbyTerminalModule from 'tabby-terminal' +import { SettingsTabComponent } from 'tabby-settings' import { TelnetProfileSettingsComponent } from './components/telnetProfileSettings.component' import { TelnetTabComponent } from './components/telnetTab.component' @@ -30,7 +31,7 @@ import { TelnetProfilesService } from './profiles' { provide: ConfigProvider, useClass: TelnetConfigProvider, multi: true }, { provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true }, { provide: HotkeyProvider, useClass: TelnetHotkeyProvider, multi: true }, - { provide: ProfileProvider, useClass: TelnetProfilesService, multi: true }, + { provide: ProfileProvider, useExisting: TelnetProfilesService, multi: true }, ], entryComponents: [ TelnetProfileSettingsComponent, @@ -41,4 +42,49 @@ import { TelnetProfilesService } from './profiles' TelnetTabComponent, ], }) -export default class TelnetModule { } // eslint-disable-line @typescript-eslint/no-extraneous-class +export default class TelnetModule { + constructor ( + hotkeys: HotkeysService, + private app: AppService, + private selector: SelectorService, + private profilesService: ProfilesService, + private telnetProfiles: TelnetProfilesService, + ) { + hotkeys.hotkey$.subscribe(hotkey => { + if (hotkey === 'telnet-profile-selector') { + this.showSelector() + } + }) + } + + async showSelector (): Promise { + let profiles = await this.profilesService.getProfiles() + + profiles = profiles.filter(x => !x.isTemplate && x.type === 'telnet') + + const options: SelectorOption[] = profiles.map(p => ({ + ...this.profilesService.selectorOptionForProfile(p), + callback: () => this.profilesService.openNewTabForProfile(p), + })) + + options.push({ + name: 'Manage profiles', + icon: 'fas fa-window-restore', + callback: () => this.app.openNewTabRaw({ + type: SettingsTabComponent, + inputs: { activeTab: 'profiles' }, + }), + }) + + options.push({ + name: 'Quick connect', + freeInputPattern: 'Connect to "%s"...', + icon: 'fas fa-arrow-right', + callback: query => this.profilesService.openNewTabForProfile( + this.telnetProfiles.quickConnect(query) + ), + }) + + await this.selector.show('Select an Telnet profile', options) + } +} diff --git a/tabby-telnet/src/profiles.ts b/tabby-telnet/src/profiles.ts index 26f88558..76e36c68 100644 --- a/tabby-telnet/src/profiles.ts +++ b/tabby-telnet/src/profiles.ts @@ -8,7 +8,7 @@ import { TelnetProfile } from './session' export class TelnetProfilesService extends ProfileProvider { id = 'telnet' name = 'Telnet' - supportsQuickConnect = true + supportsQuickConnect = false settingsComponent = TelnetProfileSettingsComponent async getBuiltinProfiles (): Promise { @@ -41,12 +41,7 @@ export class TelnetProfilesService extends ProfileProvider { return profile.options.host ? `${profile.options.host}:${profile.options.port}` : '' } - quickConnect (query: string): TelnetProfile|null { - if (!query.startsWith('telnet:')) { - return null - } - query = query.substring('telnet:'.length) - + quickConnect (query: string): TelnetProfile { let host = query let port = 23 if (host.includes('[')) { diff --git a/tabby-terminal/src/api/baseTerminalTab.component.ts b/tabby-terminal/src/api/baseTerminalTab.component.ts index 42af78d8..11b70c2d 100644 --- a/tabby-terminal/src/api/baseTerminalTab.component.ts +++ b/tabby-terminal/src/api/baseTerminalTab.component.ts @@ -174,7 +174,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit this.logger = this.log.create('baseTerminalTab') this.setTitle('Terminal') - this.subscribeUntilDestroyed(this.hotkeys.matchedHotkey, async hotkey => { + this.subscribeUntilDestroyed(this.hotkeys.hotkey$, async hotkey => { if (!this.hasFocus) { return }