1import { paramMock } from "./utils" 2 3export function mockPasteBoard() { 4 const PasteDataMock = { 5 getPrimaryText: function () { 6 console.warn("PasteData.getPrimaryText interface mocked in the Previewer. How this interface works on the" + 7 " Previewer may be different from that on a real device.") 8 return "[PC Preview] unknow primarytext" 9 } 10 } 11 const SystemPasteboardMock = { 12 getPasteData: function (...args) { 13 console.warn("SystemPasteboard.getPasteData interface mocked in the Previewer. How this interface works on the" + 14 " Previewer may be different from that on a real device.") 15 const len = args.length 16 if (typeof args[len - 1] === 'function') { 17 args[len - 1].call(this, paramMock.businessErrorMock, PasteDataMock) 18 } else { 19 return new Promise((resolve, reject) => { 20 resolve(PasteDataMock); 21 }) 22 } 23 }, 24 setPasteData: function (...args) { 25 console.warn("SystemPasteboard.setPasteData interface mocked in the Previewer. How this interface works on the" + 26 " Previewer may be different from that on a real device.") 27 const len = args.length 28 if (typeof args[len - 1] === 'function') { 29 args[len - 1].call(this, paramMock.businessErrorMock); 30 } else { 31 return new Promise((resolve, reject) => { 32 resolve(); 33 }) 34 } 35 } 36 } 37 global.systemplugin.pasteboard = { 38 createPlainTextData: function () { 39 console.warn("pasteboard.createPlainTextData interface mocked in the Previewer. How this interface works on" + 40 " the Previewer may be different from that on a real device.") 41 return PasteDataMock; 42 }, 43 getSystemPasteboard: function () { 44 console.warn("pasteboard.getSystemPasteboard interface mocked in the Previewer. How this interface works on" + 45 " the Previewer may be different from that on a real device.") 46 return SystemPasteboardMock; 47 } 48 } 49} 50