Adding version checking
This commit is contained in:
parent
9ab95e6602
commit
6f63999dce
@ -86,6 +86,17 @@ function populateAnkiDeckAndModel(opts) {
|
|||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateAnkiStatus() {
|
||||||
|
$('.error-dlg').hide();
|
||||||
|
yomichan().api_getVersion({callback: (version) => {
|
||||||
|
if (version === null) {
|
||||||
|
$('.error-dlg-connection').show();
|
||||||
|
} else if (version !== yomichan().getApiVersion()) {
|
||||||
|
$('.error-dlg-version').show();
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
function populateAnkiFields(element, opts) {
|
function populateAnkiFields(element, opts) {
|
||||||
const modelName = element.val();
|
const modelName = element.val();
|
||||||
if (modelName === null) {
|
if (modelName === null) {
|
||||||
@ -119,6 +130,7 @@ function onOptionsGeneralChanged(e) {
|
|||||||
saveOptions(optsNew, () => {
|
saveOptions(optsNew, () => {
|
||||||
yomichan().setOptions(optsNew);
|
yomichan().setOptions(optsNew);
|
||||||
if (!optsOld.enableAnkiConnect && optsNew.enableAnkiConnect) {
|
if (!optsOld.enableAnkiConnect && optsNew.enableAnkiConnect) {
|
||||||
|
updateAnkiStatus();
|
||||||
populateAnkiDeckAndModel(optsNew);
|
populateAnkiDeckAndModel(optsNew);
|
||||||
$('.options-anki').fadeIn();
|
$('.options-anki').fadeIn();
|
||||||
} else if (optsOld.enableAnkiConnect && !optsNew.enableAnkiConnect) {
|
} else if (optsOld.enableAnkiConnect && !optsNew.enableAnkiConnect) {
|
||||||
@ -159,6 +171,7 @@ $(document).ready(() => {
|
|||||||
$('.anki-model').change(onAnkiModelChanged);
|
$('.anki-model').change(onAnkiModelChanged);
|
||||||
|
|
||||||
if (opts.enableAnkiConnect) {
|
if (opts.enableAnkiConnect) {
|
||||||
|
updateAnkiStatus();
|
||||||
populateAnkiDeckAndModel(opts);
|
populateAnkiDeckAndModel(opts);
|
||||||
$('.options-anki').show();
|
$('.options-anki').show();
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,10 @@ class Yomichan {
|
|||||||
this.notifyTabs('options', this.options);
|
this.notifyTabs('options', this.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getApiVersion() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
notifyTabs(name, value) {
|
notifyTabs(name, value) {
|
||||||
chrome.tabs.query({}, (tabs) => {
|
chrome.tabs.query({}, (tabs) => {
|
||||||
for (const tab of 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) {
|
ankiInvoke(action, params, pool, callback) {
|
||||||
if (this.options.enableAnkiConnect) {
|
if (this.options.enableAnkiConnect) {
|
||||||
if (pool !== null && this.asyncPools.hasOwnProperty(pool)) {
|
if (pool !== null && this.asyncPools.hasOwnProperty(pool)) {
|
||||||
@ -181,7 +195,7 @@ class Yomichan {
|
|||||||
|
|
||||||
api_addDefinition({definition, mode, callback}) {
|
api_addDefinition({definition, mode, callback}) {
|
||||||
const note = this.formatNote(definition, mode);
|
const note = this.formatNote(definition, mode);
|
||||||
this.ankiInvoke('addNote', {note}, null, callback);
|
this.ankiInvokeSafe('addNote', {note}, null, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
api_canAddDefinitions({definitions, modes, 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 = [];
|
const states = [];
|
||||||
|
|
||||||
if (results !== null) {
|
if (results !== null) {
|
||||||
@ -219,15 +233,19 @@ class Yomichan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
api_getDeckNames({callback}) {
|
api_getDeckNames({callback}) {
|
||||||
this.ankiInvoke('deckNames', {}, null, callback);
|
this.ankiInvokeSafe('deckNames', {}, null, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
api_getModelNames({callback}) {
|
api_getModelNames({callback}) {
|
||||||
this.ankiInvoke('modelNames', {}, null, callback);
|
this.ankiInvokeSafe('modelNames', {}, null, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
api_getModelFieldNames({modelName, 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}) {
|
api_getOptions({callback}) {
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
border-right: 1px #ddd solid;
|
border-right: 1px #ddd solid;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error-dlg {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -60,7 +64,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-sm-offset-2 col-sm-10">
|
<div class="col-sm-offset-2 col-sm-10">
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label class="control-label"><input type="checkbox" id="enable-anki-connect"> Enable <a href="https://foosoft.net/projects/yomichan">AnkiConnect</a></label>
|
<label class="control-label"><input type="checkbox" id="enable-anki-connect"> Enable <a href="https://foosoft.net/projects/anki-connect">AnkiConnect</a></label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -71,6 +75,9 @@
|
|||||||
<div class="options-anki">
|
<div class="options-anki">
|
||||||
<h2>Anki</h2>
|
<h2>Anki</h2>
|
||||||
|
|
||||||
|
<div class="alert alert-danger error-dlg error-dlg-connection"><strong>Unable to connect</strong>: is the <a href="https://foosoft.net/projects/anki-connect">AnkiConnect</a> extension for <a href="http://ankisrs.net/">Anki</a> installed and running?</div>
|
||||||
|
<div class="alert alert-warning error-dlg error-dlg-version"><strong>Unsupported version</strong>: the installed version of the <a href="https://foosoft.net/projects/anki-connect">AnkiConnect</a> extension for <a href="http://ankisrs.net/">Anki</a> is not compatible with this release.</div>
|
||||||
|
|
||||||
<form class="form-horizontal">
|
<form class="form-horizontal">
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
<li class="active"><a href="#vocab" data-toggle="tab">Vocabulary</a></li>
|
<li class="active"><a href="#vocab" data-toggle="tab">Vocabulary</a></li>
|
||||||
|
Loading…
Reference in New Issue
Block a user