From 8a85fcac21f5ea3dc2bd4b1ae04f88865f61ca31 Mon Sep 17 00:00:00 2001 From: Clem Fern Date: Sat, 22 Jul 2023 20:16:27 +0200 Subject: [PATCH] wip ref(core/profiles.service): add methods to interract with Provider defaults --- tabby-core/src/services/profiles.service.ts | 41 ++++++++++++++++--- .../profilesSettingsTab.component.ts | 4 +- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/tabby-core/src/services/profiles.service.ts b/tabby-core/src/services/profiles.service.ts index cc0fc1f9..c4bafb2e 100644 --- a/tabby-core/src/services/profiles.service.ts +++ b/tabby-core/src/services/profiles.service.ts @@ -212,12 +212,7 @@ export class ProfilesService { } getConfigProxyForProfile (profile: PartialProfile, skipUserDefaults = false): T { - const provider = this.providerForProfile(profile) - const defaults = [ - this.profileDefaults, - provider?.configDefaults ?? {}, - !provider || skipUserDefaults ? {} : this.config.store.profileDefaults[provider.id] ?? {}, - ].reduce(configMerge, {}) + const defaults = this.getProfileDefaults(profile).reduce(configMerge, {}) return new ConfigProxy(profile, defaults) as unknown as T } @@ -234,4 +229,38 @@ export class ProfilesService { } window.localStorage['recentProfiles'] = JSON.stringify(recentProfiles) } + + /* + * Methods used to interract with Profile/ProfileGroup/Global defaults + */ + + /** + * Return global defaults for a given profile provider + * Always return something, empty object if no defaults found + */ + getProviderDefaults (provider: ProfileProvider): any { + const defaults = this.config.store.profileDefaults + return defaults[provider.id] ?? {} + } + + /** + * Set global defaults for a given profile provider + */ + setProviderDefaults (provider: ProfileProvider, pdefaults: any) { + this.config.store.profileDefaults[provider.id] = pdefaults + } + + /** + * Return defaults for a given profile + * Always return something, empty object if no defaults found + */ + getProfileDefaults (profile: PartialProfile, skipUserDefaults = false): any { + const provider = this.providerForProfile(profile) + return [ + this.profileDefaults, + provider?.configDefaults ?? {}, + !provider || skipUserDefaults ? {} : this.getProviderDefaults(provider), + ] + } + } diff --git a/tabby-settings/src/components/profilesSettingsTab.component.ts b/tabby-settings/src/components/profilesSettingsTab.component.ts index 38898ae6..6508e912 100644 --- a/tabby-settings/src/components/profilesSettingsTab.component.ts +++ b/tabby-settings/src/components/profilesSettingsTab.component.ts @@ -282,7 +282,7 @@ export class ProfilesSettingsTabComponent extends BaseComponent { EditProfileModalComponent, { size: 'lg' }, ) - const model = this.config.store.profileDefaults[provider.id] ?? {} + const model = this.profilesService.getProviderDefaults(provider) model.type = provider.id modal.componentInstance.profile = Object.assign({}, model) modal.componentInstance.profileProvider = provider @@ -295,7 +295,7 @@ export class ProfilesSettingsTabComponent extends BaseComponent { delete model[k] } Object.assign(model, result) - this.config.store.profileDefaults[provider.id] = model + this.profilesService.setProviderDefaults(provider, model) await this.config.save() }