diff --git a/tabby-core/src/api/toolbarButtonProvider.ts b/tabby-core/src/api/toolbarButtonProvider.ts index a30b9987..a3e2402a 100644 --- a/tabby-core/src/api/toolbarButtonProvider.ts +++ b/tabby-core/src/api/toolbarButtonProvider.ts @@ -27,6 +27,10 @@ export interface ToolbarButton { /** @hidden */ submenuItems?: ToolbarButton[] + + showInToolbar?: boolean + + showInStartPage?: boolean } /** diff --git a/tabby-core/src/buttonProvider.ts b/tabby-core/src/buttonProvider.ts index 5cccc328..8aa45165 100644 --- a/tabby-core/src/buttonProvider.ts +++ b/tabby-core/src/buttonProvider.ts @@ -3,8 +3,6 @@ import { Injectable } from '@angular/core' import { ToolbarButton, ToolbarButtonProvider } from './api/toolbarButtonProvider' import { HostAppService, Platform } from './api/hostApp' -import { PartialProfile, Profile } from './api/profileProvider' -import { ConfigService } from './services/config.service' import { HotkeysService } from './services/hotkeys.service' import { ProfilesService } from './services/profiles.service' @@ -14,7 +12,6 @@ export class ButtonProvider extends ToolbarButtonProvider { constructor ( private hostApp: HostAppService, private profilesService: ProfilesService, - private config: ConfigService, hotkeys: HotkeysService, ) { super() @@ -28,31 +25,29 @@ export class ButtonProvider extends ToolbarButtonProvider { async activate () { const profile = await this.profilesService.showProfileSelector() if (profile) { - this.launchProfile(profile) + this.profilesService.launchProfile(profile) } } - async launchProfile (profile: PartialProfile) { - await this.profilesService.openNewTabForProfile(profile) - - let recentProfiles: PartialProfile[] = JSON.parse(window.localStorage['recentProfiles'] ?? '[]') - if (this.config.store.terminal.showRecentProfiles > 0) { - recentProfiles = recentProfiles.filter(x => x.group !== profile.group || x.name !== profile.name) - recentProfiles.unshift(profile) - recentProfiles = recentProfiles.slice(0, this.config.store.terminal.showRecentProfiles) - } else { - recentProfiles = [] - } - window.localStorage['recentProfiles'] = JSON.stringify(recentProfiles) - } - 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(), - }] + return [ + { + icon: this.hostApp.platform === Platform.Web + ? require('./icons/plus.svg') + : require('./icons/profiles.svg'), + title: 'New tab with profile', + click: () => this.activate(), + }, + ...this.profilesService.getRecentProfiles().map(profile => ({ + icon: require('./icons/history.svg'), + title: profile.name, + showInToolbar: false, + showinStartPage: true, + click: async () => { + const p = (await this.profilesService.getProfiles()).find(x => x.id === profile.id) ?? profile + this.profilesService.launchProfile(p) + }, + })), + ] } } diff --git a/tabby-core/src/components/appRoot.component.ts b/tabby-core/src/components/appRoot.component.ts index c30da5e8..9c62c528 100644 --- a/tabby-core/src/components/appRoot.component.ts +++ b/tabby-core/src/components/appRoot.component.ts @@ -203,6 +203,7 @@ export class AppRootComponent { buttons = buttons.concat(provider.provide()) }) return buttons + .filter(x => x.showInToolbar ?? true) .filter(button => (button.weight ?? 0) > 0 === aboveZero) .sort((a: ToolbarButton, b: ToolbarButton) => (a.weight ?? 0) - (b.weight ?? 0)) } diff --git a/tabby-core/src/components/startPage.component.ts b/tabby-core/src/components/startPage.component.ts index 9f7bc84f..60fc7ca1 100644 --- a/tabby-core/src/components/startPage.component.ts +++ b/tabby-core/src/components/startPage.component.ts @@ -25,6 +25,7 @@ export class StartPageComponent { return this.config.enabledServices(this.toolbarButtonProviders) .map(provider => provider.provide()) .reduce((a, b) => a.concat(b)) + .filter(x => x.showInStartPage ?? true) .filter(x => !!x.click) .sort((a: ToolbarButton, b: ToolbarButton) => (a.weight ?? 0) - (b.weight ?? 0)) } diff --git a/tabby-core/src/icons/history.svg b/tabby-core/src/icons/history.svg new file mode 100644 index 00000000..d7c238ec --- /dev/null +++ b/tabby-core/src/icons/history.svg @@ -0,0 +1 @@ + diff --git a/tabby-core/src/services/profiles.service.ts b/tabby-core/src/services/profiles.service.ts index c466165a..55f48330 100644 --- a/tabby-core/src/services/profiles.service.ts +++ b/tabby-core/src/services/profiles.service.ts @@ -89,11 +89,16 @@ export class ProfilesService { } } + getRecentProfiles (): PartialProfile[] { + let recentProfiles: PartialProfile[] = JSON.parse(window.localStorage['recentProfiles'] ?? '[]') + recentProfiles = recentProfiles.slice(0, this.config.store.terminal.showRecentProfiles) + return recentProfiles + } + showProfileSelector (): Promise|null> { return new Promise|null>(async (resolve, reject) => { try { - let recentProfiles: PartialProfile[] = JSON.parse(window.localStorage['recentProfiles'] ?? '[]') - recentProfiles = recentProfiles.slice(0, this.config.store.terminal.showRecentProfiles) + const recentProfiles = this.getRecentProfiles() let options: SelectorOption[] = recentProfiles.map(p => ({ ...this.selectorOptionForProfile(p), @@ -188,4 +193,18 @@ export class ProfilesService { ].reduce(configMerge, {}) return new ConfigProxy(profile, defaults) as unknown as T } + + async launchProfile (profile: PartialProfile): Promise { + await this.openNewTabForProfile(profile) + + let recentProfiles: PartialProfile[] = JSON.parse(window.localStorage['recentProfiles'] ?? '[]') + if (this.config.store.terminal.showRecentProfiles > 0) { + recentProfiles = recentProfiles.filter(x => x.group !== profile.group || x.name !== profile.name) + recentProfiles.unshift(profile) + recentProfiles = recentProfiles.slice(0, this.config.store.terminal.showRecentProfiles) + } else { + recentProfiles = [] + } + window.localStorage['recentProfiles'] = JSON.stringify(recentProfiles) + } }