aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-01-26 03:31:31 +0200
committersiikamiika <siikamiika@users.noreply.github.com>2020-02-09 21:51:33 +0200
commit90a5d795708898fba940f77358269354e96355a7 (patch)
treed77eea8b005848d5528c539ace87232cc624f0cd /ext/bg/js/backend.js
parentc685fd0e5f90c32911a225f0aaa68f5ff9fdfb7b (diff)
use ClipboardMonitor in Backend
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js25
1 files changed, 11 insertions, 14 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index d80e7713..fa1660c2 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -22,6 +22,7 @@ class Backend {
this.translator = new Translator();
this.anki = new AnkiNull();
this.mecab = new Mecab();
+ this.clipboardMonitor = new ClipboardMonitor();
this.options = null;
this.optionsSchema = null;
this.optionsContext = {
@@ -33,10 +34,8 @@ class Backend {
this.isPreparedPromise = new Promise((resolve) => (this.isPreparedResolve = resolve));
this.clipboardPasteTarget = document.querySelector('#clipboard-paste-target');
+
this.popupWindow = null;
- this.clipboardPopupTimerId = null;
- this.clipboardInterval = 250;
- this.clipboardPreviousText = null;
this.apiForwarder = new BackendApiForwarder();
}
@@ -71,6 +70,8 @@ class Backend {
this.isPreparedResolve();
this.isPreparedResolve = null;
this.isPreparedPromise = null;
+
+ this.clipboardMonitor.onClipboardText = (text) => this._onClipboardText(text);
}
onOptionsUpdated(source) {
@@ -101,6 +102,10 @@ class Backend {
}
}
+ _onClipboardText(text) {
+ this._onCommandSearch({mode: 'popup', query: text});
+ }
+
_onZoomChange({tabId, oldZoomFactor, newZoomFactor}) {
const callback = () => this.checkLastError(chrome.runtime.lastError);
chrome.tabs.sendMessage(tabId, {action: 'zoomChanged', params: {oldZoomFactor, newZoomFactor}}, callback);
@@ -126,18 +131,10 @@ class Backend {
this.mecab.stopListener();
}
- window.clearInterval(this.clipboardPopupTimerId);
if (options.general.enableClipboardPopups) {
- this.clipboardPopupTimerId = setInterval(() => {
- this._onApiClipboardGet()
- .then((result) => {
- if (this.clipboardPreviousText === result) {
- return;
- }
- this._onCommandSearch({mode: 'popup', query: result});
- this.clipboardPreviousText = result;
- });
- }, this.clipboardInterval);
+ this.clipboardMonitor.start();
+ } else {
+ this.clipboardMonitor.stop();
}
}