codex-proxy / shared /utils /clipboard.ts
icebear0828
refactor: extract startServer() + path abstraction for Electron reuse
4a940a5
raw
history blame
590 Bytes
function fallbackCopy(text: string): boolean {
const ta = document.createElement("textarea");
ta.value = text;
ta.style.cssText = "position:fixed;left:-9999px;opacity:0";
document.body.appendChild(ta);
ta.select();
let ok = false;
try {
ok = document.execCommand("copy");
} catch {}
document.body.removeChild(ta);
return ok;
}
export async function clipboardCopy(text: string): Promise<boolean> {
if (navigator.clipboard?.writeText) {
try {
await navigator.clipboard.writeText(text);
return true;
} catch {}
}
return fallbackCopy(text);
}