fix: safari copy link issue

This commit is contained in:
Timothy J. Baek 2024-04-19 06:34:55 -05:00
parent b67f80f7a4
commit a4083f43cb
3 changed files with 33 additions and 49 deletions

View file

@ -187,7 +187,8 @@ export const generateInitialsImage = (name) => {
return canvas.toDataURL();
};
export const copyToClipboard = (text) => {
export const copyToClipboard = async (text) => {
let result = false;
if (!navigator.clipboard) {
const textArea = document.createElement('textarea');
textArea.value = text;
@ -205,21 +206,27 @@ export const copyToClipboard = (text) => {
const successful = document.execCommand('copy');
const msg = successful ? 'successful' : 'unsuccessful';
console.log('Fallback: Copying text command was ' + msg);
result = true;
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
}
document.body.removeChild(textArea);
return;
return result;
}
navigator.clipboard.writeText(text).then(
function () {
result = await navigator.clipboard
.writeText(text)
.then(() => {
console.log('Async: Copying to clipboard was successful!');
},
function (err) {
console.error('Async: Could not copy text: ', err);
}
);
return true;
})
.catch((error) => {
console.error('Async: Could not copy text: ', error);
return false;
});
return result;
};
export const compareVersion = (latest, current) => {