summaryrefslogtreecommitdiff
path: root/ext/bg/js/yomichan.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-05-29 14:20:13 -0700
committerAlex Yatskov <alex@foosoft.net>2016-05-29 14:20:13 -0700
commit6f63999dce9f14103d6dfae155c4fc0c151ab8de (patch)
tree2a8621b94c0bc0dc3d66526b4545c093cde870ea /ext/bg/js/yomichan.js
parent9ab95e6602e7bf327764f356efc388558856e6e3 (diff)
Adding version checking
Diffstat (limited to 'ext/bg/js/yomichan.js')
-rw-r--r--ext/bg/js/yomichan.js28
1 files changed, 23 insertions, 5 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 03f9d082..b3e8bf71 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -99,6 +99,10 @@ class Yomichan {
this.notifyTabs('options', this.options);
}
+ getApiVersion() {
+ return 1;
+ }
+
notifyTabs(name, value) {
chrome.tabs.query({}, (tabs) => {
for (const tab of tabs) {
@@ -107,6 +111,16 @@ class Yomichan {
});
}
+ ankiInvokeSafe(action, params, pool, callback) {
+ this.api_getVersion({callback: (version) => {
+ if (version === this.getApiVersion()) {
+ this.ankiInvoke(action, params, pool, callback);
+ } else {
+ callback(null);
+ }
+ }});
+ }
+
ankiInvoke(action, params, pool, callback) {
if (this.options.enableAnkiConnect) {
if (pool !== null && this.asyncPools.hasOwnProperty(pool)) {
@@ -181,7 +195,7 @@ class Yomichan {
api_addDefinition({definition, mode, callback}) {
const note = this.formatNote(definition, mode);
- this.ankiInvoke('addNote', {note}, null, callback);
+ this.ankiInvokeSafe('addNote', {note}, null, callback);
}
api_canAddDefinitions({definitions, modes, callback}) {
@@ -192,7 +206,7 @@ class Yomichan {
}
}
- this.ankiInvoke('canAddNotes', {notes}, 'notes', (results) => {
+ this.ankiInvokeSafe('canAddNotes', {notes}, 'notes', (results) => {
const states = [];
if (results !== null) {
@@ -219,15 +233,19 @@ class Yomichan {
}
api_getDeckNames({callback}) {
- this.ankiInvoke('deckNames', {}, null, callback);
+ this.ankiInvokeSafe('deckNames', {}, null, callback);
}
api_getModelNames({callback}) {
- this.ankiInvoke('modelNames', {}, null, callback);
+ this.ankiInvokeSafe('modelNames', {}, null, callback);
}
api_getModelFieldNames({modelName, callback}) {
- this.ankiInvoke('modelFieldNames', {modelName}, null, callback);
+ this.ankiInvokeSafe('modelFieldNames', {modelName}, null, callback);
+ }
+
+ api_getVersion({callback}) {
+ this.ankiInvoke('version', {}, null, callback);
}
api_getOptions({callback}) {