Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): improve error handling if unable to copy to clipboard

Elian Doranac0f6662a6f7
diff --git a/apps/client/src/services/clipboard.ts b/apps/client/src/services/clipboard.ts
index af898e296d..73bce475ff 100644
--- a/apps/client/src/services/clipboard.ts
+++ b/apps/client/src/services/clipboard.ts
@@ -114,12 +114,20 @@ export function copyText(text: string) {
return;
}
+ let succeeded = false;
+
try {
if (navigator.clipboard) {
navigator.clipboard.writeText(text);
- toast.showMessage(t("code_block.copy_success"));
+ succeeded = true;
}
} catch (e) {
+ succeeded = false;
+ }
+
+ if (succeeded) {
+ toast.showMessage(t("code_block.copy_success"));
+ } else {
toast.showError(t("code_block.copy_failed"));
}
}