aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/backend.js2
-rw-r--r--ext/bg/js/mecab.js19
-rw-r--r--ext/bg/js/settings.js15
3 files changed, 12 insertions, 24 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 027cc250..45db9660 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -101,6 +101,8 @@ class Backend {
if (options.parsing.enableMecabParser) {
this.mecab.startListener();
+ } else {
+ this.mecab.stopListener();
}
}
diff --git a/ext/bg/js/mecab.js b/ext/bg/js/mecab.js
index b9f2d0b3..ada96945 100644
--- a/ext/bg/js/mecab.js
+++ b/ext/bg/js/mecab.js
@@ -34,15 +34,7 @@ class Mecab {
startListener() {
if (this.port !== null) { return; }
this.port = chrome.runtime.connectNative('yomichan_mecab');
- this.port.onMessage.addListener((message) => {
- const {sequence, data} = message;
- const {callback, timer} = this.listeners[sequence] || {};
- if (timer) {
- clearTimeout(timer);
- delete this.listeners[sequence];
- callback(data);
- }
- });
+ this.port.onMessage.addListener(this.onNativeMessage.bind(this));
}
stopListener() {
@@ -53,6 +45,15 @@ class Mecab {
this.sequence = 0;
}
+ onNativeMessage({sequence, data}) {
+ if (this.listeners.hasOwnProperty(sequence)) {
+ const {callback, timer} = this.listeners[sequence];
+ clearTimeout(timer);
+ callback(data);
+ delete this.listeners[sequence];
+ }
+ }
+
invoke(action, params) {
return new Promise((resolve, reject) => {
const sequence = this.sequence++;
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js
index 0013291a..f4fe032a 100644
--- a/ext/bg/js/settings.js
+++ b/ext/bg/js/settings.js
@@ -154,7 +154,6 @@ async function formWrite(options) {
function formSetupEventListeners() {
$('input, select, textarea').not('.anki-model').not('.ignore-form-changes *').change(utilAsync(onFormOptionsChanged));
- $('#parsing-mecab-enable').change(onParseMecabChanged);
$('.anki-model').change(utilAsync(onAnkiModelChanged));
}
@@ -442,20 +441,6 @@ function onMessage({action, params}, sender, callback) {
/*
- * Text parsing
- */
-
-function onParseMecabChanged(e) {
- const mecab = utilBackend().mecab;
- if (e.target.checked) {
- mecab.startListener();
- } else {
- mecab.stopListener();
- }
-}
-
-
-/*
* Anki
*/