use async/await for copy to clipboard action

This commit is contained in:
andz-bb 2025-03-07 11:41:39 +00:00
parent 8a11fcfd06
commit 363142414b
1 changed files with 11 additions and 13 deletions

View File

@ -421,7 +421,7 @@ const showNotificationHandler = action => {
const promptUserHandler = () => {} const promptUserHandler = () => {}
const copyToClipboardHandler = action => { const copyToClipboardHandler = async action => {
const { textToCopy, showNotification, notificationMessage } = const { textToCopy, showNotification, notificationMessage } =
action.parameters action.parameters
@ -429,18 +429,16 @@ const copyToClipboardHandler = action => {
return return
} }
navigator.clipboard try {
.writeText(textToCopy) await navigator.clipboard.writeText(textToCopy)
.then(() => { if (showNotification) {
if (showNotification) { const message = notificationMessage || "Copied to clipboard"
const message = notificationMessage || "Copied to clipboard" notificationStore.actions.success(message, true, 3000)
notificationStore.actions.success(message, true, 3000) }
} } catch (err) {
}) console.error("Failed to copy text: ", err)
.catch(err => { notificationStore.actions.error("Failed to copy to clipboard")
console.error("Failed to copy text: ", err) }
notificationStore.actions.error("Failed to copy to clipboard")
})
return { copied: textToCopy } return { copied: textToCopy }
} }