From f168efb69c0387da0be4e9f2807fd9074992346f Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 11 Sep 2020 14:15:08 -0400 Subject: OptionsUtil refactor / options default values (#807) * Replace _readFile with _fetchAsset for consistency with Backend * Fix error messages * Make OptionsUtil non-static * Update how default options are assigned * Add createValidatingProxy * Add validate, update _onApiSetAllSettings * Remove unused api.optionsSchemaGet * Remove Backend._optionsSchema * Update OptionsUtil to create its own JsonSchemaValidator * Rename Backend._optionsSchemaValidator * Make getDefault non-async --- ext/bg/js/settings/backup-controller.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'ext/bg/js/settings') diff --git a/ext/bg/js/settings/backup-controller.js b/ext/bg/js/settings/backup-controller.js index ac1294e7..08ee7070 100644 --- a/ext/bg/js/settings/backup-controller.js +++ b/ext/bg/js/settings/backup-controller.js @@ -26,9 +26,12 @@ class BackupController { this._settingsExportToken = null; this._settingsExportRevoke = null; this._currentVersion = 0; + this._optionsUtil = new OptionsUtil(); } - prepare() { + async prepare() { + await this._optionsUtil.prepare(); + document.querySelector('#settings-export').addEventListener('click', this._onSettingsExportClick.bind(this), false); document.querySelector('#settings-import').addEventListener('click', this._onSettingsImportClick.bind(this), false); document.querySelector('#settings-import-file').addEventListener('change', this._onSettingsImportFileChange.bind(this), false); @@ -140,7 +143,11 @@ class BackupController { // Importing async _settingsImportSetOptionsFull(optionsFull) { - await this._settingsController.setAllSettings(optionsFull); + try { + await this._settingsController.setAllSettings(optionsFull); + } catch (e) { + yomichan.logError(e); + } } _showSettingsImportError(error) { @@ -322,7 +329,7 @@ class BackupController { } // Upgrade options - optionsFull = await OptionsUtil.update(optionsFull); + optionsFull = await this._optionsUtil.update(optionsFull); // Check for warnings const sanitizationWarnings = this._settingsImportSanitizeOptions(optionsFull, true); @@ -368,7 +375,7 @@ class BackupController { $('#settings-reset-modal').modal('hide'); // Get default options - const optionsFull = await OptionsUtil.getDefault(); + const optionsFull = this._optionsUtil.getDefault(); // Assign options await this._settingsImportSetOptionsFull(optionsFull); -- cgit v1.2.3