diff --git a/resources/i18n/pt.json b/resources/i18n/pt.json index ee81b078f..631b11301 100644 --- a/resources/i18n/pt.json +++ b/resources/i18n/pt.json @@ -365,6 +365,7 @@ "shareOriginalFormat": "Compartilhar no formato original", "shareDialogTitle": "Compartilhar %{resource} '%{name}'", "shareBatchDialogTitle": "Compartilhar 1 %{resource} |||| Compartilhar %{smart_count} %{resource}", + "shareCopyToClipboard": "Copie para o clipboard: Ctrl+C, Enter", "shareSuccess": "Link copiado para o clipboard : %{url}", "shareFailure": "Erro ao copiar o link %{url} para o clipboard", "downloadDialogTitle": "Baixar %{resource} '%{name}' (%{size})" @@ -451,4 +452,4 @@ "current_song": "Vai para música atual" } } -} \ No newline at end of file +} diff --git a/ui/src/dialogs/ShareDialog.js b/ui/src/dialogs/ShareDialog.js index bafce383e..05e74c425 100644 --- a/ui/src/dialogs/ShareDialog.js +++ b/ui/src/dialogs/ShareDialog.js @@ -47,21 +47,23 @@ export const ShareDialog = () => { { onSuccess: (res) => { const url = shareUrl(res?.data?.id) - navigator.clipboard - .writeText(url) - .then(() => { - notify('message.shareSuccess', 'info', { url }, false, 0) - }) - .catch((err) => { - notify( - translate('message.shareFailure', { url }) + ': ' + err.message, - { - type: 'warning', - multiLine: true, - duration: 0, - } - ) - }) + if (navigator.clipboard && window.isSecureContext) { + navigator.clipboard + .writeText(url) + .then(() => { + notify('message.shareSuccess', 'info', { url }, false, 0) + }) + .catch((err) => { + notify( + translate('message.shareFailure', { url }) + ': ' + err.message, + { + type: 'warning', + multiLine: true, + duration: 0, + } + ) + }) + } else prompt(translate('message.shareCopyToClipboard'), url) }, onFailure: (error) => notify(translate('ra.page.error') + ': ' + error.message, { diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json index a57cc81b5..96d5842bf 100644 --- a/ui/src/i18n/en.json +++ b/ui/src/i18n/en.json @@ -369,6 +369,7 @@ "shareOriginalFormat": "Share in original format", "shareDialogTitle": "Share %{resource} '%{name}'", "shareBatchDialogTitle": "Share 1 %{resource} |||| Share %{smart_count} %{resource}", + "shareCopyToClipboard": "Copy to clipboard: Ctrl+C, Enter", "shareSuccess": "URL copied to clipboard: %{url}", "shareFailure": "Error copying URL %{url} to clipboard", "downloadDialogTitle": "Download %{resource} '%{name}' (%{size})", diff --git a/ui/src/share/ShareList.js b/ui/src/share/ShareList.js index 35272e29f..d9512c271 100644 --- a/ui/src/share/ShareList.js +++ b/ui/src/share/ShareList.js @@ -29,25 +29,28 @@ const ShareList = (props) => { const handleShare = (r) => (e) => { const url = shareUrl(r?.id) - navigator.clipboard - .writeText(url) - .then(() => { - notify(translate('message.shareSuccess', { url }), { - type: 'info', - multiLine: true, - duration: 0, - }) - }) - .catch((err) => { - notify( - translate('message.shareFailure', { url }) + ': ' + err.message, - { - type: 'warning', + if (navigator.clipboard && window.isSecureContext) { + navigator.clipboard + .writeText(url) + .then(() => { + notify(translate('message.shareSuccess', { url }), { + type: 'info', multiLine: true, duration: 0, - } - ) - }) + }) + }) + .catch((err) => { + notify( + translate('message.shareFailure', { url }) + ': ' + err.message, + { + type: 'warning', + multiLine: true, + duration: 0, + } + ) + }) + } else prompt(translate('message.shareCopyToClipboard'), url) + e.preventDefault() e.stopPropagation() }