From 07413513185ddb3bcc7094f290f8329167c275b6 Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Thu, 19 Feb 2026 19:55:10 -0800 Subject: [PATCH] fix(share): only copy to clipboard if available and secure --- src/i18n/locales/en.json | 2 ++ .../components/share-item-context-modal.tsx | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 5b9df0682..cef04ee90 100755 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -391,9 +391,11 @@ }, "shareItem": { "allowDownloading": "allow downloading", + "copyToClipboard": "Copy to clipboard: Ctrl+C, Enter", "description": "description", "setExpiration": "set expiration", "success": "share link copied to clipboard (or click here to open)", + "successMustClick": "share created successfully. click here to open", "expireInvalid": "expiration must be in the future", "createFailed": "failed to create share (is sharing enabled?)" }, diff --git a/src/renderer/features/sharing/components/share-item-context-modal.tsx b/src/renderer/features/sharing/components/share-item-context-modal.tsx index 59697576c..74d3be4a1 100644 --- a/src/renderer/features/sharing/components/share-item-context-modal.tsx +++ b/src/renderer/features/sharing/components/share-item-context-modal.tsx @@ -74,13 +74,22 @@ export const ShareItemContextModal = ({ if (!serverUrl) throw new Error('Server URL not found'); const shareUrl = `${serverUrl}/share/${_data.id}`; - navigator.clipboard.writeText(shareUrl); + const canUseClipboard = navigator.clipboard && window.isSecureContext; + if (canUseClipboard) { + navigator.clipboard.writeText(shareUrl); + } + toast.success({ - autoClose: 5000, + autoClose: canUseClipboard ? 5000 : 15000, id: 'share-item-toast', - message: t('form.shareItem.success', { - postProcess: 'sentenceCase', - }), + message: t( + canUseClipboard + ? 'form.shareItem.success' + : 'form.shareItem.successMustClick', + { + postProcess: 'sentenceCase', + }, + ), onClick: (a) => { if (!(a.target instanceof HTMLElement)) return;