Use explicit dependency injection for ClipboardMonitor
This commit is contained in:
parent
7822230b7f
commit
93aa275d82
@ -25,10 +25,6 @@ function apiAudioGetUrl(definition, source, optionsContext) {
|
|||||||
return _apiInvoke('audioGetUrl', {definition, source, optionsContext});
|
return _apiInvoke('audioGetUrl', {definition, source, optionsContext});
|
||||||
}
|
}
|
||||||
|
|
||||||
function apiClipboardGet() {
|
|
||||||
return _apiInvoke('clipboardGet');
|
|
||||||
}
|
|
||||||
|
|
||||||
function _apiInvoke(action, params={}) {
|
function _apiInvoke(action, params={}) {
|
||||||
const data = {action, params};
|
const data = {action, params};
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -30,7 +30,7 @@ class Backend {
|
|||||||
this.translator = new Translator();
|
this.translator = new Translator();
|
||||||
this.anki = new AnkiNull();
|
this.anki = new AnkiNull();
|
||||||
this.mecab = new Mecab();
|
this.mecab = new Mecab();
|
||||||
this.clipboardMonitor = new ClipboardMonitor();
|
this.clipboardMonitor = new ClipboardMonitor({getClipboard: this._onApiClipboardGet.bind(this)});
|
||||||
this.options = null;
|
this.options = null;
|
||||||
this.optionsSchema = null;
|
this.optionsSchema = null;
|
||||||
this.defaultAnkiFieldTemplates = null;
|
this.defaultAnkiFieldTemplates = null;
|
||||||
|
@ -16,22 +16,23 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*global apiClipboardGet, jpIsStringPartiallyJapanese*/
|
/*global jpIsStringPartiallyJapanese*/
|
||||||
|
|
||||||
class ClipboardMonitor extends EventDispatcher {
|
class ClipboardMonitor extends EventDispatcher {
|
||||||
constructor() {
|
constructor({getClipboard}) {
|
||||||
super();
|
super();
|
||||||
this.timerId = null;
|
this.timerId = null;
|
||||||
this.timerToken = null;
|
this.timerToken = null;
|
||||||
this.interval = 250;
|
this.interval = 250;
|
||||||
this.previousText = null;
|
this.previousText = null;
|
||||||
|
this.getClipboard = getClipboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
this.stop();
|
this.stop();
|
||||||
|
|
||||||
// The token below is used as a unique identifier to ensure that a new clipboard monitor
|
// 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.
|
// call will exit early if the reference has changed.
|
||||||
const token = {};
|
const token = {};
|
||||||
const intervalCallback = async () => {
|
const intervalCallback = async () => {
|
||||||
@ -39,7 +40,7 @@ class ClipboardMonitor extends EventDispatcher {
|
|||||||
|
|
||||||
let text = null;
|
let text = null;
|
||||||
try {
|
try {
|
||||||
text = await apiClipboardGet();
|
text = await this.getClipboard();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// NOP
|
// NOP
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* 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 {
|
class DisplaySearch extends Display {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -38,7 +38,7 @@ class DisplaySearch extends Display {
|
|||||||
this.introVisible = true;
|
this.introVisible = true;
|
||||||
this.introAnimationTimer = null;
|
this.introAnimationTimer = null;
|
||||||
|
|
||||||
this.clipboardMonitor = new ClipboardMonitor();
|
this.clipboardMonitor = new ClipboardMonitor({getClipboard: apiClipboardGet});
|
||||||
|
|
||||||
this._onKeyDownIgnoreKeys = new Map([
|
this._onKeyDownIgnoreKeys = new Map([
|
||||||
['ANY_MOD', new Set([
|
['ANY_MOD', new Set([
|
||||||
|
Loading…
Reference in New Issue
Block a user