new profile system

This commit is contained in:
Eugene Pankov
2021-07-04 12:23:27 +02:00
parent 38b7e44f64
commit 92b34fbc08
104 changed files with 2029 additions and 2205 deletions

View File

@@ -19,7 +19,6 @@
"devDependencies": {
"@types/js-yaml": "^4.0.0",
"bootstrap": "^4.1.3",
"clone-deep": "^4.0.1",
"core-js": "^3.1.2",
"deep-equal": "^2.0.5",
"deepmerge": "^4.1.1",

View File

@@ -2,7 +2,7 @@ export { BaseComponent, SubscriptionContainer } from '../components/base.compone
export { BaseTabComponent, BaseTabProcess } from '../components/baseTab.component'
export { TabHeaderComponent } from '../components/tabHeader.component'
export { SplitTabComponent, SplitContainer } from '../components/splitTab.component'
export { TabRecoveryProvider, RecoveredTab, RecoveryToken } from './tabRecovery'
export { TabRecoveryProvider, RecoveryToken } from './tabRecovery'
export { ToolbarButtonProvider, ToolbarButton } from './toolbarButtonProvider'
export { ConfigProvider } from './configProvider'
export { HotkeyProvider, HotkeyDescription } from './hotkeyProvider'
@@ -16,6 +16,8 @@ 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 { PromptModalComponent } from '../components/promptModal.component'
export { AppService } from '../services/app.service'
export { ConfigService } from '../services/config.service'
@@ -25,8 +27,9 @@ export { HomeBaseService } from '../services/homeBase.service'
export { HotkeysService } from '../services/hotkeys.service'
export { NotificationsService } from '../services/notifications.service'
export { ThemesService } from '../services/themes.service'
export { ProfilesService } from '../services/profiles.service'
export { SelectorService } from '../services/selector.service'
export { TabsService } from '../services/tabs.service'
export { TabsService, NewTabParameters, TabComponentType } from '../services/tabs.service'
export { UpdaterService } from '../services/updater.service'
export { VaultService, Vault, VaultSecret, VAULT_SECRET_TYPE_FILE } from '../services/vault.service'
export { FileProvidersService } from '../services/fileProviders.service'

View File

@@ -0,0 +1,43 @@
/* 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
type: string
name: string
group?: string
options?: Record<string, any>
icon?: string
color?: string
disableDynamicTitle?: boolean
isBuiltin?: boolean
isTemplate?: boolean
}
export interface ProfileSettingsComponent {
profile: Profile
save?: () => void
}
export abstract class ProfileProvider {
id: string
name: string
supportsQuickConnect = false
settingsComponent: new (...args: any[]) => ProfileSettingsComponent
abstract getBuiltinProfiles (): Promise<Profile[]>
abstract getNewTabParameters (profile: Profile): Promise<NewTabParameters<BaseTabComponent>>
abstract getDescription (profile: Profile): string
quickConnect (query: string): Profile|null {
return null
}
deleteProfile (profile: Profile): void { }
}

View File

@@ -1,17 +1,6 @@
import deepClone from 'clone-deep'
import { TabComponentType } from '../services/tabs.service'
export interface RecoveredTab {
/**
* Component type to be instantiated
*/
type: TabComponentType
/**
* Component instance inputs
*/
options?: any
}
import { BaseTabComponent } from '../components/baseTab.component'
import { NewTabParameters } from '../services/tabs.service'
export interface RecoveryToken {
[_: string]: any
@@ -35,19 +24,20 @@ export interface RecoveryToken {
* }
* ```
*/
export abstract class TabRecoveryProvider {
export abstract class TabRecoveryProvider <T extends BaseTabComponent> {
/**
* @param recoveryToken a recovery token found in the saved tabs list
* @returns [[boolean]] whether this [[TabRecoveryProvider]] can recover a tab from this token
*/
abstract applicableTo (recoveryToken: RecoveryToken): Promise<boolean>
/**
* @param recoveryToken a recovery token found in the saved tabs list
* @returns [[RecoveredTab]] descriptor containing tab type and component inputs
* @returns [[NewTabParameters]] descriptor containing tab type and component inputs
* or `null` if this token is from a different tab type or is not supported
*/
abstract recover (recoveryToken: RecoveryToken): Promise<RecoveredTab>
abstract recover (recoveryToken: RecoveryToken): Promise<NewTabParameters<T>>
/**
* @param recoveryToken a recovery token found in the saved tabs list

View File

@@ -0,0 +1,115 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Injectable } from '@angular/core'
import { ToolbarButton, ToolbarButtonProvider } from './api/toolbarButtonProvider'
import { SelectorService } from './services/selector.service'
import { HostAppService, Platform } from './api/hostApp'
import { Profile } from './api/profileProvider'
import { ConfigService } from './services/config.service'
import { SelectorOption } from './api/selector'
import { ProfilesService } from './services/profiles.service'
import { AppService } from './services/app.service'
import { NotificationsService } from './services/notifications.service'
/** @hidden */
@Injectable()
export class ButtonProvider extends ToolbarButtonProvider {
constructor (
private selector: SelectorService,
private app: AppService,
private hostApp: HostAppService,
private profilesServices: ProfilesService,
private config: ConfigService,
private notifications: NotificationsService,
) {
super()
}
async activate () {
const recentProfiles: Profile[] = this.config.store.recentProfiles
const getProfileOptions = (profile): SelectorOption<void> => ({
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),
})
let options = recentProfiles.map(getProfileOptions)
if (recentProfiles.length) {
options.push({
name: 'Clear recent connections',
icon: 'fas fa-eraser',
callback: () => {
this.config.store.recentProfiles = []
this.config.save()
},
})
}
let profiles = await this.profilesServices.getProfiles()
if (!this.config.store.terminal.showBuiltinProfiles) {
profiles = profiles.filter(x => !x.isBuiltin)
}
profiles = profiles.filter(x => !x.isTemplate)
options = [...options, ...profiles.map(getProfileOptions)]
try {
const { SettingsTabComponent } = window['nodeRequire']('tabby-settings')
options.push({
name: 'Manage profiles',
icon: 'fas fa-window-restore',
callback: () => this.app.openNewTabRaw({
type: SettingsTabComponent,
inputs: { activeTab: 'profiles' },
}),
})
} catch { }
if (this.profilesServices.getProviders().some(x => x.supportsQuickConnect)) {
options.push({
name: 'Quick connect',
freeInputPattern: 'Connect to "%s"...',
icon: 'fas fa-arrow-right',
callback: query => this.quickConnect(query),
})
}
await this.selector.show('Select profile', options)
}
quickConnect (query: string) {
for (const provider of this.profilesServices.getProviders()) {
const profile = provider.quickConnect(query)
if (profile) {
this.launchProfile(profile)
return
}
}
this.notifications.error(`Could not parse "${query}"`)
}
async launchProfile (profile: Profile) {
await this.profilesServices.openNewTabForProfile(profile)
const recentProfiles = this.config.store.recentProfiles
recentProfiles.unshift(profile)
if (recentProfiles.length > 5) {
recentProfiles.pop()
}
this.config.store.recentProfiles = recentProfiles
this.config.save()
}
provide (): ToolbarButton[] {
return [{
icon: this.hostApp.platform === Platform.Web
? require('./icons/plus.svg')
: require('./icons/profiles.svg'),
title: 'New tab with profile',
click: () => this.activate(),
}]
}
}

View File

@@ -1,6 +1,41 @@
import { Injectable } from '@angular/core'
import { HostAppService } from './api/hostApp'
import { CLIHandler, CLIEvent } from './api/cli'
import { HostWindowService } from './api/hostWindow'
import { ProfilesService } from './services/profiles.service'
@Injectable()
export class ProfileCLIHandler extends CLIHandler {
firstMatchOnly = true
priority = 0
constructor (
private profiles: ProfilesService,
private hostWindow: HostWindowService,
) {
super()
}
async handle (event: CLIEvent): Promise<boolean> {
const op = event.argv._[0]
if (op === 'profile') {
this.handleOpenProfile(event.argv.profileName)
return true
}
return false
}
private async handleOpenProfile (profileName: string) {
const profile = (await this.profiles.getProfiles()).find(x => x.name === profileName)
if (!profile) {
console.error('Requested profile', profileName, 'not found')
return
}
this.profiles.openNewTabForProfile(profile)
this.hostWindow.bringToFront()
}
}
@Injectable()
export class LastCLIHandler extends CLIHandler {

View File

@@ -0,0 +1,19 @@
.modal-body
input.form-control(
[type]='password ? "password" : "text"',
autofocus,
[(ngModel)]='value',
#input,
[placeholder]='prompt',
(keyup.enter)='ok()',
(keyup.esc)='cancel()',
)
.d-flex.align-items-start.mt-2
checkbox(
*ngIf='showRememberCheckbox',
[(ngModel)]='remember',
text='Remember'
)
button.btn.btn-primary.ml-auto(
(click)='ok()',
) Enter

View File

@@ -0,0 +1,35 @@
import { Component, Input, ViewChild, ElementRef } from '@angular/core'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
/** @hidden */
@Component({
template: require('./promptModal.component.pug'),
})
export class PromptModalComponent {
@Input() value: string
@Input() password: boolean
@Input() remember: boolean
@Input() showRememberCheckbox: boolean
@ViewChild('input') input: ElementRef
constructor (
private modalInstance: NgbActiveModal,
) { }
ngOnInit (): void {
setTimeout(() => {
this.input.nativeElement.focus()
})
}
ok (): void {
this.modalInstance.close({
value: this.value,
remember: this.remember,
})
}
cancel (): void {
this.modalInstance.close(null)
}
}

View File

@@ -15,7 +15,7 @@
*ngFor='let option of filteredOptions; let i = index'
)
i.icon(
class='fa-fw fas fa-{{option.icon}}',
class='fa-fw {{option.icon}}',
*ngIf='!iconIsSVG(option.icon)'
)
.icon(

View File

@@ -1,8 +1,8 @@
import { Observable, Subject } from 'rxjs'
import { Component, Injectable, ViewChild, ViewContainerRef, EmbeddedViewRef, AfterViewInit, OnDestroy } from '@angular/core'
import { BaseTabComponent, BaseTabProcess } from './baseTab.component'
import { TabRecoveryProvider, RecoveredTab, RecoveryToken } from '../api/tabRecovery'
import { TabsService } from '../services/tabs.service'
import { TabRecoveryProvider, RecoveryToken } from '../api/tabRecovery'
import { TabsService, NewTabParameters } from '../services/tabs.service'
import { HotkeysService } from '../services/hotkeys.service'
import { TabRecoveryService } from '../services/tabRecovery.service'
@@ -601,7 +601,7 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
} else {
const recovered = await this.tabRecovery.recoverTab(childState, duplicate)
if (recovered) {
const tab = this.tabsService.create(recovered.type, recovered.options)
const tab = this.tabsService.create(recovered)
children.push(tab)
tab.parent = this
this.attachTabView(tab)
@@ -619,15 +619,15 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
/** @hidden */
@Injectable()
export class SplitTabRecoveryProvider extends TabRecoveryProvider {
export class SplitTabRecoveryProvider extends TabRecoveryProvider<SplitTabComponent> {
async applicableTo (recoveryToken: RecoveryToken): Promise<boolean> {
return recoveryToken.type === 'app:split-tab'
}
async recover (recoveryToken: RecoveryToken): Promise<RecoveredTab> {
async recover (recoveryToken: RecoveryToken): Promise<NewTabParameters<SplitTabComponent>> {
return {
type: SplitTabComponent,
options: { _recoveredState: recoveryToken },
inputs: { _recoveredState: recoveryToken },
}
}

View File

@@ -14,8 +14,9 @@ appearance:
opacity: 1.0
vibrancy: true
vibrancyType: 'blur'
terminal:
recoverTabs: true
profiles: []
recentProfiles: []
recoverTabs: true
enableAnalytics: true
enableWelcomeTab: true
electronFlags:

View File

@@ -0,0 +1,19 @@
import { Directive, ElementRef, AfterViewInit } from '@angular/core'
/** @hidden */
@Directive({
selector: '[alwaysVisibleTypeahead]',
})
export class AlwaysVisibleTypeaheadDirective implements AfterViewInit {
constructor (private el: ElementRef) { }
ngAfterViewInit (): void {
this.el.nativeElement.addEventListener('focus', e => {
e.stopPropagation()
setTimeout(() => {
const inputEvent: Event = new Event('input')
e.target.dispatchEvent(inputEvent)
}, 0)
})
}
}

View File

@@ -1,4 +1,5 @@
import { Injectable } from '@angular/core'
import { ProfilesService } from './services/profiles.service'
import { HotkeyDescription, HotkeyProvider } from './api/hotkeyProvider'
/** @hidden */
@@ -171,7 +172,18 @@ export class AppHotkeyProvider extends HotkeyProvider {
},
]
constructor (
private profilesService: ProfilesService,
) { super() }
async provide (): Promise<HotkeyDescription[]> {
return this.hotkeys
const profiles = await this.profilesService.getProfiles()
return [
...this.hotkeys,
...profiles.map(profile => ({
id: `profile.${profile.id}`,
name: `New tab: ${profile.name}`,
})),
]
}
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" class="svg-inline--fa fa-plus fa-w-12 fa-3x" data-icon="plus" data-prefix="fal" focusable="false" role="img" viewBox="0 0 384 512"><path fill="#fff" stroke="none" stroke-width="1" d="M376 232H216V72c0-4.42-3.58-8-8-8h-32c-4.42 0-8 3.58-8 8v160H8c-4.42 0-8 3.58-8 8v32c0 4.42 3.58 8 8 8h160v160c0 4.42 3.58 8 8 8h32c4.42 0 8-3.58 8-8V280h160c4.42 0 8-3.58 8-8v-32c0-4.42-3.58-8-8-8z"/></svg>

After

Width:  |  Height:  |  Size: 449 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" class="svg-inline--fa fa-window-restore fa-w-16 fa-3x" data-icon="window-restore" data-prefix="fal" focusable="false" role="img" viewBox="0 0 512 512"><path fill="#fff" stroke="none" stroke-width="1" d="M464 0H144c-26.5 0-48 21.5-48 48v48H48c-26.5 0-48 21.5-48 48v320c0 26.5 21.5 48 48 48h320c26.5 0 48-21.5 48-48v-48h48c26.5 0 48-21.5 48-48V48c0-26.5-21.5-48-48-48zM32 144c0-8.8 7.2-16 16-16h320c8.8 0 16 7.2 16 16v80H32v-80zm352 320c0 8.8-7.2 16-16 16H48c-8.8 0-16-7.2-16-16V256h352v208zm96-96c0 8.8-7.2 16-16 16h-48V144c0-26.5-21.5-48-48-48H128V48c0-8.8 7.2-16 16-16h320c8.8 0 16 7.2 16 16v320z"/></svg>

After

Width:  |  Height:  |  Size: 665 B

View File

@@ -10,6 +10,7 @@ import { DndModule } from 'ng2-dnd'
import { AppRootComponent } from './components/appRoot.component'
import { CheckboxComponent } from './components/checkbox.component'
import { TabBodyComponent } from './components/tabBody.component'
import { PromptModalComponent } from './components/promptModal.component'
import { SafeModeModalComponent } from './components/safeModeModal.component'
import { StartPageComponent } from './components/startPage.component'
import { TabHeaderComponent } from './components/tabHeader.component'
@@ -25,20 +26,23 @@ import { WelcomeTabComponent } from './components/welcomeTab.component'
import { TransfersMenuComponent } from './components/transfersMenu.component'
import { AutofocusDirective } from './directives/autofocus.directive'
import { AlwaysVisibleTypeaheadDirective } from './directives/alwaysVisibleTypeahead.directive'
import { FastHtmlBindDirective } from './directives/fastHtmlBind.directive'
import { DropZoneDirective } from './directives/dropZone.directive'
import { Theme, CLIHandler, TabContextMenuItemProvider, TabRecoveryProvider, HotkeyProvider, ConfigProvider, PlatformService, FileProvider } from './api'
import { Theme, CLIHandler, TabContextMenuItemProvider, TabRecoveryProvider, HotkeyProvider, ConfigProvider, PlatformService, FileProvider, ToolbarButtonProvider, ProfilesService } from './api'
import { AppService } from './services/app.service'
import { ConfigService } from './services/config.service'
import { VaultFileProvider } from './services/vault.service'
import { HotkeysService } from './services/hotkeys.service'
import { StandardTheme, StandardCompactTheme, PaperTheme } from './theme'
import { CoreConfigProvider } from './config'
import { AppHotkeyProvider } from './hotkeys'
import { TaskCompletionContextMenu, CommonOptionsContextMenu, TabManagementContextMenu } from './tabContextMenu'
import { LastCLIHandler } from './cli'
import { LastCLIHandler, ProfileCLIHandler } from './cli'
import { ButtonProvider } from './buttonProvider'
import 'perfect-scrollbar/css/perfect-scrollbar.css'
import 'ng2-dnd/bundles/style.css'
@@ -53,9 +57,11 @@ const PROVIDERS = [
{ provide: TabContextMenuItemProvider, useClass: TabManagementContextMenu, multi: true },
{ provide: TabContextMenuItemProvider, useClass: TaskCompletionContextMenu, multi: true },
{ provide: TabRecoveryProvider, useClass: SplitTabRecoveryProvider, multi: true },
{ provide: CLIHandler, useClass: ProfileCLIHandler, multi: true },
{ provide: CLIHandler, useClass: LastCLIHandler, multi: true },
{ provide: PERFECT_SCROLLBAR_CONFIG, useValue: { suppressScrollX: true } },
{ provide: FileProvider, useClass: VaultFileProvider, multi: true },
{ provide: ToolbarButtonProvider, useClass: ButtonProvider, multi: true },
]
/** @hidden */
@@ -72,6 +78,7 @@ const PROVIDERS = [
declarations: [
AppRootComponent as any,
CheckboxComponent,
PromptModalComponent,
StartPageComponent,
TabBodyComponent,
TabHeaderComponent,
@@ -82,6 +89,7 @@ const PROVIDERS = [
SafeModeModalComponent,
AutofocusDirective,
FastHtmlBindDirective,
AlwaysVisibleTypeaheadDirective,
SelectorModalComponent,
SplitTabComponent,
SplitTabSpannerComponent,
@@ -91,6 +99,7 @@ const PROVIDERS = [
DropZoneDirective,
],
entryComponents: [
PromptModalComponent,
RenameTabModalComponent,
SafeModeModalComponent,
SelectorModalComponent,
@@ -101,21 +110,40 @@ const PROVIDERS = [
exports: [
CheckboxComponent,
ToggleComponent,
PromptModalComponent,
AutofocusDirective,
DropZoneDirective,
FastHtmlBindDirective,
AlwaysVisibleTypeaheadDirective,
],
})
export default class AppModule { // eslint-disable-line @typescript-eslint/no-extraneous-class
constructor (app: AppService, config: ConfigService, platform: PlatformService) {
constructor (
app: AppService,
config: ConfigService,
platform: PlatformService,
hotkeys: HotkeysService,
profilesService: ProfilesService,
) {
app.ready$.subscribe(() => {
if (config.store.enableWelcomeTab) {
app.openNewTabRaw(WelcomeTabComponent)
app.openNewTabRaw({ type: WelcomeTabComponent })
}
})
platform.setErrorHandler(err => {
console.error('Unhandled exception:', err)
})
hotkeys.matchedHotkey.subscribe(async (hotkey) => {
if (hotkey.startsWith('profile.')) {
const id = hotkey.split('.')[1]
const profile = (await profilesService.getProfiles()).find(x => x.id === id)
if (profile) {
profilesService.openNewTabForProfile(profile)
}
}
})
}
static forRoot (): ModuleWithProviders<AppModule> {

View File

@@ -1,4 +1,3 @@
import { Observable, Subject, AsyncSubject } from 'rxjs'
import { takeUntil } from 'rxjs/operators'
import { Injectable, Inject } from '@angular/core'
@@ -13,7 +12,7 @@ import { HostAppService } from '../api/hostApp'
import { ConfigService } from './config.service'
import { TabRecoveryService } from './tabRecovery.service'
import { TabsService, TabComponentType } from './tabs.service'
import { TabsService, NewTabParameters } from './tabs.service'
import { SelectorService } from './selector.service'
class CompletionObserver {
@@ -88,10 +87,10 @@ export class AppService {
config.ready$.toPromise().then(async () => {
if (this.bootstrapData.isFirstWindow) {
if (config.store.terminal.recoverTabs) {
if (config.store.recoverTabs) {
const tabs = await this.tabRecovery.recoverTabs()
for (const tab of tabs) {
this.openNewTabRaw(tab.type, tab.options)
this.openNewTabRaw(tab)
}
}
/** Continue to store the tabs even if the setting is currently off */
@@ -152,8 +151,8 @@ export class AppService {
* Adds a new tab **without** wrapping it in a SplitTabComponent
* @param inputs Properties to be assigned on the new tab component instance
*/
openNewTabRaw (type: TabComponentType, inputs?: Record<string, any>): BaseTabComponent {
const tab = this.tabsService.create(type, inputs)
openNewTabRaw <T extends BaseTabComponent> (params: NewTabParameters<T>): T {
const tab = this.tabsService.create(params)
this.addTabRaw(tab)
return tab
}
@@ -162,9 +161,9 @@ export class AppService {
* Adds a new tab while wrapping it in a SplitTabComponent
* @param inputs Properties to be assigned on the new tab component instance
*/
openNewTab (type: TabComponentType, inputs?: Record<string, any>): BaseTabComponent {
const splitTab = this.tabsService.create(SplitTabComponent) as SplitTabComponent
const tab = this.tabsService.create(type, inputs)
openNewTab <T extends BaseTabComponent> (params: NewTabParameters<T>): T {
const splitTab = this.tabsService.create({ type: SplitTabComponent })
const tab = this.tabsService.create(params)
splitTab.addTab(tab, null, 'r')
this.addTabRaw(splitTab)
return tab
@@ -175,7 +174,7 @@ export class AppService {
if (token) {
const recoveredTab = await this.tabRecovery.recoverTab(token)
if (recoveredTab) {
const tab = this.tabsService.create(recoveredTab.type, recoveredTab.options)
const tab = this.tabsService.create(recoveredTab)
if (this.activeTab) {
this.addTabRaw(tab, this.tabs.indexOf(this.activeTab) + 1)
} else {

View File

@@ -1,5 +1,6 @@
import { Observable, Subject, AsyncSubject } from 'rxjs'
import { v4 as uuidv4 } from 'uuid'
import * as yaml from 'js-yaml'
import { Observable, Subject, AsyncSubject } from 'rxjs'
import { Injectable, Inject } from '@angular/core'
import { ConfigProvider } from '../api/configProvider'
import { PlatformService } from '../api/platform'
@@ -58,18 +59,27 @@ export class ConfigProxy {
if (real[key] !== undefined) {
return real[key]
} else {
if (isNonStructuralObjectMember(defaults[key])) {
real[key] = { ...defaults[key] }
delete real[key].__nonStructural
return real[key]
} else {
return defaults[key]
}
return this.getDefault(key)
}
}
this.getDefault = (key: string) => { // eslint-disable-line @typescript-eslint/unbound-method
if (isNonStructuralObjectMember(defaults[key])) {
real[key] = { ...defaults[key] }
delete real[key].__nonStructural
return real[key]
} else {
return defaults[key]
}
}
this.setValue = (key: string, value: any) => { // eslint-disable-line @typescript-eslint/unbound-method
real[key] = value
if (value === this.getDefault(key)) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete real[key]
} else {
real[key] = value
}
}
}
@@ -77,6 +87,8 @@ export class ConfigProxy {
getValue (_key: string): any { }
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-empty-function
setValue (_key: string, _value: any) { }
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-empty-function
getDefault (_key: string) { }
}
@Injectable({ providedIn: 'root' })
@@ -250,6 +262,67 @@ export class ConfigService {
}
config.version = 1
}
if (config.version < 2) {
if (config.terminal?.recoverTabs !== undefined) {
config.recoverTabs = config.terminal.recoverTabs
delete config.terminal.recoverTabs
}
for (const profile of config.terminal?.profiles ?? []) {
if (profile.sessionOptions) {
profile.options = profile.sessionOptions
delete profile.sessionOptions
}
profile.type = 'local'
profile.id = `local:custom:${uuidv4()}`
}
if (config.terminal?.profiles) {
config.profiles = config.terminal.profiles
delete config.terminal.profiles
delete config.terminal.environment
config.terminal.profile = `local:${config.terminal.profile}`
}
config.version = 2
}
if (config.version < 3) {
delete config.ssh.recentConnections
for (const c of config.ssh?.connections ?? []) {
const p = {
id: `ssh:${uuidv4()}`,
type: 'ssh',
icon: 'fas fa-desktop',
name: c.name,
group: c.group ?? undefined,
color: c.color,
disableDynamicTitle: c.disableDynamicTitle,
options: c,
}
config.profiles.push(p)
}
for (const p of config.profiles ?? []) {
if (p.type === 'ssh') {
if (p.options.jumpHost) {
p.options.jumpHost = config.profiles.find(x => x.name === p.options.jumpHost)?.id
}
}
}
for (const c of config.serial?.connections ?? []) {
const p = {
id: `serial:${uuidv4()}`,
type: 'serial',
icon: 'fas fa-microchip',
name: c.name,
group: c.group ?? undefined,
color: c.color,
options: c,
}
config.profiles.push(p)
}
delete config.ssh?.connections
delete config.serial?.connections
delete window.localStorage.lastSerialConnection
// config.version = 3
// migrate jump hosts
}
}
private async maybeDecryptConfig (store) {

View File

@@ -0,0 +1,54 @@
import { Injectable, Inject } from '@angular/core'
import { NewTabParameters } from './tabs.service'
import { BaseTabComponent } from '../components/baseTab.component'
import { Profile, ProfileProvider } from '../api/profileProvider'
import { AppService } from './app.service'
import { ConfigService } from './config.service'
@Injectable({ providedIn: 'root' })
export class ProfilesService {
constructor (
private app: AppService,
private config: ConfigService,
@Inject(ProfileProvider) private profileProviders: ProfileProvider[],
) { }
async openNewTabForProfile (profile: Profile): 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
if (profile.disableDynamicTitle) {
tab['enableDynamicTitle'] = false
tab.setTitle(profile.name)
}
return tab
}
return null
}
async newTabParametersForProfile (profile: Profile): Promise<NewTabParameters<BaseTabComponent>|null> {
return this.providerForProfile(profile)?.getNewTabParameters(profile) ?? null
}
getProviders (): ProfileProvider[] {
return [...this.profileProviders]
}
async getProfiles (): Promise<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 = [
...this.config.store.profiles ?? [],
...list,
]
list.sort((a, b) => a.group?.localeCompare(b.group ?? '') ?? -1)
list.sort((a, b) => a.name.localeCompare(b.name))
list.sort((a, b) => (a.isBuiltin ? 1 : 0) - (b.isBuiltin ? 1 : 0))
return list
}
providerForProfile (profile: Profile): ProfileProvider|null {
return this.profileProviders.find(x => x.id === profile.type) ?? null
}
}

View File

@@ -1,8 +1,9 @@
import { Injectable, Inject } from '@angular/core'
import { TabRecoveryProvider, RecoveredTab, RecoveryToken } from '../api/tabRecovery'
import { TabRecoveryProvider, RecoveryToken } from '../api/tabRecovery'
import { BaseTabComponent } from '../components/baseTab.component'
import { Logger, LogService } from '../services/log.service'
import { ConfigService } from '../services/config.service'
import { Logger, LogService } from './log.service'
import { ConfigService } from './config.service'
import { NewTabParameters } from './tabs.service'
/** @hidden */
@Injectable({ providedIn: 'root' })
@@ -11,7 +12,7 @@ export class TabRecoveryService {
enabled = false
private constructor (
@Inject(TabRecoveryProvider) private tabRecoveryProviders: TabRecoveryProvider[]|null,
@Inject(TabRecoveryProvider) private tabRecoveryProviders: TabRecoveryProvider<BaseTabComponent>[]|null,
private config: ConfigService,
log: LogService
) {
@@ -40,7 +41,7 @@ export class TabRecoveryService {
return token
}
async recoverTab (token: RecoveryToken, duplicate = false): Promise<RecoveredTab|null> {
async recoverTab (token: RecoveryToken, duplicate = false): Promise<NewTabParameters<BaseTabComponent>|null> {
for (const provider of this.config.enabledServices(this.tabRecoveryProviders ?? [])) {
try {
if (!await provider.applicableTo(token)) {
@@ -50,9 +51,9 @@ export class TabRecoveryService {
token = provider.duplicate(token)
}
const tab = await provider.recover(token)
tab.options = tab.options || {}
tab.options.color = token.tabColor ?? null
tab.options.title = token.tabTitle || ''
tab.inputs = tab.inputs ?? {}
tab.inputs.color = token.tabColor ?? null
tab.inputs.title = token.tabTitle || ''
return tab
} catch (error) {
this.logger.warn('Tab recovery crashed:', token, provider, error)
@@ -61,9 +62,9 @@ export class TabRecoveryService {
return null
}
async recoverTabs (): Promise<RecoveredTab[]> {
async recoverTabs (): Promise<NewTabParameters<BaseTabComponent>[]> {
if (window.localStorage.tabsRecovery) {
const tabs: RecoveredTab[] = []
const tabs: NewTabParameters<BaseTabComponent>[] = []
for (const token of JSON.parse(window.localStorage.tabsRecovery)) {
const tab = await this.recoverTab(token)
if (tab) {

View File

@@ -3,7 +3,22 @@ import { BaseTabComponent } from '../components/baseTab.component'
import { TabRecoveryService } from './tabRecovery.service'
// eslint-disable-next-line @typescript-eslint/no-type-alias
export type TabComponentType = new (...args: any[]) => BaseTabComponent
export interface TabComponentType<T extends BaseTabComponent> {
// eslint-disable-next-line @typescript-eslint/prefer-function-type
new (...args: any[]): T
}
export interface NewTabParameters<T extends BaseTabComponent> {
/**
* Component type to be instantiated
*/
type: TabComponentType<T>
/**
* Component instance inputs
*/
inputs?: Record<string, any>
}
@Injectable({ providedIn: 'root' })
export class TabsService {
@@ -17,12 +32,12 @@ export class TabsService {
/**
* Instantiates a tab component and assigns given inputs
*/
create (type: TabComponentType, inputs?: Record<string, any>): BaseTabComponent {
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(type)
create <T extends BaseTabComponent> (params: NewTabParameters<T>): T {
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(params.type)
const componentRef = componentFactory.create(this.injector)
const tab = componentRef.instance
tab.hostView = componentRef.hostView
Object.assign(tab, inputs ?? {})
Object.assign(tab, params.inputs ?? {})
return tab
}
@@ -36,7 +51,7 @@ export class TabsService {
}
const dup = await this.tabRecovery.recoverTab(token, true)
if (dup) {
return this.create(dup.type, dup.options)
return this.create(dup)
}
return null
}

View File

@@ -247,12 +247,12 @@ export class VaultFileProvider extends FileProvider {
const result = await this.selector.show<VaultSecret|null>('Select file', [
{
name: 'Add a new file',
icon: 'plus',
icon: 'fas fa-plus',
result: null,
},
...files.map(f => ({
name: f.key.description,
icon: 'file',
icon: 'fas fa-file',
result: f,
})),
])

View File

@@ -235,12 +235,11 @@ hotkey-input-modal {
}
}
.list-group-light {
.list-group-item {
background: transparent;
border: none;
border-top: 1px solid rgba(255, 255, 255, .1);
border-top: 1px solid rgba(255, 255, 255, .05);
&:first-child {
border-top: none;

View File

@@ -50,15 +50,6 @@ call-bind@^1.0.0, call-bind@^1.0.2:
function-bind "^1.1.1"
get-intrinsic "^1.0.2"
clone-deep@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/clone-deep/-/clone-deep-4.0.1.tgz#c19fd9bdbbf85942b4fd979c84dcf7d5f07c2387"
integrity sha512-neHB9xuzh/wk0dIHweyAXv2aPGZIVk3pLMe+/RNzINf17fe0OG96QroktYAUm7SM1PBnzTabaLboqqxDyMU+SQ==
dependencies:
is-plain-object "^2.0.4"
kind-of "^6.0.2"
shallow-clone "^3.0.0"
core-js@^3.1.2:
version "3.14.0"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.14.0.tgz#62322b98c71cc2018b027971a69419e2425c2a6c"
@@ -282,13 +273,6 @@ is-number-object@^1.0.4:
resolved "https://registry.yarnpkg.com/is-number-object/-/is-number-object-1.0.5.tgz#6edfaeed7950cff19afedce9fbfca9ee6dd289eb"
integrity sha512-RU0lI/n95pMoUKu9v1BZP5MBcZuNSVJkMkAG2dJqC4z2GlkGUNeH68SuHuBKBD/XFe+LHZ+f9BKkLET60Niedw==
is-plain-object@^2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677"
integrity sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==
dependencies:
isobject "^3.0.1"
is-regex@^1.1.1, is-regex@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.3.tgz#d029f9aff6448b93ebbe3f33dac71511fdcbef9f"
@@ -340,11 +324,6 @@ isarray@^2.0.5:
resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.5.tgz#8af1e4c1221244cc62459faf38940d4e644a5723"
integrity sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==
isobject@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=
js-yaml@^4.0.0, js-yaml@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
@@ -361,11 +340,6 @@ jsonfile@^6.0.1:
optionalDependencies:
graceful-fs "^4.1.6"
kind-of@^6.0.2:
version "6.0.3"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==
lazy-val@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/lazy-val/-/lazy-val-1.0.4.tgz#882636a7245c2cfe6e0a4e3ba6c5d68a137e5c65"
@@ -494,13 +468,6 @@ semver@^7.3.5:
dependencies:
lru-cache "^6.0.0"
shallow-clone@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/shallow-clone/-/shallow-clone-3.0.1.tgz#8f2981ad92531f55035b01fb230769a40e02efa3"
integrity sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==
dependencies:
kind-of "^6.0.2"
side-channel@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf"