diff options
-rw-r--r-- | ext/bg/js/yomichan.js | 46 | ||||
-rw-r--r-- | ext/bg/options.html | 7 | ||||
-rw-r--r-- | ext/fg/js/util.js | 10 |
3 files changed, 38 insertions, 25 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index 0e39d3e8..416a4911 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -231,28 +231,44 @@ class Yomichan { } api_getEnabled({callback}) { - callback(this.state === 'enabled'); + callback(this.state === 'enabled', null); } api_getOptions({callback}) { - loadOptions().then(opts => callback(opts)).catch(() => callback(null)); + loadOptions().then(result => { + callback(result, null); + }).catch(error => { + callback(null, error); + }); } api_findKanji({text, callback}) { - this.translator.findKanji(text).then(result => callback(result)).catch(() => callback(null)); + this.translator.findKanji(text).then(result => { + callback(result, null); + }).catch(error => { + callback(null, error); + }); } api_findTerm({text, callback}) { - this.translator.findTerm(text).then(result => callback(result)).catch(() => callback(null)); + this.translator.findTerm(text).then(result => { + callback(result, null); + }).catch(error => { + callback(null, error); + }); } api_renderText({template, data, callback}) { - callback(Handlebars.templates[template](data)); + callback(Handlebars.templates[template](data), null); } api_addDefinition({definition, mode, callback}) { const note = this.formatNote(definition, mode); - this.anki.addNote(note).then(callback).catch(() => callback(null)); + this.anki.addNote(note).then(result => { + callback(result, null); + }).catch(error => { + callback(null, error); + }); } api_canAddDefinitions({definitions, modes, callback}) { @@ -276,23 +292,11 @@ class Yomichan { } } - callback(states); - }).catch(() => { - callback(null); + callback(states, null); + }).catch(error => { + callback(null, error); }); } - - api_getDeckNames({callback}) { - this.anki.getDeckNames().then(callback).catch(() => callback(null)); - } - - api_getModelNames({callback}) { - this.anki.getModelNames().then(callback).catch(() => callback(null)); - } - - api_getModelFieldNames({modelName, callback}) { - this.anki.getModelFieldNames(modelName).then(callback).catch(() => callback(null)); - } } window.yomichan = new Yomichan(); diff --git a/ext/bg/options.html b/ext/bg/options.html index 2b2e283b..73e3b790 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -59,9 +59,10 @@ </div> <div> - <img src="img/spinner.gif" class="pull-right" id="anki-spinner" alt> - - <h3>Anki Options</h3> + <div> + <img src="img/spinner.gif" class="pull-right" id="anki-spinner" alt> + <h3>Anki Options</h3> + </div> <div class="alert alert-danger" id="anki-error"> <strong>Error:</strong> diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js index cf5621ec..7248ae86 100644 --- a/ext/fg/js/util.js +++ b/ext/fg/js/util.js @@ -18,7 +18,15 @@ function invokeApiBg(action, params) { - return new Promise((resolve, reject) => chrome.runtime.sendMessage({action, params}, resolve)); + return new Promise((resolve, reject) => { + chrome.runtime.sendMessage({action, params}, (result, error) => { + if (error) { + reject(error); + } else { + resolve(result); + } + }); + }); } function getEnabled() { |