aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-11-23 19:18:29 +0200
committersiikamiika <siikamiika@users.noreply.github.com>2019-11-23 19:18:29 +0200
commit7bf2c8048d82c62dafdfa6a6866ec63e7e95a56b (patch)
tree972a7869a9cf2ccbd41ee24f9cbf0da209e81d0a
parent2577d4054e344d2e6dc08d2cf95e83478c05bee6 (diff)
add mecab version check
-rw-r--r--ext/bg/js/mecab.js24
1 files changed, 21 insertions, 3 deletions
diff --git a/ext/bg/js/mecab.js b/ext/bg/js/mecab.js
index ada96945..a26b7f39 100644
--- a/ext/bg/js/mecab.js
+++ b/ext/bg/js/mecab.js
@@ -24,10 +24,23 @@ class Mecab {
this.sequence = 0;
}
- async parseText(text) {
- if (this.port === null) {
- return {};
+ onError(error) {
+ logError(error, true);
+ }
+
+ async checkVersion() {
+ try {
+ const {version} = await this.invoke('get_version', {});
+ if (version !== Mecab.version) {
+ this.stopListener();
+ throw new Error(`Unsupported MeCab native messenger version ${version}. Yomichan supports version ${Mecab.version}.`);
+ }
+ } catch (error) {
+ this.onError(error);
}
+ }
+
+ async parseText(text) {
return await this.invoke('parse_text', {text});
}
@@ -35,6 +48,7 @@ class Mecab {
if (this.port !== null) { return; }
this.port = chrome.runtime.connectNative('yomichan_mecab');
this.port.onMessage.addListener(this.onNativeMessage.bind(this));
+ this.checkVersion();
}
stopListener() {
@@ -55,6 +69,9 @@ class Mecab {
}
invoke(action, params) {
+ if (this.port === null) {
+ return {};
+ }
return new Promise((resolve, reject) => {
const sequence = this.sequence++;
@@ -72,3 +89,4 @@ class Mecab {
}
Mecab.timeout = 5000;
+Mecab.version = 1;