Skip to content

Commit

Permalink
Make the preference schema validation optional (#11189)
Browse files Browse the repository at this point in the history
It costs time at startup and it only logs warnings.
Can be disabled with the `validatePreferencesSchema`
fronted app config.

Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
kittaakos authored May 24, 2022
1 parent eb5b668 commit fad026f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 10 additions & 1 deletion dev-packages/application-package/src/application-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export namespace FrontendApplicationConfig {
defaultTheme: 'dark',
defaultIconTheme: 'none',
electron: ElectronFrontendApplicationConfig.DEFAULT,
defaultLocale: ''
defaultLocale: '',
validatePreferencesSchema: true
};
export interface Partial extends ApplicationConfig {

Expand Down Expand Up @@ -93,6 +94,14 @@ export namespace FrontendApplicationConfig {
* Defaults to "".
*/
readonly defaultLocale?: string;

/**
* When `true`, the application will validate the JSON schema of the preferences on start
* and log warnings to the console if the schema is not valid.
*
* Defaults to `true`.
*/
readonly validatePreferencesSchema?: boolean;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,19 @@ export class PreferenceSchemaProvider extends PreferenceProvider {
return inverseChanges;
}

protected doSetSchema(schema: PreferenceSchema): PreferenceProviderDataChange[] {
protected validateSchema(schema: PreferenceSchema): void {
const ajv = new Ajv();
const valid = ajv.validateSchema(schema);
if (!valid) {
const errors = !!ajv.errors ? ajv.errorsText(ajv.errors) : 'unknown validation error';
console.warn('A contributed preference schema has validation issues : ' + errors);
}
}

protected doSetSchema(schema: PreferenceSchema): PreferenceProviderDataChange[] {
if (FrontendApplicationConfigProvider.get().validatePreferencesSchema) {
this.validateSchema(schema);
}
const scope = PreferenceScope.Default;
const domain = this.getDomain();
const changes: PreferenceProviderDataChange[] = [];
Expand Down

0 comments on commit fad026f

Please sign in to comment.