Mark fields as private
This commit is contained in:
parent
93aa275d82
commit
ba64f34df1
@ -21,59 +21,59 @@
|
|||||||
class ClipboardMonitor extends EventDispatcher {
|
class ClipboardMonitor extends EventDispatcher {
|
||||||
constructor({getClipboard}) {
|
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;
|
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 this.getClipboard()
|
// 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 () => {
|
||||||
this.timerId = null;
|
this._timerId = null;
|
||||||
|
|
||||||
let text = null;
|
let text = null;
|
||||||
try {
|
try {
|
||||||
text = await this.getClipboard();
|
text = await this._getClipboard();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// NOP
|
// NOP
|
||||||
}
|
}
|
||||||
if (this.timerToken !== token) { return; }
|
if (this._timerToken !== token) { return; }
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof text === 'string' &&
|
typeof text === 'string' &&
|
||||||
(text = text.trim()).length > 0 &&
|
(text = text.trim()).length > 0 &&
|
||||||
text !== this.previousText
|
text !== this._previousText
|
||||||
) {
|
) {
|
||||||
this.previousText = text;
|
this._previousText = text;
|
||||||
if (jpIsStringPartiallyJapanese(text)) {
|
if (jpIsStringPartiallyJapanese(text)) {
|
||||||
this.trigger('change', {text});
|
this.trigger('change', {text});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.timerId = setTimeout(intervalCallback, this.interval);
|
this._timerId = setTimeout(intervalCallback, this._interval);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.timerToken = token;
|
this._timerToken = token;
|
||||||
|
|
||||||
intervalCallback();
|
intervalCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
this.timerToken = null;
|
this._timerToken = null;
|
||||||
if (this.timerId !== null) {
|
if (this._timerId !== null) {
|
||||||
clearTimeout(this.timerId);
|
clearTimeout(this._timerId);
|
||||||
this.timerId = null;
|
this._timerId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setPreviousText(text) {
|
setPreviousText(text) {
|
||||||
this.previousText = text;
|
this._previousText = text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user