UNPKG

@uni-helper/uni-promises

Version:
481 lines (347 loc) 19.4 kB
var __defProp$3 = Object.defineProperty; var __defProps$3 = Object.defineProperties; var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols; var __hasOwnProp$3 = Object.prototype.hasOwnProperty; var __propIsEnum$3 = Object.prototype.propertyIsEnumerable; var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues$3 = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp$3.call(b, prop)) __defNormalProp$3(a, prop, b[prop]); if (__getOwnPropSymbols$3) for (var prop of __getOwnPropSymbols$3(b)) { if (__propIsEnum$3.call(b, prop)) __defNormalProp$3(a, prop, b[prop]); } return a; }; var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)); function noop() { } function promisify(callback) { return (...args) => { const options = args[0]; return new Promise( (resolve, reject) => { callback(__spreadProps$3(__spreadValues$3({}, options), { success: (result) => { var _a; (_a = options == null ? void 0 : options.success) == null ? void 0 : _a.call(options, result); resolve(result); }, fail: (error) => { var _a; (_a = options == null ? void 0 : options.fail) == null ? void 0 : _a.call(options, error); reject(error); } })); } ); }; } function mountTaskMethodToPromise(task, promise) { if (!task || !promise) return; for (const fn of [ "onHeadersReceived", "offHeadersReceived", "onChunkReceived", "offChunkReceived", "onProgressUpdate", "offProgressUpdate" ]) { if (fn in task) { promise[fn] = task[fn].bind(task); } } promise.abort = () => { task == null ? void 0 : task.abort(); return promise; }; } const addPhoneContact = promisify(uni.addPhoneContact); const authorize = promisify(uni.authorize); const checkIsSoterEnrolledInDevice = promisify(uni.checkIsSoterEnrolledInDevice); const checkIsSupportSoterAuthentication = promisify(uni.checkIsSupportSoterAuthentication); const checkSession = promisify(uni.checkSession); const chooseAddress = promisify(uni.chooseAddress); const chooseFile = promisify(uni.chooseFile); const chooseImage = promisify(uni.chooseImage); const chooseInvoice = promisify(uni.chooseInvoice); const chooseInvoiceTitle = promisify(uni.chooseInvoiceTitle); const chooseLocation = promisify(uni.chooseLocation); const chooseMedia = promisify(uni.chooseMedia); const chooseMessageFile = promisify(uni.chooseMessageFile); const chooseVideo = promisify(uni.chooseVideo); const clearStorage = promisify(uni.clearStorage); const closeBLEConnection = promisify(uni.closeBLEConnection); const closeBluetoothAdapter = promisify(uni.closeBluetoothAdapter); const closePreviewImage = promisify(uni.closePreviewImage); const closeSocket = () => promisify(uni.closeSocket); const compressImage = promisify(uni.compressImage); const compressVideo = promisify(uni.compressVideo); const connectSocket = () => promisify(uni.connectSocket); const createBLEConnection = promisify(uni.createBLEConnection); const createCameraContext = () => uni.createCameraContext(); const createCanvasContext = (canvasId, componentInstance) => uni.createCanvasContext(canvasId, componentInstance); const createInnerAudioContext = () => uni.createInnerAudioContext(); const createLivePlayerContext = (livePlayerId, componentInstance) => uni.createLivePlayerContext(livePlayerId, componentInstance); const createLivePusherContext = (livePusherId, componentInstance) => uni.createLivePusherContext(livePusherId, componentInstance); const createMapContext = (mapId, componentInstance) => { return new Promise((resolve, reject) => { try { const context = uni.createMapContext(mapId, componentInstance); context.getCenterLocation = promisify(context.getCenterLocation.bind(context)); context.moveToLocation = promisify(context.moveToLocation.bind(context)); context.translateMarker = promisify(context.translateMarker.bind(context)); context.includePoints = promisify(context.includePoints.bind(context)); context.getRegion = promisify(context.getRegion.bind(context)); context.getScale = promisify(context.getScale.bind(context)); context.addCustomLayer = promisify(context.addCustomLayer.bind(context)); context.addGroundOverlay = promisify(context.addGroundOverlay.bind(context)); context.addMarkers = promisify(context.addMarkers.bind(context)); context.fromScreenLocation = promisify(context.fromScreenLocation.bind(context)); context.initMarkerCluster = promisify(context.initMarkerCluster.bind(context)); context.moveAlong = promisify(context.moveAlong.bind(context)); context.openMapApp = promisify(context.openMapApp.bind(context)); context.removeCustomLayer = promisify(context.removeCustomLayer.bind(context)); context.removeGroundOverlay = promisify(context.removeGroundOverlay.bind(context)); context.removeMarkers = promisify(context.removeMarkers.bind(context)); context.setCenterOffset = promisify(context.setCenterOffset.bind(context)); context.toScreenLocation = promisify(context.toScreenLocation.bind(context)); context.updateGroundOverlay = promisify(context.updateGroundOverlay.bind(context)); resolve(context); } catch (error) { reject(error); } }); }; const createMediaContainer = () => uni.createMediaContainer(); const createPushMessage = promisify(uni.createPushMessage); const createSelectorQuery = () => uni.createSelectorQuery(); const createVideoContext = (videoId, componentInstance) => uni.createVideoContext(videoId, componentInstance); var __defProp$2 = Object.defineProperty; var __defProps$2 = Object.defineProperties; var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols; var __hasOwnProp$2 = Object.prototype.hasOwnProperty; var __propIsEnum$2 = Object.prototype.propertyIsEnumerable; var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues$2 = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp$2.call(b, prop)) __defNormalProp$2(a, prop, b[prop]); if (__getOwnPropSymbols$2) for (var prop of __getOwnPropSymbols$2(b)) { if (__propIsEnum$2.call(b, prop)) __defNormalProp$2(a, prop, b[prop]); } return a; }; var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b)); function downloadFile(urlOrOptions, options) { var _a, _b, _c; const _options = typeof urlOrOptions === "string" ? __spreadProps$2(__spreadValues$2({}, options), { url: urlOrOptions, complete: (_a = options == null ? void 0 : options.complete) != null ? _a : noop }) : __spreadProps$2(__spreadValues$2(__spreadValues$2({}, urlOrOptions), options), { complete: (_c = (_b = urlOrOptions == null ? void 0 : urlOrOptions.complete) != null ? _b : options == null ? void 0 : options.complete) != null ? _c : noop }); const { success, fail } = _options; let task; const promise = new Promise((resolve, reject) => { _options.success = (r) => { success == null ? void 0 : success(r); resolve(r); }; _options.fail = (e) => { fail == null ? void 0 : fail(e); reject(e); }; task = uni.downloadFile(_options); }); mountTaskMethodToPromise(task, promise); return promise; } const _getApp = () => new Promise((resolve, reject) => { try { const app = getApp(); resolve(app); } catch (error) { reject(error); } }); const getBackgroundAudioManager = () => uni.getBackgroundAudioManager(); const getBatteryInfo = promisify(uni.getBatteryInfo); const getBLEDeviceCharacteristics = promisify(uni.getBLEDeviceCharacteristics); const getBLEDeviceRSSI = promisify(uni.getBLEDeviceRSSI); const getBLEDeviceServices = promisify(uni.getBLEDeviceServices); const getBluetoothAdapterState = promisify(uni.getBluetoothAdapterState); const getBluetoothDevices = promisify(uni.getBluetoothDevices); const getCheckBoxState = promisify(uni.getCheckBoxState); const getClipboardData = promisify(uni.getClipboardData); const getConnectedBluetoothDevices = promisify(uni.getConnectedBluetoothDevices); const getExtConfig = promisify(uni.getExtConfig); const getFileInfo = promisify(uni.getFileInfo); const getImageInfo = promisify(uni.getImageInfo); const getLocation = promisify(uni.getLocation); const getNetworkType = promisify(uni.getNetworkType); const getProvider = promisify(uni.getProvider); const getPushClientId = promisify(uni.getPushClientId); const getRecordManager = () => uni.getRecorderManager(); const getSavedFileInfo = promisify(uni.getSavedFileInfo); const getSavedFileList = promisify(uni.getSavedFileList); const getScreenBrightness = promisify(uni.getScreenBrightness); const getSelectedTextRange = promisify(uni.getSelectedTextRange); const getSetting = promisify(uni.getSetting); const getStorage = promisify(uni.getStorage); const getStorageInfo = promisify(uni.getStorageInfo); const getSystemInfo = promisify(uni.getSystemInfo); const getUserInfo = promisify(uni.getUserInfo); const getUserProfile = promisify(uni.getUserProfile); const getVideoInfo = promisify(uni.getVideoInfo); const hideHomeButton = promisify(uni.hideHomeButton); const hideNavigationBarLoading = promisify(uni.hideNavigationBarLoading); const hideShareMenu = promisify(uni.hideShareMenu); const hideTabBar = promisify(uni.hideTabBar); const hideTabBarRedDot = promisify(uni.hideTabBarRedDot); const loadFontFace = promisify(uni.loadFontFace); const login = promisify(uni.login); const makePhoneCall = promisify(uni.makePhoneCall); const navigateBack = promisify(uni.navigateBack); const navigateBackMiniProgram = promisify(uni.navigateBackMiniProgram); const navigateTo = promisify(uni.navigateTo); const navigateToMiniProgram = promisify(uni.navigateToMiniProgram); const notifyBLECharacteristicValueChange = promisify(uni.notifyBLECharacteristicValueChange); const openAppAuthorizeSetting = promisify(uni.openAppAuthorizeSetting); const openBluetoothAdapter = promisify(uni.openBluetoothAdapter); const openDocument = promisify(uni.openDocument); const openLocation = promisify(uni.openLocation); const openVideoEditor = promisify(uni.openVideoEditor); const pageScrollTo = promisify(uni.pageScrollTo); const preLogin = promisify(uni.preLogin); const previewImage = promisify(uni.previewImage); const readBLECharacteristicValue = promisify(uni.readBLECharacteristicValue); const redirectTo = promisify(uni.redirectTo); const reLaunch = promisify(uni.reLaunch); const removeSavedFile = promisify(uni.removeSavedFile); const removeStorage = promisify(uni.removeStorage); const removeTabBarBadge = promisify(uni.removeTabBarBadge); var __defProp$1 = Object.defineProperty; var __defProps$1 = Object.defineProperties; var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols; var __hasOwnProp$1 = Object.prototype.hasOwnProperty; var __propIsEnum$1 = Object.prototype.propertyIsEnumerable; var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues$1 = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp$1.call(b, prop)) __defNormalProp$1(a, prop, b[prop]); if (__getOwnPropSymbols$1) for (var prop of __getOwnPropSymbols$1(b)) { if (__propIsEnum$1.call(b, prop)) __defNormalProp$1(a, prop, b[prop]); } return a; }; var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b)); function request(urlOrOptions, options) { var _a, _b, _c; const _options = typeof urlOrOptions === "string" ? __spreadProps$1(__spreadValues$1({}, options), { url: urlOrOptions, complete: (_a = options == null ? void 0 : options.complete) != null ? _a : noop }) : __spreadProps$1(__spreadValues$1(__spreadValues$1({}, urlOrOptions), options), { complete: (_c = (_b = urlOrOptions == null ? void 0 : urlOrOptions.complete) != null ? _b : options == null ? void 0 : options.complete) != null ? _c : noop }); const { success, fail } = _options; let task; const promise = new Promise((resolve, reject) => { _options.success = (r) => { success == null ? void 0 : success(r); resolve(r); }; _options.fail = (e) => { fail == null ? void 0 : fail(e); reject(e); }; task = uni.request(_options); }); mountTaskMethodToPromise(task, promise); return promise; } const requestPayment = promisify(uni.requestPayment); const requestSubscribeMessage = promisify(uni.requestSubscribeMessage); const saveFile = promisify(uni.saveFile); const saveImageToPhotosAlbum = promisify(uni.saveImageToPhotosAlbum); const saveVideoToPhotosAlbum = promisify(uni.saveVideoToPhotosAlbum); const scanCode = promisify(uni.scanCode); const sendSocketMessage = () => promisify(uni.sendSocketMessage); const setBackgroundColor = promisify(uni.setBackgroundColor); const setBackgroundTextStyle = promisify(uni.setBackgroundTextStyle); const setBLEMTU = promisify(uni.setBLEMTU); const setClipboardData = promisify(uni.setClipboardData); const setEnableDebug = promisify(uni.setEnableDebug); const setKeepScreenOn = promisify(uni.setKeepScreenOn); const setNavigationBarColor = promisify(uni.setNavigationBarColor); const setNavigationBarTitle = promisify(uni.setNavigationBarTitle); const setScreenBrightness = promisify(uni.setScreenBrightness); const setStorage = promisify(uni.setStorage); const setTabBarBadge = promisify(uni.setTabBarBadge); const setTabBarItem = promisify(uni.setTabBarItem); const setTabBarStyle = promisify(uni.setTabBarStyle); const share = promisify(uni.share); const shareWithSystem = promisify(uni.shareWithSystem); const showActionSheet = promisify(uni.showActionSheet); const showLoading = promisify(uni.showLoading); const showModal = promisify(uni.showModal); const showNavigationBarLoading = promisify(uni.showNavigationBarLoading); const showShareMenu = promisify(uni.showShareMenu); const showTabBar = promisify(uni.showTabBar); const showTabBarRedDot = promisify(uni.showTabBarRedDot); const showToast = promisify(uni.showToast); const startBluetoothDevicesDiscovery = promisify(uni.startBluetoothDevicesDiscovery); const startPullDownRefresh = promisify(uni.startPullDownRefresh); const startSoterAuthentication = promisify(uni.startSoterAuthentication); const stopBluetoothDevicesDiscovery = promisify(uni.stopBluetoothDevicesDiscovery); const switchTab = promisify(uni.switchTab); var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); function uploadFile(urlOrOptions, options) { var _a, _b, _c; const _options = typeof urlOrOptions === "string" ? __spreadProps(__spreadValues({}, options), { url: urlOrOptions, complete: (_a = options == null ? void 0 : options.complete) != null ? _a : noop }) : __spreadProps(__spreadValues(__spreadValues({}, urlOrOptions), options), { complete: (_c = (_b = urlOrOptions == null ? void 0 : urlOrOptions.complete) != null ? _b : options == null ? void 0 : options.complete) != null ? _c : noop }); const { success, fail } = _options; let task; const promise = new Promise((resolve, reject) => { _options.success = (r) => { success == null ? void 0 : success(r); resolve(r); }; _options.fail = (e) => { fail == null ? void 0 : fail(e); reject(e); }; task = uni.uploadFile(_options); }); mountTaskMethodToPromise(task, promise); return promise; } const vibrate = promisify(uni.vibrate); const vibrateLong = promisify(uni.vibrateLong); const vibrateShort = promisify(uni.vibrateShort); const writeBLECharacteristicValue = promisify(uni.writeBLECharacteristicValue); export { addPhoneContact, authorize, checkIsSoterEnrolledInDevice, checkIsSupportSoterAuthentication, checkSession, chooseAddress, chooseFile, chooseImage, chooseInvoice, chooseInvoiceTitle, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, clearStorage, closeBLEConnection, closeBluetoothAdapter, closePreviewImage, closeSocket, compressImage, compressVideo, connectSocket, createBLEConnection, createCameraContext, createCanvasContext, createInnerAudioContext, createLivePlayerContext, createLivePusherContext, createMapContext, createMediaContainer, createPushMessage, createSelectorQuery, createVideoContext, downloadFile, _getApp as getApp, getBLEDeviceCharacteristics, getBLEDeviceRSSI, getBLEDeviceServices, getBackgroundAudioManager, getBatteryInfo, getBluetoothAdapterState, getBluetoothDevices, getCheckBoxState, getClipboardData, getConnectedBluetoothDevices, getExtConfig, getFileInfo, getImageInfo, getLocation, getNetworkType, getProvider, getPushClientId, getRecordManager, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange, getSetting, getStorage, getStorageInfo, getSystemInfo, getUserInfo, getUserProfile, getVideoInfo, hideHomeButton, hideNavigationBarLoading, hideShareMenu, hideTabBar, hideTabBarRedDot, loadFontFace, login, makePhoneCall, mountTaskMethodToPromise, navigateBack, navigateBackMiniProgram, navigateTo, navigateToMiniProgram, noop, notifyBLECharacteristicValueChange, openAppAuthorizeSetting, openBluetoothAdapter, openDocument, openLocation, openVideoEditor, pageScrollTo, preLogin, previewImage, promisify, reLaunch, readBLECharacteristicValue, redirectTo, removeSavedFile, removeStorage, removeTabBarBadge, request, requestPayment, requestSubscribeMessage, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setBLEMTU, setBackgroundColor, setBackgroundTextStyle, setClipboardData, setEnableDebug, setKeepScreenOn, setNavigationBarColor, setNavigationBarTitle, setScreenBrightness, setStorage, setTabBarBadge, setTabBarItem, setTabBarStyle, share, shareWithSystem, showActionSheet, showLoading, showModal, showNavigationBarLoading, showShareMenu, showTabBar, showTabBarRedDot, showToast, startBluetoothDevicesDiscovery, startPullDownRefresh, startSoterAuthentication, stopBluetoothDevicesDiscovery, switchTab, uploadFile, vibrate, vibrateLong, vibrateShort, writeBLECharacteristicValue };