From 5076b80f9690a12fda23d06b2c3ddd1df08cff56 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 5 Feb 2017 11:44:59 -0800 Subject: tweaks for ankiconnect --- ext/bg/js/ankiconnect.js | 9 +++++---- ext/bg/js/options-form.js | 4 +++- ext/bg/js/options.js | 11 ++++++----- ext/bg/js/yomichan.js | 2 +- ext/bg/options.html | 5 +++++ ext/manifest.json | 2 +- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/ext/bg/js/ankiconnect.js b/ext/bg/js/ankiconnect.js index d17f3268..f6f94329 100644 --- a/ext/bg/js/ankiconnect.js +++ b/ext/bg/js/ankiconnect.js @@ -17,7 +17,8 @@ */ class AnkiConnect { - constructor() { + constructor(server) { + this.server = server; this.asyncPools = {}; this.localVersion = 1; this.remoteVersion = null; @@ -50,8 +51,8 @@ class AnkiConnect { return this.ankiInvoke('version', {}, null).then(version => { this.remoteVersion = version; - if (this.remoteVersion !== this.localVersion) { - return Promise.reject('extension and plugin version mismatch'); + if (this.remoteVersion < this.localVersion) { + return Promise.reject('extension and plugin versions incompatible'); } }); } @@ -75,7 +76,7 @@ class AnkiConnect { } }); - xhr.open('POST', 'http://127.0.0.1:8765'); + xhr.open('POST', this.server); xhr.send(JSON.stringify({action, params})); }); } diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index ed2826b4..00b6a63e 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -44,6 +44,7 @@ function getFormData() { optionsNew.anki.tags = $('#card-tags').val().split(/[,; ]+/); optionsNew.anki.htmlCards = $('#generate-html-cards').prop('checked'); optionsNew.anki.sentenceExt = parseInt($('#sentence-detection-extent').val(), 10); + optionsNew.anki.server = $('#interface-server').val(); if (optionsOld.anki.enable) { optionsNew.anki.terms.deck = $('#anki-terms-deck').val(); optionsNew.anki.terms.model = $('#anki-terms-model').val(); @@ -106,6 +107,7 @@ $(document).ready(() => { $('#card-tags').val(options.anki.tags.join(' ')); $('#generate-html-cards').prop('checked', options.anki.htmlCards); $('#sentence-detection-extent').val(options.anki.sentenceExt); + $('#interface-server').val(options.anki.server); $('input, select').not('.anki-model').change(onOptionsChanged); $('.anki-model').change(onAnkiModelChanged); @@ -399,7 +401,7 @@ function onOptionsChanged(e) { return optionsSave(optionsNew).then(() => { yomichan().setOptions(optionsNew); updateVisibility(optionsNew); - if (optionsNew.anki.enable !== optionsOld.anki.enable) { + if (optionsNew.anki.enable !== optionsOld.anki.enable || optionsNew.anki.server !== optionsOld.anki.server) { showAnkiError(null); showAnkiSpinner(true); return populateAnkiDeckAndModel(optionsNew); diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 863e8916..a4e39e41 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -39,6 +39,7 @@ function optionsSetDefaults(options) { anki: { enable: false, + server: 'http://127.0.0.1:8765', tags: ['yomichan'], htmlCards: true, sentenceExt: 200, @@ -67,14 +68,14 @@ function optionsSetDefaults(options) { function optionsVersion(options) { - const copy = (targetDict, targetKey, sourceDict, sourceKey) => { - targetDict[targetKey] = sourceDict.hasOwnProperty(sourceKey) ? sourceDict[sourceKey] : targetDict[targetKey]; - }; - + optionsSetDefaults(options); options.version = options.version || 0; + const fixups = [ () => { - optionsSetDefaults(options); + const copy = (targetDict, targetKey, sourceDict, sourceKey) => { + targetDict[targetKey] = sourceDict.hasOwnProperty(sourceKey) ? sourceDict[sourceKey] : targetDict[targetKey]; + }; copy(options.general, 'autoStart', options, 'activateOnStartup'); copy(options.general, 'audioPlayback', options, 'enableAudioPlayback'); diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index d97dc586..80a67588 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -71,7 +71,7 @@ class Yomichan { this.options = options; if (options.anki.enable) { - this.anki = new AnkiConnect(); + this.anki = new AnkiConnect(this.options.anki.server); } else { this.anki = new AnkiNull(); } diff --git a/ext/bg/options.html b/ext/bg/options.html index 145f97fd..d9d23c6a 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -161,6 +161,11 @@ +
+ + +
+