summaryrefslogtreecommitdiff
path: root/ext/bg/js/mecab.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-11-08 00:49:20 +0200
committersiikamiika <siikamiika@users.noreply.github.com>2019-11-23 17:45:44 +0200
commitc1d24208d383e687f443c4e7dfc7bfda81d191bd (patch)
tree4be76fa658df160e1eca35832a81bb547e071b59 /ext/bg/js/mecab.js
parent955e131f9673e006556bc2c5e0b3551a614ccc48 (diff)
start mecab only after enabling the setting
Diffstat (limited to 'ext/bg/js/mecab.js')
-rw-r--r--ext/bg/js/mecab.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/ext/bg/js/mecab.js b/ext/bg/js/mecab.js
index fba9b2eb..4c62c2b0 100644
--- a/ext/bg/js/mecab.js
+++ b/ext/bg/js/mecab.js
@@ -19,16 +19,20 @@
class Mecab {
constructor() {
+ this.port = null;
this.listeners = {};
this.sequence = 0;
- this.startListener();
}
async parseText(text) {
+ if (this.port === null) {
+ return {};
+ }
return await this.invoke('parse_text', {text});
}
startListener() {
+ if (this.port !== null) { return; }
this.port = chrome.runtime.connectNative('yomichan_mecab');
this.port.onMessage.addListener((message) => {
const {sequence, data} = message;
@@ -41,6 +45,14 @@ class Mecab {
});
}
+ stopListener() {
+ if (this.port === null) { return; }
+ this.port.disconnect();
+ this.port = null;
+ this.listeners = {};
+ this.sequence = 0;
+ }
+
invoke(action, params) {
return new Promise((resolve, reject) => {
const sequence = this.sequence++;