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

Commit

Permalink
removed 'copied' notification if the copy failed
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycoates committed Mar 6, 2017
1 parent 129e80d commit 22a4519
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
17 changes: 16 additions & 1 deletion webextension/background/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* globals chrome, console, XMLHttpRequest, Image, document, setTimeout, navigator */
/* globals loadSelector, analytics, communication, catcher */
/* globals loadSelector, analytics, communication, catcher, makeUuid */
window.main = (function () {
let exports = {};

const pasteSymbol = (window.navigator.platform.match(/Mac/i)) ? "\u2318" : "Ctrl";
const { sendEvent } = analytics;

let manifest = chrome.runtime.getManifest();
Expand Down Expand Up @@ -62,5 +63,19 @@ window.main = (function () {
chrome.tabs.create({url: backend + "/shots"});
});

communication.register("openShot", ({url, copied}) => {
if (copied) {
const id = makeUuid();
chrome.notifications.create(id, {
type: "basic",
iconUrl: "../icons/clipboard-32.png",
title: "Link Copied",
message: "The link to your shot has been copied to the clipboard. Press "
+ pasteSymbol + "-V to paste."
});
}
chrome.tabs.create({url});
});

return exports;
})();
13 changes: 1 addition & 12 deletions webextension/background/takeshot.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* globals communication, shot, main, chrome, makeUuid, clipboard, auth, catcher, analytics */
/* globals communication, shot, main, chrome, auth, catcher, analytics */

window.takeshot = (function () {
let exports = {};
const Shot = shot.AbstractShot;
const { sendEvent } = analytics;
const pasteSymbol =
(window.navigator.platform.match(/Mac/i)) ? "\u2318" : "Ctrl";

communication.register("takeShot", (options) => {
let { captureType, captureText, scroll, selectedPos, shotId, shot } = options;
Expand Down Expand Up @@ -33,15 +31,6 @@ window.takeshot = (function () {
return catcher.watchPromise(capturePromise.then(() => {
return uploadShot(shot);
}).then(() => {
let id = makeUuid();
chrome.notifications.create(id, {
type: "basic",
iconUrl: "../icons/clipboard-32.png",
title: "Link Copied",
message: "The link to your shot has been copied to the clipboard. Press "
+ pasteSymbol + "-V to paste."
});
chrome.tabs.create({url: shot.viewUrl});
return shot.viewUrl;
}));
});
Expand Down
8 changes: 7 additions & 1 deletion webextension/clipboard.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* globals catcher */

window.clipboard = (function () {
let exports = {};

Expand All @@ -6,8 +8,12 @@ window.clipboard = (function () {
document.body.appendChild(el);
el.value = text;
el.select();
document.execCommand("copy");
const copied = document.execCommand("copy");
document.body.removeChild(el);
if (!copied) {
catcher.unhandled(new Error("clipboard copy failed"));
}
return copied;
};

return exports;
Expand Down
3 changes: 2 additions & 1 deletion webextension/selector/shooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ window.shooter = (function () { // eslint-disable-line no-unused-vars
shotId: shot.id,
shot: shot.asJson()
}).then((url) => {
window.clipboard.copy(url);
const copied = window.clipboard.copy(url);
return callBackground("openShot", { url, copied });
}));
exports.deactivate();
};
Expand Down

0 comments on commit 22a4519

Please sign in to comment.