From b64c4174784b3e55003cedec08d98e2947fca407 Mon Sep 17 00:00:00 2001 From: Barry Chen Date: Mon, 4 Dec 2017 17:28:16 -0600 Subject: [PATCH] Do not copy while copying. (#3878) --- addon/webextension/selector/shooter.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/addon/webextension/selector/shooter.js b/addon/webextension/selector/shooter.js index c09de2859a..3d3f0741c1 100644 --- a/addon/webextension/selector/shooter.js +++ b/addon/webextension/selector/shooter.js @@ -196,12 +196,30 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars })); }; + let copyInProgress = null; exports.copyShot = function(selectedPos) { + // This is pretty slow. We'll ignore additional user triggered copy events + // while it is in progress. + if (copyInProgress) { + return; + } + // A max of five seconds in case some error occurs. + copyInProgress = setTimeout(() => { + copyInProgress = null; + }, 5000); + + let unsetCopyInProgress = () => { + if (copyInProgress) { + clearTimeout(copyInProgress); + copyInProgress = null; + } + } let dataUrl = screenshotPage(selectedPos); let blob = blobConverters.dataUrlToBlob(dataUrl); catcher.watchPromise(callBackground("copyShotToClipboard", blob).then(() => { uicontrol.deactivate(); - })); + unsetCopyInProgress(); + }, unsetCopyInProgress)); }; exports.sendEvent = function(...args) {