36 lines
973 B
Plaintext
36 lines
973 B
Plaintext
import { BusinessError, pasteboard } from '@kit.BasicServicesKit';
|
|
|
|
|
|
export const setClipboardData = (data : string) : Promise<boolean> => {
|
|
let pasteData : pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, data);
|
|
let systemPasteboard : pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
|
|
return new Promise((res, rej) => {
|
|
|
|
systemPasteboard.setData(pasteData).then(() => {
|
|
console.info("成功")
|
|
res(true)
|
|
})
|
|
.catch((e) => {
|
|
const err = e as BusinessError
|
|
console.error(err.message)
|
|
rej(false)
|
|
})
|
|
})
|
|
|
|
}
|
|
|
|
export const getClipboardData = () : Promise<string> => {
|
|
let systemPasteboard : pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
|
|
// return new Promise((res, rej) => {
|
|
// systemPasteboard.getData((err, data) => {
|
|
// if (err) {
|
|
// console.error(err.message)
|
|
// return rej(err.message);
|
|
// }
|
|
// res(data.getPrimaryText())
|
|
// })
|
|
// })
|
|
|
|
return Promise.resolve('')
|
|
|
|
} |