aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-07 10:47:30 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-07 10:47:30 -0500
commit93aa275d827816c624f30548ac635b4fea1d23eb (patch)
tree8220d794de2b6a988a452de8403bbc7a233e5b12 /ext
parent7822230b7f969b74d3a307fe383a62be9e31c713 (diff)
Use explicit dependency injection for ClipboardMonitor
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/api.js4
-rw-r--r--ext/bg/js/backend.js2
-rw-r--r--ext/bg/js/clipboard-monitor.js9
-rw-r--r--ext/bg/js/search.js4
4 files changed, 8 insertions, 11 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 0c244ffa..93e43a7d 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -25,10 +25,6 @@ function apiAudioGetUrl(definition, source, optionsContext) {
return _apiInvoke('audioGetUrl', {definition, source, optionsContext});
}
-function apiClipboardGet() {
- return _apiInvoke('clipboardGet');
-}
-
function _apiInvoke(action, params={}) {
const data = {action, params};
return new Promise((resolve, reject) => {
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 2e46088c..3226dd9c 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -30,7 +30,7 @@ class Backend {
this.translator = new Translator();
this.anki = new AnkiNull();
this.mecab = new Mecab();
- this.clipboardMonitor = new ClipboardMonitor();
+ this.clipboardMonitor = new ClipboardMonitor({getClipboard: this._onApiClipboardGet.bind(this)});
this.options = null;
this.optionsSchema = null;
this.defaultAnkiFieldTemplates = null;
diff --git a/ext/bg/js/clipboard-monitor.js b/ext/bg/js/clipboard-monitor.js
index c102572f..2ba6d487 100644
--- a/ext/bg/js/clipboard-monitor.js
+++ b/ext/bg/js/clipboard-monitor.js
@@ -16,22 +16,23 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-/*global apiClipboardGet, jpIsStringPartiallyJapanese*/
+/*global jpIsStringPartiallyJapanese*/
class ClipboardMonitor extends EventDispatcher {
- constructor() {
+ constructor({getClipboard}) {
super();
this.timerId = null;
this.timerToken = null;
this.interval = 250;
this.previousText = null;
+ this.getClipboard = getClipboard;
}
start() {
this.stop();
// The token below is used as a unique identifier to ensure that a new clipboard monitor
- // hasn't been started during the await call. The check below the await apiClipboardGet()
+ // hasn't been started during the await call. The check below the await this.getClipboard()
// call will exit early if the reference has changed.
const token = {};
const intervalCallback = async () => {
@@ -39,7 +40,7 @@ class ClipboardMonitor extends EventDispatcher {
let text = null;
try {
- text = await apiClipboardGet();
+ text = await this.getClipboard();
} catch (e) {
// NOP
}
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 9acccb90..f9481ea2 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-/*global apiOptionsSet, apiTermsFind, Display, QueryParser, ClipboardMonitor*/
+/*global apiOptionsSet, apiTermsFind, apiClipboardGet, Display, QueryParser, ClipboardMonitor*/
class DisplaySearch extends Display {
constructor() {
@@ -38,7 +38,7 @@ class DisplaySearch extends Display {
this.introVisible = true;
this.introAnimationTimer = null;
- this.clipboardMonitor = new ClipboardMonitor();
+ this.clipboardMonitor = new ClipboardMonitor({getClipboard: apiClipboardGet});
this._onKeyDownIgnoreKeys = new Map([
['ANY_MOD', new Set([