show recent profiles in the start page - fixes #4585

上级 397a93bd
......@@ -27,6 +27,10 @@ export interface ToolbarButton {
/** @hidden */
submenuItems?: ToolbarButton[]
showInToolbar?: boolean
showInStartPage?: boolean
}
/**
......
......@@ -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<Profile>) {
await this.profilesService.openNewTabForProfile(profile)
let recentProfiles: PartialProfile<Profile>[] = 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)
},
})),
]
}
}
......@@ -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))
}
......
......@@ -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))
}
......
<svg aria-hidden="true" focusable="false" data-prefix="far" data-icon="history" class="svg-inline--fa fa-history fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="#fff" d="M504 255.532c.252 136.64-111.182 248.372-247.822 248.468-64.014.045-122.373-24.163-166.394-63.942-5.097-4.606-5.3-12.543-.443-17.4l16.96-16.96c4.529-4.529 11.776-4.659 16.555-.395C158.208 436.843 204.848 456 256 456c110.549 0 200-89.468 200-200 0-110.549-89.468-200-200-200-55.52 0-105.708 22.574-141.923 59.043l49.091 48.413c7.641 7.535 2.305 20.544-8.426 20.544H26.412c-6.627 0-12-5.373-12-12V45.443c0-10.651 12.843-16.023 20.426-8.544l45.097 44.474C124.866 36.067 187.15 8 256 8c136.811 0 247.747 110.781 248 247.532zm-167.058 90.173l14.116-19.409c3.898-5.36 2.713-12.865-2.647-16.763L280 259.778V116c0-6.627-5.373-12-12-12h-24c-6.627 0-12 5.373-12 12v168.222l88.179 64.13c5.36 3.897 12.865 2.712 16.763-2.647z"></path></svg>
......@@ -89,11 +89,16 @@ export class ProfilesService {
}
}
getRecentProfiles (): PartialProfile<Profile>[] {
let recentProfiles: PartialProfile<Profile>[] = JSON.parse(window.localStorage['recentProfiles'] ?? '[]')
recentProfiles = recentProfiles.slice(0, this.config.store.terminal.showRecentProfiles)
return recentProfiles
}
showProfileSelector (): Promise<PartialProfile<Profile>|null> {
return new Promise<PartialProfile<Profile>|null>(async (resolve, reject) => {
try {
let recentProfiles: PartialProfile<Profile>[] = JSON.parse(window.localStorage['recentProfiles'] ?? '[]')
recentProfiles = recentProfiles.slice(0, this.config.store.terminal.showRecentProfiles)
const recentProfiles = this.getRecentProfiles()
let options: SelectorOption<void>[] = 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<Profile>): Promise<void> {
await this.openNewTabForProfile(profile)
let recentProfiles: PartialProfile<Profile>[] = 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)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册