Use schema to validate options
This commit is contained in:
parent
b770944b12
commit
50e0fbbb66
@ -31,6 +31,7 @@
|
||||
<script src="/bg/js/deinflector.js"></script>
|
||||
<script src="/bg/js/dictionary.js"></script>
|
||||
<script src="/bg/js/handlebars.js"></script>
|
||||
<script src="/bg/js/json-schema.js"></script>
|
||||
<script src="/bg/js/options.js"></script>
|
||||
<script src="/bg/js/profile-conditions.js"></script>
|
||||
<script src="/bg/js/request.js"></script>
|
||||
|
@ -23,6 +23,7 @@ class Backend {
|
||||
this.anki = new AnkiNull();
|
||||
this.mecab = new Mecab();
|
||||
this.options = null;
|
||||
this.optionsSchema = null;
|
||||
this.optionsContext = {
|
||||
depth: 0,
|
||||
url: window.location.href
|
||||
@ -38,7 +39,16 @@ class Backend {
|
||||
|
||||
async prepare() {
|
||||
await this.translator.prepare();
|
||||
|
||||
this.optionsSchema = await requestJson(chrome.runtime.getURL('/bg/data/options-schema.json'), 'GET');
|
||||
this.options = await optionsLoad();
|
||||
try {
|
||||
this.options = JsonSchema.getValidValueOrDefault(this.optionsSchema, this.options);
|
||||
} catch (e) {
|
||||
// This shouldn't happen, but catch errors just in case of bugs
|
||||
logError(e);
|
||||
}
|
||||
|
||||
this.onOptionsUpdated('background');
|
||||
|
||||
if (chrome.commands !== null && typeof chrome.commands === 'object') {
|
||||
|
Loading…
Reference in New Issue
Block a user