Skip to content

Commit

Permalink
improve code to copy image
Browse files Browse the repository at this point in the history
  • Loading branch information
hatemhosny committed Jan 10, 2025
1 parent de60e72 commit 022592a
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/livecodes/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,13 @@ export const copyImage = /* @__PURE__ */ async (image: Blob, type: 'png' | 'jpg'
};
try {
if ('write' in navigator.clipboard) {
await navigator.clipboard.write([
new ClipboardItem({
[mimeTypes[type]]: new Promise(async (resolve) => {
resolve(image);
}),
}),
]);
await navigator.clipboard.write([new ClipboardItem({ [mimeTypes[type]]: image })]);
return true;
} else {
return false;
}
} catch (err) {
return false;
// proceed to return false
}
return false;
};

export const stringToValidJson = /* @__PURE__ */ (str: string) =>
Expand Down

0 comments on commit 022592a

Please sign in to comment.