From 0af55366f1443e66ad1e74852af9ee0ebaf47165 Mon Sep 17 00:00:00 2001 From: yiqiuzheng Date: Wed, 5 Apr 2023 02:49:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(utils):=20=E4=BF=AE=E5=A4=8D=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/utils.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/app/utils.ts b/app/utils.ts index 5fe277c6..81f3d24b 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -6,17 +6,23 @@ export function trimTopic(topic: string) { } export async function copyToClipboard(text: string) { - try { - await navigator.clipboard.writeText(text); - } catch (error) { - const textarea = document.createElement("textarea"); - textarea.value = text; - document.body.appendChild(textarea); - textarea.select(); - document.execCommand("copy"); - document.body.removeChild(textarea); - } finally { - showToast(Locale.Copy.Success); + if (navigator.clipboard) { + navigator.clipboard.writeText(text).catch(err => { + console.error('Failed to copy: ', err); + }); + } else { + const textArea = document.createElement('textarea'); + textArea.value = text; + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + try { + document.execCommand('copy'); + console.log('Text copied to clipboard'); + } catch (err) { + console.error('Failed to copy: ', err); + } + document.body.removeChild(textArea); } }