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