mirror of
https://github.com/idanoo/autobrr
synced 2025-07-26 02:09:13 +00:00
fix(filters): export not working with Safari (#1505)
* fix(filters): export not working with Safari * speculative fix for safari --------- Co-authored-by: s0up4200 <s0up4200@pm.me>
This commit is contained in:
parent
9d08f149b4
commit
d558db231c
2 changed files with 44 additions and 53 deletions
|
@ -152,3 +152,39 @@ export const RandomLinuxIsos = (count: number) => {
|
|||
|
||||
return Array.from({ length: count }, () => linuxIsos[Math.floor(Math.random() * linuxIsos.length)]);
|
||||
};
|
||||
|
||||
export async function CopyTextToClipboard(text: string) {
|
||||
if ("clipboard" in navigator) {
|
||||
// Safari requires clipboard operations to be directly triggered by a user interaction.
|
||||
// Using setTimeout with a delay of 0 ensures the clipboard operation is deferred until
|
||||
// after the current call stack has cleared, effectively placing it outside of the
|
||||
// immediate execution context of the user interaction event. This workaround allows
|
||||
// the clipboard operation to bypass Safari's security restrictions.
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
console.log("Text copied to clipboard successfully.");
|
||||
} catch (err) {
|
||||
console.error("Copy to clipboard unsuccessful: ", err);
|
||||
}
|
||||
}, 0);
|
||||
} else {
|
||||
// fallback for browsers that do not support the Clipboard API
|
||||
copyTextToClipboardFallback(text);
|
||||
}
|
||||
}
|
||||
|
||||
function copyTextToClipboardFallback(text: string) {
|
||||
const textarea = document.createElement("textarea");
|
||||
textarea.value = text;
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
console.log("Text copied to clipboard successfully.");
|
||||
} catch (err) {
|
||||
console.error('Failed to copy text using fallback method: ', err);
|
||||
}
|
||||
document.body.removeChild(textarea);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue