mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-08 13:30:02 +00:00
wip ref(core/profiles.service): move out group managment from settings
This commit is contained in:
parent
8a85fcac21
commit
c1e03ed532
@ -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, Profile, PartialProfile, ProfileSettingsComponent, ProfileGroup, PartialProfileGroup} from './profileProvider'
|
||||
export { PromptModalComponent } from '../components/promptModal.component'
|
||||
export * from './commands'
|
||||
|
||||
|
@ -31,6 +31,22 @@ export type PartialProfile<T extends Profile> = Omit<Omit<Omit<{
|
||||
}
|
||||
}
|
||||
|
||||
export interface ProfileGroup {
|
||||
id: string
|
||||
name: string
|
||||
profiles: PartialProfile<Profile>[]
|
||||
defaults: any
|
||||
editable: boolean
|
||||
collapsed: 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
|
||||
|
@ -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
|
||||
@ -364,6 +365,37 @@ 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]
|
||||
delete profileGroupCollapsed[g.name]
|
||||
profileGroupCollapsed[g.id] = collapsed
|
||||
}
|
||||
}
|
||||
window.localStorage.profileGroupCollapsed = JSON.stringify(profileGroupCollapsed)
|
||||
|
||||
config.groups = groups
|
||||
config.version = 5
|
||||
}
|
||||
}
|
||||
|
||||
private async maybeDecryptConfig (store) {
|
||||
|
@ -2,7 +2,7 @@ import { Injectable, Inject } from '@angular/core'
|
||||
import { TranslateService } from '@ngx-translate/core'
|
||||
import { NewTabParameters } from './tabs.service'
|
||||
import { BaseTabComponent } from '../components/baseTab.component'
|
||||
import { PartialProfile, Profile, ProfileProvider } from '../api/profileProvider'
|
||||
import { PartialProfile, PartialProfileGroup, Profile, ProfileGroup, ProfileProvider } from '../api/profileProvider'
|
||||
import { SelectorOption } from '../api/selector'
|
||||
import { AppService } from './app.service'
|
||||
import { configMerge, ConfigProxy, ConfigService } from './config.service'
|
||||
@ -80,6 +80,8 @@ export class ProfilesService {
|
||||
return list
|
||||
}
|
||||
|
||||
|
||||
|
||||
providerForProfile <T extends Profile> (profile: PartialProfile<T>): ProfileProvider<T>|null {
|
||||
const provider = this.profileProviders.find(x => x.id === profile.type) ?? null
|
||||
return provider as unknown as ProfileProvider<T>|null
|
||||
@ -263,4 +265,62 @@ export class ProfilesService {
|
||||
]
|
||||
}
|
||||
|
||||
/*
|
||||
* Methods used to interract with ProfileGroup
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return an Array of the existing ProfileGroups
|
||||
* arg: includeProfiles (default: false) -> if false, does not fill up the profiles field of ProfileGroup
|
||||
* arg: includeNonUserGroup (default: false) -> if false, does not add built-in and ungrouped groups
|
||||
*/
|
||||
async getProfileGroups (includeProfiles = false, includeNonUserGroup = false): Promise<PartialProfileGroup<ProfileGroup>[]> {
|
||||
let profiles: PartialProfile<Profile>[] = []
|
||||
if (includeProfiles) {
|
||||
profiles = await this.getProfiles()
|
||||
}
|
||||
|
||||
const profileGroupCollapsed = JSON.parse(window.localStorage.profileGroupCollapsed ?? '{}')
|
||||
let groups: PartialProfileGroup<ProfileGroup>[] = this.config.store.groups ?? []
|
||||
groups = groups.map(x => {
|
||||
x.editable = true
|
||||
x.collapsed = profileGroupCollapsed[x.id ?? ''] ?? false
|
||||
|
||||
if (includeProfiles) {
|
||||
x.profiles = profiles.filter(p => p.group === x.id)
|
||||
profiles = profiles.filter(p => p.group !== x.id)
|
||||
}
|
||||
|
||||
return x
|
||||
})
|
||||
|
||||
if (includeNonUserGroup) {
|
||||
const builtIn: PartialProfileGroup<ProfileGroup> = {
|
||||
id: 'built-in',
|
||||
name: this.translate.instant('Built-in'),
|
||||
editable: false,
|
||||
}
|
||||
builtIn.collapsed = profileGroupCollapsed[builtIn.id] ?? false
|
||||
|
||||
const ungrouped: PartialProfileGroup<ProfileGroup> = {
|
||||
id: 'ungrouped',
|
||||
name: this.translate.instant('Ungrouped'),
|
||||
editable: false,
|
||||
}
|
||||
ungrouped.collapsed = profileGroupCollapsed[ungrouped.id] ?? false
|
||||
|
||||
if (includeProfiles) {
|
||||
builtIn.profiles = profiles.filter(p => p.group === builtIn.id)
|
||||
profiles = profiles.filter(p => p.group !== builtIn.id)
|
||||
|
||||
ungrouped.profiles = profiles
|
||||
}
|
||||
|
||||
groups.push(builtIn)
|
||||
groups.push(ungrouped)
|
||||
}
|
||||
|
||||
return groups
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user