import { pasteboard } from '@kit.BasicServicesKit';


export function copyText(text: string, copyResult?: (data?: pasteboard.PasteData, err?: Error) => void) {
  const pasteboardData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, text);
  const systemPasteboard = pasteboard.getSystemPasteboard();
  systemPasteboard.setData(pasteboardData); // 将数据放入剪切板
  systemPasteboard.getData()
    .then((data) => {
      copyResult?.(data)
    })
    .catch((e: Error) => {
      copyResult?.(undefined, e)
    })
}