1
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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('')
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user