Skip to content

Commit

Permalink
Merge pull request #8726 from Clem-Fern/profiles-rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Aug 25, 2023
2 parents f963167 + eddb50b commit 4684b0d
Show file tree
Hide file tree
Showing 39 changed files with 775 additions and 263 deletions.
2 changes: 1 addition & 1 deletion tabby-core/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, PartialProfile, ProfileSettingsComponent } from './profileProvider'
export { ProfileProvider, ConnectableProfileProvider, QuickConnectProfileProvider, Profile, ConnectableProfile, PartialProfile, ProfileSettingsComponent, ProfileGroup, PartialProfileGroup } from './profileProvider'
export { PromptModalComponent } from '../components/promptModal.component'
export * from './commands'

Expand Down
36 changes: 28 additions & 8 deletions tabby-core/src/api/profileProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface Profile {
isTemplate: boolean
}

export interface ConnectableProfile extends Profile {
clearServiceMessagesOnConnect: boolean
}

export type PartialProfile<T extends Profile> = Omit<Omit<Omit<{
[K in keyof T]?: T[K]
}, 'options'>, 'type'>, 'name'> & {
Expand All @@ -31,6 +35,21 @@ export type PartialProfile<T extends Profile> = Omit<Omit<Omit<{
}
}

export interface ProfileGroup {
id: string
name: string
profiles: PartialProfile<Profile>[]
defaults: any
editable: boolean
}

export type PartialProfileGroup<T extends ProfileGroup> = Omit<Omit<{
[K in keyof T]?: T[K]
}, 'id'>, 'name'> & {
id: string
name: string
}

export interface ProfileSettingsComponent<P extends Profile> {
profile: P
save?: () => void
Expand All @@ -39,7 +58,6 @@ export interface ProfileSettingsComponent<P extends Profile> {
export abstract class ProfileProvider<P extends Profile> {
id: string
name: string
supportsQuickConnect = false
settingsComponent?: new (...args: any[]) => ProfileSettingsComponent<P>
configDefaults = {}

Expand All @@ -53,13 +71,15 @@ export abstract class ProfileProvider<P extends Profile> {

abstract getDescription (profile: PartialProfile<P>): string

quickConnect (query: string): PartialProfile<P>|null {
return null
}
deleteProfile (profile: P): void { }
}

intoQuickConnectString (profile: P): string|null {
return null
}
export abstract class ConnectableProfileProvider<P extends ConnectableProfile> extends ProfileProvider<P> {}

export abstract class QuickConnectProfileProvider<P extends ConnectableProfile> extends ConnectableProfileProvider<P> {

abstract quickConnect (query: string): PartialProfile<P>|null

abstract intoQuickConnectString (profile: P): string|null

deleteProfile (profile: P): void { }
}
2 changes: 1 addition & 1 deletion tabby-core/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CoreCommandProvider extends CommandProvider {
}

async activate () {
const profile = await this.profilesService.showProfileSelector()
const profile = await this.profilesService.showProfileSelector().catch(() => null)
if (profile) {
this.profilesService.launchProfile(profile)
}
Expand Down
2 changes: 1 addition & 1 deletion tabby-core/src/components/selectorModal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class SelectorModalComponent<T> {
{ sort: true },
).search(f)

this.options.filter(x => x.freeInputPattern).forEach(freeOption => {
this.options.filter(x => x.freeInputPattern).sort(firstBy<SelectorOption<T>, number>(x => x.weight ?? 0)).forEach(freeOption => {
if (!this.filteredOptions.includes(freeOption)) {
this.filteredOptions.push(freeOption)
}
Expand Down
1 change: 1 addition & 0 deletions tabby-core/src/configDefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ hotkeys:
profile-selectors:
__nonStructural: true
profiles: []
groups: []
profileDefaults:
__nonStructural: true
ssh:
Expand Down
6 changes: 1 addition & 5 deletions tabby-core/src/hotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Injectable } from '@angular/core'
import { TranslateService } from '@ngx-translate/core'
import { ProfilesService } from './services/profiles.service'
import { HotkeyDescription, HotkeyProvider } from './api/hotkeyProvider'
import { PartialProfile, Profile } from './api'

/** @hidden */
@Injectable()
Expand Down Expand Up @@ -268,7 +267,7 @@ export class AppHotkeyProvider extends HotkeyProvider {
return [
...this.hotkeys,
...profiles.map(profile => ({
id: `profile.${AppHotkeyProvider.getProfileHotkeyName(profile)}`,
id: `profile.${ProfilesService.getProfileHotkeyName(profile)}`,
name: this.translate.instant('New tab: {profile}', { profile: profile.name }),
})),
...this.profilesService.getProviders().map(provider => ({
Expand All @@ -278,7 +277,4 @@ export class AppHotkeyProvider extends HotkeyProvider {
]
}

static getProfileHotkeyName (profile: PartialProfile<Profile>): string {
return (profile.id ?? profile.name).replace(/\./g, '-')
}
}
10 changes: 5 additions & 5 deletions tabby-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { FastHtmlBindDirective } from './directives/fastHtmlBind.directive'
import { DropZoneDirective } from './directives/dropZone.directive'
import { CdkAutoDropGroup } from './directives/cdkAutoDropGroup.directive'

import { Theme, CLIHandler, TabContextMenuItemProvider, TabRecoveryProvider, HotkeyProvider, ConfigProvider, PlatformService, FileProvider, ProfilesService, ProfileProvider, SelectorOption, Profile, SelectorService, CommandProvider } from './api'
import { Theme, CLIHandler, TabContextMenuItemProvider, TabRecoveryProvider, HotkeyProvider, ConfigProvider, PlatformService, FileProvider, ProfilesService, ProfileProvider, QuickConnectProfileProvider, SelectorOption, Profile, SelectorService, CommandProvider } from './api'

import { AppService } from './services/app.service'
import { ConfigService } from './services/config.service'
Expand Down Expand Up @@ -177,7 +177,7 @@ export default class AppModule { // eslint-disable-line @typescript-eslint/no-ex
if (hotkey.startsWith('profile.')) {
const id = hotkey.substring(hotkey.indexOf('.') + 1)
const profiles = await profilesService.getProfiles()
const profile = profiles.find(x => AppHotkeyProvider.getProfileHotkeyName(x) === id)
const profile = profiles.find(x => ProfilesService.getProfileHotkeyName(x) === id)
if (profile) {
profilesService.openNewTabForProfile(profile)
}
Expand All @@ -191,7 +191,7 @@ export default class AppModule { // eslint-disable-line @typescript-eslint/no-ex
this.showSelector(provider)
}
if (hotkey === 'command-selector') {
commands.showSelector()
commands.showSelector().catch(() => {return})
}

if (hotkey === 'profile-selector') {
Expand All @@ -214,7 +214,7 @@ export default class AppModule { // eslint-disable-line @typescript-eslint/no-ex
callback: () => this.profilesService.openNewTabForProfile(p),
}))

if (provider.supportsQuickConnect) {
if (provider instanceof QuickConnectProfileProvider) {
options.push({
name: this.translate.instant('Quick connect'),
freeInputPattern: this.translate.instant('Connect to "%s"...'),
Expand All @@ -229,7 +229,7 @@ export default class AppModule { // eslint-disable-line @typescript-eslint/no-ex
})
}

await this.selector.show(this.translate.instant('Select profile'), options)
await this.selector.show(this.translate.instant('Select profile'), options).catch(() => {return})
}

static forRoot (): ModuleWithProviders<AppModule> {
Expand Down
4 changes: 2 additions & 2 deletions tabby-core/src/services/commands.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ export class CommandService {
context.tab = tab.getFocusedTab() ?? undefined
}
const commands = await this.getCommands(context)
await this.selector.show(
return this.selector.show(
this.translate.instant('Commands'),
commands.map(c => ({
name: c.label,
callback: c.run,
description: c.sublabel,
icon: c.icon,
})),
)
).then(() => {return})
}
}
40 changes: 40 additions & 0 deletions tabby-core/src/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PlatformService } from '../api/platform'
import { HostAppService } from '../api/hostApp'
import { Vault, VaultService } from './vault.service'
import { serializeFunction } from '../utils'
import { PartialProfileGroup, ProfileGroup } from '../api/profileProvider'
const deepmerge = require('deepmerge')

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
Expand Down Expand Up @@ -364,6 +365,45 @@ export class ConfigService {
}
config.version = 4
}
if (config.version < 5) {
const groups: PartialProfileGroup<ProfileGroup>[] = []
for (const p of config.profiles ?? []) {
if (!(p.group ?? '').trim()) {
continue
}

let group = groups.find(x => x.name === p.group)
if (!group) {
group = {
id: `${uuidv4()}`,
name: `${p.group}`,
}
groups.push(group)
}
p.group = group.id
}

const profileGroupCollapsed = JSON.parse(window.localStorage.profileGroupCollapsed ?? '{}')
for (const g of groups) {
if (profileGroupCollapsed[g.name]) {
const collapsed = profileGroupCollapsed[g.name]
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete profileGroupCollapsed[g.name]
profileGroupCollapsed[g.id] = collapsed
}
}
window.localStorage.profileGroupCollapsed = JSON.stringify(profileGroupCollapsed)

config.groups = groups
config.version = 5
}
if (config.version < 6) {
if (config.ssh.clearServiceMessagesOnConnect === false) {
config.profileDefaults.ssh.clearServiceMessagesOnConnect = false
delete config.ssh?.clearServiceMessagesOnConnect
}
config.version = 6
}
}

private async maybeDecryptConfig (store) {
Expand Down
5 changes: 3 additions & 2 deletions tabby-core/src/services/fileProviders.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export class FileProvidersService {
) { }

async selectAndStoreFile (description: string): Promise<string> {
const p = await this.selectProvider()
return p.selectAndStoreFile(description)
return this.selectProvider().then(p => {
return p.selectAndStoreFile(description)
})
}

async retrieveFile (key: string): Promise<Buffer> {
Expand Down
Loading

0 comments on commit 4684b0d

Please sign in to comment.