Skip to content

Commit

Permalink
fix: make copy to clipboard work in non-https environments (#242)
Browse files Browse the repository at this point in the history
Fixes #56 

Tested on a local domain.
  • Loading branch information
im-adithya authored Jul 10, 2024
2 parents 894c2c3 + fe24b2c commit 0a8100a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
15 changes: 4 additions & 11 deletions frontend/src/lib/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ export async function copyToClipboard(content: string) {
textArea.style.position = "absolute";
textArea.style.opacity = "0";
document.body.appendChild(textArea);
selectElement(textArea);
textArea.focus();
textArea.select();

if (document.execCommand("copy")) {
resolve(content);
} else {
reject();
}

textArea.remove();
}
});
Expand All @@ -31,13 +34,3 @@ export async function copyToClipboard(content: string) {
});
}
}

function selectElement(element: Element) {
const selection = window.getSelection();
if (selection) {
selection.removeAllRanges();
const range = document.createRange();
range.selectNode(element);
selection.addRange(range);
}
}
1 change: 0 additions & 1 deletion frontend/src/screens/apps/AppCreated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default function AppCreated() {
const queryParams = new URLSearchParams(search);
const appId = queryParams.get("app") ?? "";
const appstoreApp = suggestedApps.find((app) => app.id === appId);
console.info(appstoreApp, appId);

const [timeout, setTimeout] = useState(false);
const [isQRCodeVisible, setIsQRCodeVisible] = useState(false);
Expand Down

0 comments on commit 0a8100a

Please sign in to comment.