This commit is contained in:
Alex Yatskov 2016-10-10 20:51:42 -07:00
parent f85874f97b
commit a949e66a6c
3 changed files with 8 additions and 8 deletions

View File

@ -17,10 +17,10 @@
*/ */
class AnkiConnect { class AnkiConnect {
constructor(apiVersion) { constructor() {
this.asyncPools = {}; this.asyncPools = {};
this.apiVersion = apiVersion; this.pluginVersion = null;
this.ankiConnectVer = 0; this.apiVersion = 1;
} }
addNote(note) { addNote(note) {
@ -48,12 +48,13 @@ class AnkiConnect {
} }
ankiInvokeSafe(action, params, pool) { ankiInvokeSafe(action, params, pool) {
if (this.ankiConnectVer === this.apiVersion) { if (this.pluginVersion === this.apiVersion) {
return this.ankiInvoke(action, params, pool); return this.ankiInvoke(action, params, pool);
} }
return this.getVersion().then(version => { return this.getVersion().then(version => {
if (version === this.apiVersion) { if (version === this.apiVersion) {
this.pluginVersion = version;
return this.ankiInvoke(action, params, pool); return this.ankiInvoke(action, params, pool);
} }

View File

@ -39,7 +39,7 @@ function modelIdToFieldOptKey(id) {
function modelIdToMarkers(id) { function modelIdToMarkers(id) {
return { return {
'anki-term-model': ['audio', 'exholdion', 'glossary', 'glossary-list', 'reading', 'sentence', 'tags', 'url'], 'anki-term-model': ['audio', 'expression', 'glossary', 'glossary-list', 'reading', 'sentence', 'tags', 'url'],
'anki-kanji-model': ['character', 'glossary', 'glossary-list', 'kunyomi', 'onyomi', 'url'], 'anki-kanji-model': ['character', 'glossary', 'glossary-list', 'kunyomi', 'onyomi', 'url'],
}[id]; }[id];
} }

View File

@ -23,9 +23,9 @@ class Yomichan {
Handlebars.registerHelper('kanjiLinks', kanjiLinks); Handlebars.registerHelper('kanjiLinks', kanjiLinks);
this.translator = new Translator(); this.translator = new Translator();
this.anki = new AnkiConnect();
this.options = null; this.options = null;
this.importTabId = null; this.importTabId = null;
this.anki = new AnkiConnect(this.getApiVersion());
this.setState('disabled'); this.setState('disabled');
chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
@ -248,7 +248,6 @@ class Yomichan {
this.anki.canAddNotes(notes).then(results => { this.anki.canAddNotes(notes).then(results => {
const states = []; const states = [];
if (results !== null) { if (results !== null) {
for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) { for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
const state = {}; const state = {};
@ -269,7 +268,7 @@ class Yomichan {
} }
api_getModelNames({callback}) { api_getModelNames({callback}) {
this.anki.getModelFieldNames().then(callback); this.anki.getModelNames().then(callback);
} }
api_getModelFieldNames({modelName, callback}) { api_getModelFieldNames({modelName, callback}) {