From 017f72cc362a2523527a9177082513217cfa542c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Thu, 24 Sep 2020 14:14:21 +0000 Subject: [PATCH] Interpret preference strings as JSON values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Mäder --- .../src/browser/prefs-provider.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/extensions/eclipse-che-theia-preferences-provider-extension/src/browser/prefs-provider.ts b/extensions/eclipse-che-theia-preferences-provider-extension/src/browser/prefs-provider.ts index df1ee2153d..ec592d3db6 100644 --- a/extensions/eclipse-che-theia-preferences-provider-extension/src/browser/prefs-provider.ts +++ b/extensions/eclipse-che-theia-preferences-provider-extension/src/browser/prefs-provider.ts @@ -77,15 +77,20 @@ export class PreferencesProvider implements FrontendApplicationContribution { private async setPluginProperties(props: [string, string][]): Promise { await this.workspaceService.roots; - const workspace = this.workspaceService.workspace; - if (!workspace) { - throw new Error('Failed to get Theia workspace.'); - } for (const [key, value] of props) { - if (this.preferenceService.has(key, workspace.uri)) { - continue; + try { + this.setPreferenceValue(key, JSON.parse(value)); + } catch (error) { + console.warn('could not parse value for prefernece key %s, using string value: %o', key, error); + this.setPreferenceValue(key, value); } - await this.preferenceService.set(key, value, PreferenceScope.Workspace, workspace.uri); + } + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private async setPreferenceValue(key: string, value: any): Promise { + if (!this.preferenceService.has(key)) { + await this.preferenceService.set(key, value, PreferenceScope.Workspace); } }