Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Download or copy preview img when possible. (#3968) (#4004)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenba authored and jaredhirsch committed Jan 25, 2018
1 parent 4fae01f commit 6aa2deb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions addon/webextension/selector/shooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars
}));
};

exports.downloadShot = function(selectedPos) {
let dataUrl = screenshotPage(selectedPos);
exports.downloadShot = function(selectedPos, previewDataUrl) {
let dataUrl = previewDataUrl || screenshotPage(selectedPos);
let promise = Promise.resolve(dataUrl);
if (!dataUrl) {
promise = callBackground(
Expand Down Expand Up @@ -195,7 +195,7 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars
};

let copyInProgress = null;
exports.copyShot = function(selectedPos) {
exports.copyShot = function(selectedPos, previewDataUrl) {
// This is pretty slow. We'll ignore additional user triggered copy events
// while it is in progress.
if (copyInProgress) {
Expand All @@ -212,7 +212,7 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars
copyInProgress = null;
}
}
let dataUrl = screenshotPage(selectedPos);
let dataUrl = previewDataUrl || screenshotPage(selectedPos);
let blob = blobConverters.dataUrlToBlob(dataUrl);
catcher.watchPromise(callBackground("copyShotToClipboard", blob).then(() => {
uicontrol.deactivate();
Expand Down
6 changes: 4 additions & 2 deletions addon/webextension/selector/uicontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,15 @@ this.uicontrol = (function() {
sendEvent(`download-${captureType.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()}`, "download-preview-button");
// Downloaded shots don't have dimension limits
removeDimensionLimitsOnFullPageShot();
shooter.downloadShot(selectedPos);
let previewDataUrl = (captureType === "fullPageTruncated") ? null : dataUrl;
shooter.downloadShot(selectedPos, previewDataUrl);
},
onCopyPreview: () => {
sendEvent(`copy-${captureType.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()}`, "copy-preview-button");
// Copied shots don't have dimension limits
removeDimensionLimitsOnFullPageShot();
shooter.copyShot(selectedPos);
let previewDataUrl = (captureType === "fullPageTruncated") ? null : dataUrl;
shooter.copyShot(selectedPos, previewDataUrl);
}
};

Expand Down

0 comments on commit 6aa2deb

Please # to comment.