From fe24b2c716e3230a80e247877c9a0ec18cb826fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Wed, 10 Jul 2024 10:21:17 +0200 Subject: [PATCH] fix: make copy to clipboard work in non-https environments --- frontend/src/lib/clipboard.ts | 15 ++++----------- frontend/src/screens/apps/AppCreated.tsx | 1 - 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/frontend/src/lib/clipboard.ts b/frontend/src/lib/clipboard.ts index a35baa50..b7f16bdb 100644 --- a/frontend/src/lib/clipboard.ts +++ b/frontend/src/lib/clipboard.ts @@ -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(); } }); @@ -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); - } -} diff --git a/frontend/src/screens/apps/AppCreated.tsx b/frontend/src/screens/apps/AppCreated.tsx index 44bd88eb..e03e494d 100644 --- a/frontend/src/screens/apps/AppCreated.tsx +++ b/frontend/src/screens/apps/AppCreated.tsx @@ -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);