Files
agent-desktop/console/src/utils/clipboard.ts
T
Pine 9b30f681c6 feat: 智能体控制台前端(console)
- React+antd+zustand,注册表驱动路由/菜单/权限
- Tauri 桌面壳、后端托管 SPA、跨标签页消息队列
2026-08-23 22:43:18 +08:00

28 lines
731 B
TypeScript

/** Copy text to clipboard with fallback for non-secure contexts. */
export async function copyText(text: string): Promise<void> {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(text);
return;
}
const textarea = document.createElement("textarea");
textarea.value = text;
textarea.setAttribute("readonly", "");
textarea.style.position = "absolute";
textarea.style.left = "-9999px";
document.body.appendChild(textarea);
let copied = false;
try {
textarea.focus();
textarea.select();
copied = document.execCommand("copy");
} finally {
document.body.removeChild(textarea);
}
if (!copied) {
throw new Error("Failed to copy text");
}
}