import { clipboard } from '@dcloudio/uni-runtime'; import { SetClipboardData, GetClipboardData, SetClipboardDataOptions, SetClipboardDataSuccess, GetClipboardDataOptions, GetClipboardDataSuccess } from '../interface.uts'; import { API_GET_CLIPBOARD_DATA, API_SET_CLIPBOARD_DATA, SetClipboardDataApiOptions, SetClipboardDataProtocol } from '../protocol.uts'; export { SetClipboardData, GetClipboardData, SetClipboardDataOptions, SetClipboardDataSuccess, GetClipboardDataOptions, GetClipboardDataSuccess } interface ClipboardModuleGetStringOptions { result: string data: string } export const getClipboardData: GetClipboardData = defineAsyncApi( API_GET_CLIPBOARD_DATA, (_: GetClipboardDataOptions, res: ApiExecutor) => { clipboard.getString((ret: ClipboardModuleGetStringOptions) => { if (ret.result === 'success') { res.resolve({ data: ret.data, } as GetClipboardDataSuccess) } else { res.reject('getClipboardData:fail') } }) } ) as GetClipboardData export const setClipboardData: SetClipboardData = defineAsyncApi( API_SET_CLIPBOARD_DATA, (options: SetClipboardDataOptions, res: ApiExecutor) => { clipboard.setString(options.data) res.resolve() }, SetClipboardDataProtocol, SetClipboardDataApiOptions ) as SetClipboardData