catch paste errors

This commit is contained in:
Paul Miller
2023-06-16 16:29:20 -05:00
committed by Tony Giorgio
parent 97d9d9969e
commit 81d45874fd
3 changed files with 15 additions and 14 deletions

View File

@@ -74,10 +74,13 @@ export default function Scanner() {
history.back();
}
function handlePaste() {
navigator.clipboard.readText().then((text) => {
async function handlePaste() {
try {
const text = await navigator.clipboard.readText();
setScanResult(text);
});
} catch (e) {
console.error(e);
}
}
onMount(async () => {

View File

@@ -358,19 +358,17 @@ export default function Send() {
parsePaste(text);
}
function handlePaste() {
async function handlePaste() {
if (!navigator.clipboard.readText)
return showToast(new Error("Clipboard not supported"));
navigator.clipboard
.readText()
.then((text) => {
setFieldDestination(text);
parsePaste(text);
})
.catch((e) => {
showToast(new Error("Failed to read clipboard: " + e.message));
});
try {
const text = await navigator.clipboard.readText();
setFieldDestination(text);
parsePaste(text);
} catch (e) {
console.error(e);
}
}
async function processContacts(

View File

@@ -10,7 +10,7 @@ export const useCopy = ({ copiedTimeout = 2000 }: UseCopyProps = {}): [
copied: Accessor<boolean>
] => {
const [copied, setCopied] = createSignal(false);
let timeout: NodeJS.Timeout;
let timeout: number;
const copy: CopyFn = async (text) => {
await navigator.clipboard.writeText(text);
setCopied(true);