This commit is contained in:
Alex Yatskov 2016-10-19 20:57:08 -07:00
parent 055174efd2
commit 7618b8e909
3 changed files with 38 additions and 25 deletions

View File

@ -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();

View File

@ -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>

View File

@ -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() {