From 3d9b15a82d5b9401e14e2afb7eba7fc068dbfc3c Mon Sep 17 00:00:00 2001 From: Clem Date: Fri, 7 Jul 2023 10:35:03 +0200 Subject: [PATCH 1/9] ref(tabby-local): remove SaveAsProfile context menu --- tabby-local/src/index.ts | 3 +- tabby-local/src/tabContextMenu.ts | 52 +------------------------------ 2 files changed, 2 insertions(+), 53 deletions(-) diff --git a/tabby-local/src/index.ts b/tabby-local/src/index.ts index d7633930..3730c93d 100644 --- a/tabby-local/src/index.ts +++ b/tabby-local/src/index.ts @@ -21,7 +21,7 @@ import { RecoveryProvider } from './recoveryProvider' import { ShellSettingsTabProvider } from './settings' import { TerminalConfigProvider } from './config' import { LocalTerminalHotkeyProvider } from './hotkeys' -import { NewTabContextMenu, SaveAsProfileContextMenu } from './tabContextMenu' +import { NewTabContextMenu } from './tabContextMenu' import { AutoOpenTabCLIHandler, OpenPathCLIHandler, TerminalCLIHandler } from './cli' import { LocalProfilesService } from './profiles' @@ -47,7 +47,6 @@ import { LocalProfilesService } from './profiles' { provide: ProfileProvider, useClass: LocalProfilesService, multi: true }, { provide: TabContextMenuItemProvider, useClass: NewTabContextMenu, multi: true }, - { provide: TabContextMenuItemProvider, useClass: SaveAsProfileContextMenu, multi: true }, { provide: CLIHandler, useClass: TerminalCLIHandler, multi: true }, { provide: CLIHandler, useClass: OpenPathCLIHandler, multi: true }, diff --git a/tabby-local/src/tabContextMenu.ts b/tabby-local/src/tabContextMenu.ts index 1671e652..108ad7e5 100644 --- a/tabby-local/src/tabContextMenu.ts +++ b/tabby-local/src/tabContextMenu.ts @@ -1,59 +1,9 @@ import { Inject, Injectable, Optional } from '@angular/core' -import { NgbModal } from '@ng-bootstrap/ng-bootstrap' -import { ConfigService, BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, ProfilesService, PromptModalComponent, TranslateService } from 'tabby-core' +import { ConfigService, BaseTabComponent, TabContextMenuItemProvider, MenuItemOptions, ProfilesService, TranslateService } from 'tabby-core' import { TerminalTabComponent } from './components/terminalTab.component' import { TerminalService } from './services/terminal.service' import { LocalProfile, UACService } from './api' -/** @hidden */ -@Injectable() -export class SaveAsProfileContextMenu extends TabContextMenuItemProvider { - constructor ( - private config: ConfigService, - private ngbModal: NgbModal, - private notifications: NotificationsService, - private translate: TranslateService, - ) { - super() - } - - async getItems (tab: BaseTabComponent): Promise { - if (!(tab instanceof TerminalTabComponent)) { - return [] - } - const terminalTab = tab - const items: MenuItemOptions[] = [ - { - label: this.translate.instant('Save as profile'), - click: async () => { - const modal = this.ngbModal.open(PromptModalComponent) - modal.componentInstance.prompt = this.translate.instant('New profile name') - const name = (await modal.result)?.value - if (!name) { - return - } - const profile = { - options: { - ...terminalTab.profile.options, - cwd: await terminalTab.session?.getWorkingDirectory() ?? terminalTab.profile.options.cwd, - }, - name, - type: 'local', - } - this.config.store.profiles = [ - ...this.config.store.profiles, - profile, - ] - this.config.save() - this.notifications.info(this.translate.instant('Saved')) - }, - }, - ] - - return items - } -} - /** @hidden */ @Injectable() export class NewTabContextMenu extends TabContextMenuItemProvider { From d98fbe8b44ec063237632658fc071d1ea584b003 Mon Sep 17 00:00:00 2001 From: Clem Date: Fri, 7 Jul 2023 10:37:28 +0200 Subject: [PATCH 2/9] feat(tabby-terminal): Eugeny/tabby#5688 add global Save As Profile context menu --- tabby-terminal/src/index.ts | 3 +- tabby-terminal/src/tabContextMenu.ts | 60 +++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/tabby-terminal/src/index.ts b/tabby-terminal/src/index.ts index 35b0ac70..77cd82ed 100644 --- a/tabby-terminal/src/index.ts +++ b/tabby-terminal/src/index.ts @@ -28,7 +28,7 @@ import { PathDropDecorator } from './features/pathDrop' import { ZModemDecorator } from './features/zmodem' import { TerminalConfigProvider } from './config' import { TerminalHotkeyProvider } from './hotkeys' -import { CopyPasteContextMenu, MiscContextMenu, LegacyContextMenu, ReconnectContextMenu } from './tabContextMenu' +import { CopyPasteContextMenu, MiscContextMenu, LegacyContextMenu, ReconnectContextMenu, SaveAsProfileContextMenu } from './tabContextMenu' import { Frontend } from './frontends/frontend' import { XTermFrontend, XTermWebGLFrontend } from './frontends/xtermFrontend' @@ -60,6 +60,7 @@ import { DefaultColorSchemes } from './colorSchemes' { provide: TabContextMenuItemProvider, useClass: MiscContextMenu, multi: true }, { provide: TabContextMenuItemProvider, useClass: LegacyContextMenu, multi: true }, { provide: TabContextMenuItemProvider, useClass: ReconnectContextMenu, multi: true }, + { provide: TabContextMenuItemProvider, useClass: SaveAsProfileContextMenu, multi: true }, { provide: CLIHandler, useClass: TerminalCLIHandler, multi: true }, { provide: TerminalColorSchemeProvider, useClass: DefaultColorSchemes, multi: true }, diff --git a/tabby-terminal/src/tabContextMenu.ts b/tabby-terminal/src/tabContextMenu.ts index 9be79476..e566d135 100644 --- a/tabby-terminal/src/tabContextMenu.ts +++ b/tabby-terminal/src/tabContextMenu.ts @@ -1,5 +1,6 @@ import { Injectable, Optional, Inject } from '@angular/core' -import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent } from 'tabby-core' +import { NgbModal } from '@ng-bootstrap/ng-bootstrap' +import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent, PromptModalComponent, ConfigService } from 'tabby-core' import { BaseTerminalTabComponent } from './api/baseTerminalTab.component' import { TerminalContextMenuItemProvider } from './api/contextMenuProvider' import { MultifocusService } from './services/multifocus.service' @@ -150,3 +151,60 @@ export class LegacyContextMenu extends TabContextMenuItemProvider { } } + +/** @hidden */ +@Injectable() +export class SaveAsProfileContextMenu extends TabContextMenuItemProvider { + constructor ( + private config: ConfigService, + private ngbModal: NgbModal, + private notifications: NotificationsService, + private translate: TranslateService, + ) { + super() + } + + async getItems (tab: BaseTabComponent): Promise { + if (tab instanceof BaseTerminalTabComponent) { + return [ + { + label: this.translate.instant('Save as profile'), + click: async () => { + const modal = this.ngbModal.open(PromptModalComponent) + modal.componentInstance.prompt = this.translate.instant('New profile name') + const name = (await modal.result)?.value + if (!name) { + return + } + + let options = {...tab.profile.options} + const cwd = await tab.session?.getWorkingDirectory() ?? tab.profile.options.cwd + if (cwd) { + options = { + ...options, + cwd + } + } + + const profile = { + options, + name, + type: tab.profile.type, + } + + console.log(profile) + + this.config.store.profiles = [ + ...this.config.store.profiles, + profile, + ] + this.config.save() + this.notifications.info(this.translate.instant('Saved')) + }, + }, + ] + } + + return [] + } +} \ No newline at end of file From 4bbf86a7a7cedb5cc765cd4fe4568ed880164028 Mon Sep 17 00:00:00 2001 From: Clem Date: Fri, 7 Jul 2023 11:23:19 +0200 Subject: [PATCH 3/9] fix(tabby-terminal): create an ID for 'Save As' Profile --- tabby-terminal/src/tabContextMenu.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tabby-terminal/src/tabContextMenu.ts b/tabby-terminal/src/tabContextMenu.ts index e566d135..349ea91a 100644 --- a/tabby-terminal/src/tabContextMenu.ts +++ b/tabby-terminal/src/tabContextMenu.ts @@ -1,10 +1,12 @@ import { Injectable, Optional, Inject } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' -import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent, PromptModalComponent, ConfigService } from 'tabby-core' +import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent, PromptModalComponent, ConfigService, PartialProfile, Profile } from 'tabby-core' import { BaseTerminalTabComponent } from './api/baseTerminalTab.component' import { TerminalContextMenuItemProvider } from './api/contextMenuProvider' import { MultifocusService } from './services/multifocus.service' import { ConnectableTerminalTabComponent } from './api/connectableTerminalTab.component' +import { v4 as uuidv4 } from 'uuid' +import slugify from 'slugify' /** @hidden */ @Injectable() @@ -186,13 +188,13 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider { } } - const profile = { + const profile: PartialProfile = { options, name, type: tab.profile.type, } - console.log(profile) + profile.id = `${profile.type}:custom:${slugify(profile.name)}:${uuidv4()}` this.config.store.profiles = [ ...this.config.store.profiles, From 6709217a8636573eb84d323eadec16ddfaa6ea51 Mon Sep 17 00:00:00 2001 From: Clem Date: Fri, 7 Jul 2023 15:03:57 +0200 Subject: [PATCH 4/9] fix(tabby-terminal): save icon/color/group/dynamic title/behavior on session end with 'Save As' Profile --- tabby-terminal/src/tabContextMenu.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tabby-terminal/src/tabContextMenu.ts b/tabby-terminal/src/tabContextMenu.ts index 349ea91a..2d96bdf5 100644 --- a/tabby-terminal/src/tabContextMenu.ts +++ b/tabby-terminal/src/tabContextMenu.ts @@ -1,6 +1,6 @@ import { Injectable, Optional, Inject } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' -import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent, PromptModalComponent, ConfigService, PartialProfile, Profile } from 'tabby-core' +import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent, PromptModalComponent, ConfigService, PartialProfile, Profile} from 'tabby-core' import { BaseTerminalTabComponent } from './api/baseTerminalTab.component' import { TerminalContextMenuItemProvider } from './api/contextMenuProvider' import { MultifocusService } from './services/multifocus.service' @@ -174,27 +174,33 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider { click: async () => { const modal = this.ngbModal.open(PromptModalComponent) modal.componentInstance.prompt = this.translate.instant('New profile name') + modal.componentInstance.value = tab.profile.name const name = (await modal.result)?.value if (!name) { return } - let options = {...tab.profile.options} + let options = { + ...tab.profile.options + } + const cwd = await tab.session?.getWorkingDirectory() ?? tab.profile.options.cwd if (cwd) { - options = { - ...options, - cwd - } + options.cwd = cwd } const profile: PartialProfile = { - options, - name, type: tab.profile.type, + name, + options } - profile.id = `${profile.type}:custom:${slugify(profile.name)}:${uuidv4()}` + profile.id = `${profile.type}:custom:${slugify(name)}:${uuidv4()}` + profile.group = tab.profile.group + profile.icon = tab.profile.icon + profile.color = tab.profile.color + profile.disableDynamicTitle = tab.profile.disableDynamicTitle + profile.behaviorOnSessionEnd = tab.profile.behaviorOnSessionEnd this.config.store.profiles = [ ...this.config.store.profiles, From 82a262026f71ec7ec187cba460f9037c7fb0f286 Mon Sep 17 00:00:00 2001 From: Clem Date: Fri, 7 Jul 2023 15:06:47 +0200 Subject: [PATCH 5/9] fix Eugeny/tabby#8534 : skip yaml unacceptable kind of object to dump --- tabby-core/src/services/config.service.ts | 4 ++-- tabby-settings/src/services/configSync.service.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tabby-core/src/services/config.service.ts b/tabby-core/src/services/config.service.ts index 8b5f7629..cee3fb9e 100644 --- a/tabby-core/src/services/config.service.ts +++ b/tabby-core/src/services/config.service.ts @@ -205,7 +205,7 @@ export class ConfigService { // Scrub undefined values let cleanStore = JSON.parse(JSON.stringify(this._store)) cleanStore = await this.maybeEncryptConfig(cleanStore) - await this.platform.saveConfig(yaml.dump(cleanStore)) + await this.platform.saveConfig(yaml.dump(cleanStore, {skipInvalid: true})) this.emitChange() } @@ -213,7 +213,7 @@ export class ConfigService { * Reads config YAML as string */ readRaw (): string { - return yaml.dump(this._store) + return yaml.dump(this._store, {skipInvalid: true}) } /** diff --git a/tabby-settings/src/services/configSync.service.ts b/tabby-settings/src/services/configSync.service.ts index fdd5efec..e1717925 100644 --- a/tabby-settings/src/services/configSync.service.ts +++ b/tabby-settings/src/services/configSync.service.ts @@ -97,7 +97,7 @@ export class ConfigSyncService { data[part] = remoteData[part] } } - const content = yaml.dump(data) + const content = yaml.dump(data, {skipInvalid: true}) const result = await this.updateConfig(this.config.store.configSync.configID, { content, last_used_with_version: this.platform.getAppVersion(), @@ -154,7 +154,7 @@ export class ConfigSyncService { } private async writeConfigDataFromSync (data: any) { - await this.platform.saveConfig(yaml.dump(data)) + await this.platform.saveConfig(yaml.dump(data, {skipInvalid: true})) await this.config.load() await this.config.save() } From a4136bec6efdcab26ecc00c3a4f4bdc89ebe8786 Mon Sep 17 00:00:00 2001 From: Clem Date: Fri, 7 Jul 2023 15:15:13 +0200 Subject: [PATCH 6/9] lint --- tabby-core/src/services/config.service.ts | 4 ++-- tabby-settings/src/services/configSync.service.ts | 4 ++-- tabby-terminal/src/tabContextMenu.ts | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tabby-core/src/services/config.service.ts b/tabby-core/src/services/config.service.ts index cee3fb9e..331fcdff 100644 --- a/tabby-core/src/services/config.service.ts +++ b/tabby-core/src/services/config.service.ts @@ -205,7 +205,7 @@ export class ConfigService { // Scrub undefined values let cleanStore = JSON.parse(JSON.stringify(this._store)) cleanStore = await this.maybeEncryptConfig(cleanStore) - await this.platform.saveConfig(yaml.dump(cleanStore, {skipInvalid: true})) + await this.platform.saveConfig(yaml.dump(cleanStore, { skipInvalid: true })) this.emitChange() } @@ -213,7 +213,7 @@ export class ConfigService { * Reads config YAML as string */ readRaw (): string { - return yaml.dump(this._store, {skipInvalid: true}) + return yaml.dump(this._store, { skipInvalid: true }) } /** diff --git a/tabby-settings/src/services/configSync.service.ts b/tabby-settings/src/services/configSync.service.ts index e1717925..5a976907 100644 --- a/tabby-settings/src/services/configSync.service.ts +++ b/tabby-settings/src/services/configSync.service.ts @@ -97,7 +97,7 @@ export class ConfigSyncService { data[part] = remoteData[part] } } - const content = yaml.dump(data, {skipInvalid: true}) + const content = yaml.dump(data, { skipInvalid: true }) const result = await this.updateConfig(this.config.store.configSync.configID, { content, last_used_with_version: this.platform.getAppVersion(), @@ -154,7 +154,7 @@ export class ConfigSyncService { } private async writeConfigDataFromSync (data: any) { - await this.platform.saveConfig(yaml.dump(data, {skipInvalid: true})) + await this.platform.saveConfig(yaml.dump(data, { skipInvalid: true })) await this.config.load() await this.config.save() } diff --git a/tabby-terminal/src/tabContextMenu.ts b/tabby-terminal/src/tabContextMenu.ts index 2d96bdf5..bef7cbba 100644 --- a/tabby-terminal/src/tabContextMenu.ts +++ b/tabby-terminal/src/tabContextMenu.ts @@ -1,6 +1,6 @@ import { Injectable, Optional, Inject } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' -import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent, PromptModalComponent, ConfigService, PartialProfile, Profile} from 'tabby-core' +import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent, PromptModalComponent, ConfigService, PartialProfile, Profile } from 'tabby-core' import { BaseTerminalTabComponent } from './api/baseTerminalTab.component' import { TerminalContextMenuItemProvider } from './api/contextMenuProvider' import { MultifocusService } from './services/multifocus.service' @@ -180,8 +180,8 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider { return } - let options = { - ...tab.profile.options + const options = { + ...tab.profile.options, } const cwd = await tab.session?.getWorkingDirectory() ?? tab.profile.options.cwd @@ -192,7 +192,7 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider { const profile: PartialProfile = { type: tab.profile.type, name, - options + options, } profile.id = `${profile.type}:custom:${slugify(name)}:${uuidv4()}` @@ -215,4 +215,4 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider { return [] } -} \ No newline at end of file +} From 0313e872fd10c78003a94d07ca1d1544e9b11d74 Mon Sep 17 00:00:00 2001 From: Clem Date: Mon, 10 Jul 2023 18:03:14 +0200 Subject: [PATCH 7/9] fix(core): new config migration to recover profile without ID --- tabby-core/src/services/config.service.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tabby-core/src/services/config.service.ts b/tabby-core/src/services/config.service.ts index 331fcdff..6235af10 100644 --- a/tabby-core/src/services/config.service.ts +++ b/tabby-core/src/services/config.service.ts @@ -351,6 +351,14 @@ export class ConfigService { delete window.localStorage.lastSerialConnection config.version = 3 } + if (config.version < 4) { + for (const p of config.profiles ?? []) { + if (!p.id) { + p.id = `${p.type}:custom:${uuidv4()}` + } + } + config.version = 4 + } } private async maybeDecryptConfig (store) { From eea3ab9c74a8b91b4dd0dbb5f09a6bc786c25800 Mon Sep 17 00:00:00 2001 From: Clem Date: Tue, 11 Jul 2023 18:49:53 +0200 Subject: [PATCH 8/9] Revert "fix Eugeny/tabby#8534 : skip yaml unacceptable kind of object to dump" This reverts commit 82a262026f71ec7ec187cba460f9037c7fb0f286. --- tabby-core/src/services/config.service.ts | 4 ++-- tabby-settings/src/services/configSync.service.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tabby-core/src/services/config.service.ts b/tabby-core/src/services/config.service.ts index 6235af10..1051e7b7 100644 --- a/tabby-core/src/services/config.service.ts +++ b/tabby-core/src/services/config.service.ts @@ -205,7 +205,7 @@ export class ConfigService { // Scrub undefined values let cleanStore = JSON.parse(JSON.stringify(this._store)) cleanStore = await this.maybeEncryptConfig(cleanStore) - await this.platform.saveConfig(yaml.dump(cleanStore, { skipInvalid: true })) + await this.platform.saveConfig(yaml.dump(cleanStore)) this.emitChange() } @@ -213,7 +213,7 @@ export class ConfigService { * Reads config YAML as string */ readRaw (): string { - return yaml.dump(this._store, { skipInvalid: true }) + return yaml.dump(this._store) } /** diff --git a/tabby-settings/src/services/configSync.service.ts b/tabby-settings/src/services/configSync.service.ts index 5a976907..fdd5efec 100644 --- a/tabby-settings/src/services/configSync.service.ts +++ b/tabby-settings/src/services/configSync.service.ts @@ -97,7 +97,7 @@ export class ConfigSyncService { data[part] = remoteData[part] } } - const content = yaml.dump(data, { skipInvalid: true }) + const content = yaml.dump(data) const result = await this.updateConfig(this.config.store.configSync.configID, { content, last_used_with_version: this.platform.getAppVersion(), @@ -154,7 +154,7 @@ export class ConfigSyncService { } private async writeConfigDataFromSync (data: any) { - await this.platform.saveConfig(yaml.dump(data, { skipInvalid: true })) + await this.platform.saveConfig(yaml.dump(data)) await this.config.load() await this.config.save() } From 47a6e8199802849f6df3b6c49c2ff98d68b84d41 Mon Sep 17 00:00:00 2001 From: Clem Date: Tue, 11 Jul 2023 19:00:27 +0200 Subject: [PATCH 9/9] fix Eugeny/tabby#8534 by @Eugeny --- tabby-core/src/services/config.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tabby-core/src/services/config.service.ts b/tabby-core/src/services/config.service.ts index 1051e7b7..5d199f90 100644 --- a/tabby-core/src/services/config.service.ts +++ b/tabby-core/src/services/config.service.ts @@ -213,7 +213,9 @@ export class ConfigService { * Reads config YAML as string */ readRaw (): string { - return yaml.dump(this._store) + // Scrub undefined values + const cleanStore = JSON.parse(JSON.stringify(this._store)) + return yaml.dump(cleanStore) } /**