diff --git a/.github/workflows/build-webview-bridge.yml b/.github/workflows/build-webview-bridge.yml new file mode 100644 index 0000000000..a2cacab180 --- /dev/null +++ b/.github/workflows/build-webview-bridge.yml @@ -0,0 +1,41 @@ +name: build-webview-bridge + +on: + pull_request: + paths: + - 'packages/webview-bridge/src/**' + - 'packages/webview-bridge/build/**' + - 'packages/webview-bridge/package.json' + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + working-directory: packages/webview-bridge + run: npm install + + - name: Build webview-bridge + working-directory: packages/webview-bridge + run: node build/build.js + + - name: Commit if changed + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add packages/webview-bridge/dist/ + git add examples/mpx-webview/H5/webviewbridge.min.js + if git diff --cached --quiet; then + echo "dist is already up-to-date, nothing to commit" + else + git commit -m "chore: auto-build webview-bridge dist" + git push origin HEAD:${{ github.head_ref }} + fi diff --git a/.github/workflows/gen-api-dynamic.yml b/.github/workflows/gen-api-dynamic.yml new file mode 100644 index 0000000000..e9b26496f9 --- /dev/null +++ b/.github/workflows/gen-api-dynamic.yml @@ -0,0 +1,34 @@ +name: gen-dynamic + +on: + pull_request: + paths: + - 'packages/api-proxy/src/platform/**' + - 'packages/api-proxy/scripts/gen-dynamic.js' + workflow_dispatch: + +jobs: + generate: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Generate dynamic.js + run: node packages/api-proxy/scripts/gen-dynamic.js + + - name: Commit if changed + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add packages/api-proxy/src/common/js/dynamic.js + if git diff --cached --quiet; then + echo "dynamic.js is already up-to-date, nothing to commit" + else + git commit -m "chore: auto-generate dynamic.js" + git push origin HEAD:${{ github.head_ref }} + fi diff --git a/packages/api-proxy/package.json b/packages/api-proxy/package.json index 39d3e247d2..b2af5dae0a 100644 --- a/packages/api-proxy/package.json +++ b/packages/api-proxy/package.json @@ -8,7 +8,8 @@ "*.styl" ], "scripts": { - "test": "jest" + "test": "jest", + "gen:dynamic": "node scripts/gen-dynamic.js" }, "files": [ "src", diff --git a/packages/api-proxy/scripts/gen-dynamic.js b/packages/api-proxy/scripts/gen-dynamic.js new file mode 100644 index 0000000000..ef3d816374 --- /dev/null +++ b/packages/api-proxy/scripts/gen-dynamic.js @@ -0,0 +1,106 @@ +#!/usr/bin/env node +/** + * Scans all exported methods from src/platform/api and generates + * src/common/js/dynamic.js with lazy-loading require() wrappers. + * + * Run: node scripts/gen-dynamic.js + */ + +const fs = require('fs') +const path = require('path') + +const srcDir = path.resolve(__dirname, '../src') +const platformIndexPath = path.join(srcDir, 'platform/index.js') +const outputPath = path.join(srcDir, 'common/js/dynamic.js') +const commonJsDir = path.join(srcDir, 'common/js') + +if (!fs.existsSync(platformIndexPath)) { + console.error('platform/index.js not found:', platformIndexPath) + process.exit(1) +} + +const platformContent = fs.readFileSync(platformIndexPath, 'utf-8') + +// Extract all "export * from './api/xxx'" paths +const exportMatches = [...platformContent.matchAll(/export \* from '(.+?)'/g)] + +if (exportMatches.length === 0) { + console.error('No export * from entries found in platform/index.js') + process.exit(1) +} + +// name -> requirePath (relative to common/js/) +const apiEntries = [] +const seenNames = new Set() + +for (const [, relPath] of exportMatches) { + // relPath is like './api/system' or './api/device/network' + const apiDir = path.join(srcDir, 'platform', relPath) + + let indexFilePath = path.join(apiDir, 'index.js') + if (!fs.existsSync(indexFilePath)) { + // fallback: relPath might point directly to a .js file + indexFilePath = apiDir + '.js' + if (!fs.existsSync(indexFilePath)) { + console.warn(' [skip] index.js not found for:', relPath) + continue + } + } + + const content = fs.readFileSync(indexFilePath, 'utf-8') + + // Match all export { name1, name2, ... } blocks (may span multiple lines) + const exportBlockRegex = /export\s*\{([^}]+)\}/g + let blockMatch + while ((blockMatch = exportBlockRegex.exec(content)) !== null) { + const names = blockMatch[1] + .split(',') + .map(n => { + // Handle "localName as exportedName" — take the exported name + const parts = n.trim().split(/\s+as\s+/) + return (parts[1] || parts[0]).trim() + }) + .filter(n => n && /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(n)) + + // require path: relative from common/js/ to the api dir's index (no .js extension) + const requireTarget = path.join(apiDir, 'index') + let requirePath = path.relative(commonJsDir, requireTarget).replace(/\\/g, '/') + if (!requirePath.startsWith('.')) requirePath = './' + requirePath + + for (const name of names) { + if (seenNames.has(name)) { + console.warn(' [dup] skipping duplicate export:', name) + continue + } + seenNames.add(name) + apiEntries.push({ name, requirePath }) + } + } +} + +if (apiEntries.length === 0) { + console.error('No exported names found — aborting to avoid writing an empty file') + process.exit(1) +} + +// Build dynamic.js content +const methodLines = apiEntries.map(({ name, requirePath }, i) => { + const comma = i < apiEntries.length - 1 ? ',' : '' + return [ + ` ${name} (...args) {`, + ` const ${name} = require('${requirePath}').${name}`, + ` return ${name}(...args)`, + ` }${comma}` + ].join('\n') +}) + +const output = [ + '// This file is auto-generated by scripts/gen-dynamic.js — do not edit manually', + 'export default {', + methodLines.join('\n'), + '}', + '' +].join('\n') + +fs.writeFileSync(outputPath, output, 'utf-8') +console.log(`Generated ${path.relative(process.cwd(), outputPath)} with ${apiEntries.length} methods`) diff --git a/packages/api-proxy/src/common/js/dynamic.js b/packages/api-proxy/src/common/js/dynamic.js new file mode 100644 index 0000000000..9817b40b88 --- /dev/null +++ b/packages/api-proxy/src/common/js/dynamic.js @@ -0,0 +1,523 @@ +// This file is auto-generated by scripts/gen-dynamic.js — do not edit manually +export default { + showActionSheet (...args) { + const showActionSheet = require('../../platform/api/action-sheet/index').showActionSheet + return showActionSheet(...args) + }, + addPhoneContact (...args) { + const addPhoneContact = require('../../platform/api/add-phone-contact/index').addPhoneContact + return addPhoneContact(...args) + }, + createAnimation (...args) { + const createAnimation = require('../../platform/api/animation/index').createAnimation + return createAnimation(...args) + }, + onAppShow (...args) { + const onAppShow = require('../../platform/api/app/index').onAppShow + return onAppShow(...args) + }, + onAppHide (...args) { + const onAppHide = require('../../platform/api/app/index').onAppHide + return onAppHide(...args) + }, + offAppShow (...args) { + const offAppShow = require('../../platform/api/app/index').offAppShow + return offAppShow(...args) + }, + offAppHide (...args) { + const offAppHide = require('../../platform/api/app/index').offAppHide + return offAppHide(...args) + }, + onError (...args) { + const onError = require('../../platform/api/app/index').onError + return onError(...args) + }, + offError (...args) { + const offError = require('../../platform/api/app/index').offError + return offError(...args) + }, + createInnerAudioContext (...args) { + const createInnerAudioContext = require('../../platform/api/audio/index').createInnerAudioContext + return createInnerAudioContext(...args) + }, + base64ToArrayBuffer (...args) { + const base64ToArrayBuffer = require('../../platform/api/base/index').base64ToArrayBuffer + return base64ToArrayBuffer(...args) + }, + arrayBufferToBase64 (...args) { + const arrayBufferToBase64 = require('../../platform/api/base/index').arrayBufferToBase64 + return arrayBufferToBase64(...args) + }, + onBLEConnectionStateChange (...args) { + const onBLEConnectionStateChange = require('../../platform/api/ble-connection/index').onBLEConnectionStateChange + return onBLEConnectionStateChange(...args) + }, + offBLEConnectionStateChange (...args) { + const offBLEConnectionStateChange = require('../../platform/api/ble-connection/index').offBLEConnectionStateChange + return offBLEConnectionStateChange(...args) + }, + openBluetoothAdapter (...args) { + const openBluetoothAdapter = require('../../platform/api/ble-connection/index').openBluetoothAdapter + return openBluetoothAdapter(...args) + }, + closeBluetoothAdapter (...args) { + const closeBluetoothAdapter = require('../../platform/api/ble-connection/index').closeBluetoothAdapter + return closeBluetoothAdapter(...args) + }, + startBluetoothDevicesDiscovery (...args) { + const startBluetoothDevicesDiscovery = require('../../platform/api/ble-connection/index').startBluetoothDevicesDiscovery + return startBluetoothDevicesDiscovery(...args) + }, + stopBluetoothDevicesDiscovery (...args) { + const stopBluetoothDevicesDiscovery = require('../../platform/api/ble-connection/index').stopBluetoothDevicesDiscovery + return stopBluetoothDevicesDiscovery(...args) + }, + onBluetoothDeviceFound (...args) { + const onBluetoothDeviceFound = require('../../platform/api/ble-connection/index').onBluetoothDeviceFound + return onBluetoothDeviceFound(...args) + }, + offBluetoothDeviceFound (...args) { + const offBluetoothDeviceFound = require('../../platform/api/ble-connection/index').offBluetoothDeviceFound + return offBluetoothDeviceFound(...args) + }, + getConnectedBluetoothDevices (...args) { + const getConnectedBluetoothDevices = require('../../platform/api/ble-connection/index').getConnectedBluetoothDevices + return getConnectedBluetoothDevices(...args) + }, + getBluetoothAdapterState (...args) { + const getBluetoothAdapterState = require('../../platform/api/ble-connection/index').getBluetoothAdapterState + return getBluetoothAdapterState(...args) + }, + onBluetoothAdapterStateChange (...args) { + const onBluetoothAdapterStateChange = require('../../platform/api/ble-connection/index').onBluetoothAdapterStateChange + return onBluetoothAdapterStateChange(...args) + }, + offBluetoothAdapterStateChange (...args) { + const offBluetoothAdapterStateChange = require('../../platform/api/ble-connection/index').offBluetoothAdapterStateChange + return offBluetoothAdapterStateChange(...args) + }, + getBluetoothDevices (...args) { + const getBluetoothDevices = require('../../platform/api/ble-connection/index').getBluetoothDevices + return getBluetoothDevices(...args) + }, + writeBLECharacteristicValue (...args) { + const writeBLECharacteristicValue = require('../../platform/api/ble-connection/index').writeBLECharacteristicValue + return writeBLECharacteristicValue(...args) + }, + readBLECharacteristicValue (...args) { + const readBLECharacteristicValue = require('../../platform/api/ble-connection/index').readBLECharacteristicValue + return readBLECharacteristicValue(...args) + }, + notifyBLECharacteristicValueChange (...args) { + const notifyBLECharacteristicValueChange = require('../../platform/api/ble-connection/index').notifyBLECharacteristicValueChange + return notifyBLECharacteristicValueChange(...args) + }, + onBLECharacteristicValueChange (...args) { + const onBLECharacteristicValueChange = require('../../platform/api/ble-connection/index').onBLECharacteristicValueChange + return onBLECharacteristicValueChange(...args) + }, + offBLECharacteristicValueChange (...args) { + const offBLECharacteristicValueChange = require('../../platform/api/ble-connection/index').offBLECharacteristicValueChange + return offBLECharacteristicValueChange(...args) + }, + setBLEMTU (...args) { + const setBLEMTU = require('../../platform/api/ble-connection/index').setBLEMTU + return setBLEMTU(...args) + }, + getBLEDeviceRSSI (...args) { + const getBLEDeviceRSSI = require('../../platform/api/ble-connection/index').getBLEDeviceRSSI + return getBLEDeviceRSSI(...args) + }, + getBLEDeviceServices (...args) { + const getBLEDeviceServices = require('../../platform/api/ble-connection/index').getBLEDeviceServices + return getBLEDeviceServices(...args) + }, + getBLEDeviceCharacteristics (...args) { + const getBLEDeviceCharacteristics = require('../../platform/api/ble-connection/index').getBLEDeviceCharacteristics + return getBLEDeviceCharacteristics(...args) + }, + createBLEConnection (...args) { + const createBLEConnection = require('../../platform/api/ble-connection/index').createBLEConnection + return createBLEConnection(...args) + }, + closeBLEConnection (...args) { + const closeBLEConnection = require('../../platform/api/ble-connection/index').closeBLEConnection + return closeBLEConnection(...args) + }, + canvasToTempFilePath (...args) { + const canvasToTempFilePath = require('../../platform/api/canvas/index').canvasToTempFilePath + return canvasToTempFilePath(...args) + }, + canvasGetImageData (...args) { + const canvasGetImageData = require('../../platform/api/canvas/index').canvasGetImageData + return canvasGetImageData(...args) + }, + checkSession (...args) { + const checkSession = require('../../platform/api/check-session/index').checkSession + return checkSession(...args) + }, + setClipboardData (...args) { + const setClipboardData = require('../../platform/api/clipboard-data/index').setClipboardData + return setClipboardData(...args) + }, + getClipboardData (...args) { + const getClipboardData = require('../../platform/api/clipboard-data/index').getClipboardData + return getClipboardData(...args) + }, + createIntersectionObserver (...args) { + const createIntersectionObserver = require('../../platform/api/create-intersection-observer/index').createIntersectionObserver + return createIntersectionObserver(...args) + }, + createSelectorQuery (...args) { + const createSelectorQuery = require('../../platform/api/create-selector-query/index').createSelectorQuery + return createSelectorQuery(...args) + }, + getNetworkType (...args) { + const getNetworkType = require('../../platform/api/device/network/index').getNetworkType + return getNetworkType(...args) + }, + onNetworkStatusChange (...args) { + const onNetworkStatusChange = require('../../platform/api/device/network/index').onNetworkStatusChange + return onNetworkStatusChange(...args) + }, + offNetworkStatusChange (...args) { + const offNetworkStatusChange = require('../../platform/api/device/network/index').offNetworkStatusChange + return offNetworkStatusChange(...args) + }, + startWifi (...args) { + const startWifi = require('../../platform/api/device/wifi/index').startWifi + return startWifi(...args) + }, + stopWifi (...args) { + const stopWifi = require('../../platform/api/device/wifi/index').stopWifi + return stopWifi(...args) + }, + getWifiList (...args) { + const getWifiList = require('../../platform/api/device/wifi/index').getWifiList + return getWifiList(...args) + }, + onGetWifiList (...args) { + const onGetWifiList = require('../../platform/api/device/wifi/index').onGetWifiList + return onGetWifiList(...args) + }, + offGetWifiList (...args) { + const offGetWifiList = require('../../platform/api/device/wifi/index').offGetWifiList + return offGetWifiList(...args) + }, + getConnectedWifi (...args) { + const getConnectedWifi = require('../../platform/api/device/wifi/index').getConnectedWifi + return getConnectedWifi(...args) + }, + downloadFile (...args) { + const downloadFile = require('../../platform/api/file/index').downloadFile + return downloadFile(...args) + }, + uploadFile (...args) { + const uploadFile = require('../../platform/api/file/index').uploadFile + return uploadFile(...args) + }, + getUserInfo (...args) { + const getUserInfo = require('../../platform/api/get-user-info/index').getUserInfo + return getUserInfo(...args) + }, + previewImage (...args) { + const previewImage = require('../../platform/api/image/index').previewImage + return previewImage(...args) + }, + compressImage (...args) { + const compressImage = require('../../platform/api/image/index').compressImage + return compressImage(...args) + }, + getImageInfo (...args) { + const getImageInfo = require('../../platform/api/image/index').getImageInfo + return getImageInfo(...args) + }, + chooseMedia (...args) { + const chooseMedia = require('../../platform/api/image/index').chooseMedia + return chooseMedia(...args) + }, + login (...args) { + const login = require('../../platform/api/login/index').login + return login(...args) + }, + makePhoneCall (...args) { + const makePhoneCall = require('../../platform/api/make-phone-call/index').makePhoneCall + return makePhoneCall(...args) + }, + showModal (...args) { + const showModal = require('../../platform/api/modal/index').showModal + return showModal(...args) + }, + nextTick (...args) { + const nextTick = require('../../platform/api/next-tick/index').nextTick + return nextTick(...args) + }, + pageScrollTo (...args) { + const pageScrollTo = require('../../platform/api/page-scroll-to/index').pageScrollTo + return pageScrollTo(...args) + }, + stopPullDownRefresh (...args) { + const stopPullDownRefresh = require('../../platform/api/pull-down/index').stopPullDownRefresh + return stopPullDownRefresh(...args) + }, + startPullDownRefresh (...args) { + const startPullDownRefresh = require('../../platform/api/pull-down/index').startPullDownRefresh + return startPullDownRefresh(...args) + }, + request (...args) { + const request = require('../../platform/api/request/index').request + return request(...args) + }, + requestPayment (...args) { + const requestPayment = require('../../platform/api/request-payment/index').requestPayment + return requestPayment(...args) + }, + redirectTo (...args) { + const redirectTo = require('../../platform/api/route/index').redirectTo + return redirectTo(...args) + }, + navigateTo (...args) { + const navigateTo = require('../../platform/api/route/index').navigateTo + return navigateTo(...args) + }, + navigateBack (...args) { + const navigateBack = require('../../platform/api/route/index').navigateBack + return navigateBack(...args) + }, + reLaunch (...args) { + const reLaunch = require('../../platform/api/route/index').reLaunch + return reLaunch(...args) + }, + switchTab (...args) { + const switchTab = require('../../platform/api/route/index').switchTab + return switchTab(...args) + }, + scanCode (...args) { + const scanCode = require('../../platform/api/scan-code/index').scanCode + return scanCode(...args) + }, + setScreenBrightness (...args) { + const setScreenBrightness = require('../../platform/api/screen-brightness/index').setScreenBrightness + return setScreenBrightness(...args) + }, + getScreenBrightness (...args) { + const getScreenBrightness = require('../../platform/api/screen-brightness/index').getScreenBrightness + return getScreenBrightness(...args) + }, + setVisualEffectOnCapture (...args) { + const setVisualEffectOnCapture = require('../../platform/api/screen-brightness/index').setVisualEffectOnCapture + return setVisualEffectOnCapture(...args) + }, + onUserCaptureScreen (...args) { + const onUserCaptureScreen = require('../../platform/api/screen-brightness/index').onUserCaptureScreen + return onUserCaptureScreen(...args) + }, + offUserCaptureScreen (...args) { + const offUserCaptureScreen = require('../../platform/api/screen-brightness/index').offUserCaptureScreen + return offUserCaptureScreen(...args) + }, + setNavigationBarTitle (...args) { + const setNavigationBarTitle = require('../../platform/api/set-navigation-bar/index').setNavigationBarTitle + return setNavigationBarTitle(...args) + }, + setNavigationBarColor (...args) { + const setNavigationBarColor = require('../../platform/api/set-navigation-bar/index').setNavigationBarColor + return setNavigationBarColor(...args) + }, + hideHomeButton (...args) { + const hideHomeButton = require('../../platform/api/set-navigation-bar/index').hideHomeButton + return hideHomeButton(...args) + }, + connectSocket (...args) { + const connectSocket = require('../../platform/api/socket/index').connectSocket + return connectSocket(...args) + }, + setStorage (...args) { + const setStorage = require('../../platform/api/storage/index').setStorage + return setStorage(...args) + }, + setStorageSync (...args) { + const setStorageSync = require('../../platform/api/storage/index').setStorageSync + return setStorageSync(...args) + }, + getStorage (...args) { + const getStorage = require('../../platform/api/storage/index').getStorage + return getStorage(...args) + }, + getStorageSync (...args) { + const getStorageSync = require('../../platform/api/storage/index').getStorageSync + return getStorageSync(...args) + }, + getStorageInfo (...args) { + const getStorageInfo = require('../../platform/api/storage/index').getStorageInfo + return getStorageInfo(...args) + }, + getStorageInfoSync (...args) { + const getStorageInfoSync = require('../../platform/api/storage/index').getStorageInfoSync + return getStorageInfoSync(...args) + }, + removeStorage (...args) { + const removeStorage = require('../../platform/api/storage/index').removeStorage + return removeStorage(...args) + }, + removeStorageSync (...args) { + const removeStorageSync = require('../../platform/api/storage/index').removeStorageSync + return removeStorageSync(...args) + }, + clearStorage (...args) { + const clearStorage = require('../../platform/api/storage/index').clearStorage + return clearStorage(...args) + }, + clearStorageSync (...args) { + const clearStorageSync = require('../../platform/api/storage/index').clearStorageSync + return clearStorageSync(...args) + }, + getSystemInfo (...args) { + const getSystemInfo = require('../../platform/api/system/index').getSystemInfo + return getSystemInfo(...args) + }, + getSystemInfoSync (...args) { + const getSystemInfoSync = require('../../platform/api/system/index').getSystemInfoSync + return getSystemInfoSync(...args) + }, + getDeviceInfo (...args) { + const getDeviceInfo = require('../../platform/api/system/index').getDeviceInfo + return getDeviceInfo(...args) + }, + getWindowInfo (...args) { + const getWindowInfo = require('../../platform/api/system/index').getWindowInfo + return getWindowInfo(...args) + }, + getLaunchOptionsSync (...args) { + const getLaunchOptionsSync = require('../../platform/api/system/index').getLaunchOptionsSync + return getLaunchOptionsSync(...args) + }, + getEnterOptionsSync (...args) { + const getEnterOptionsSync = require('../../platform/api/system/index').getEnterOptionsSync + return getEnterOptionsSync(...args) + }, + setTabBarItem (...args) { + const setTabBarItem = require('../../platform/api/tab-bar/index').setTabBarItem + return setTabBarItem(...args) + }, + setTabBarStyle (...args) { + const setTabBarStyle = require('../../platform/api/tab-bar/index').setTabBarStyle + return setTabBarStyle(...args) + }, + showTabBar (...args) { + const showTabBar = require('../../platform/api/tab-bar/index').showTabBar + return showTabBar(...args) + }, + hideTabBar (...args) { + const hideTabBar = require('../../platform/api/tab-bar/index').hideTabBar + return hideTabBar(...args) + }, + showToast (...args) { + const showToast = require('../../platform/api/toast/index').showToast + return showToast(...args) + }, + hideToast (...args) { + const hideToast = require('../../platform/api/toast/index').hideToast + return hideToast(...args) + }, + showLoading (...args) { + const showLoading = require('../../platform/api/toast/index').showLoading + return showLoading(...args) + }, + hideLoading (...args) { + const hideLoading = require('../../platform/api/toast/index').hideLoading + return hideLoading(...args) + }, + createVideoContext (...args) { + const createVideoContext = require('../../platform/api/video/index').createVideoContext + return createVideoContext(...args) + }, + onWindowResize (...args) { + const onWindowResize = require('../../platform/api/window/index').onWindowResize + return onWindowResize(...args) + }, + offWindowResize (...args) { + const offWindowResize = require('../../platform/api/window/index').offWindowResize + return offWindowResize(...args) + }, + getLocation (...args) { + const getLocation = require('../../platform/api/location/index').getLocation + return getLocation(...args) + }, + openLocation (...args) { + const openLocation = require('../../platform/api/location/index').openLocation + return openLocation(...args) + }, + chooseLocation (...args) { + const chooseLocation = require('../../platform/api/location/index').chooseLocation + return chooseLocation(...args) + }, + onLocationChange (...args) { + const onLocationChange = require('../../platform/api/location/index').onLocationChange + return onLocationChange(...args) + }, + offLocationChange (...args) { + const offLocationChange = require('../../platform/api/location/index').offLocationChange + return offLocationChange(...args) + }, + startLocationUpdate (...args) { + const startLocationUpdate = require('../../platform/api/location/index').startLocationUpdate + return startLocationUpdate(...args) + }, + stopLocationUpdate (...args) { + const stopLocationUpdate = require('../../platform/api/location/index').stopLocationUpdate + return stopLocationUpdate(...args) + }, + getExtConfig (...args) { + const getExtConfig = require('../../platform/api/ext/index').getExtConfig + return getExtConfig(...args) + }, + getExtConfigSync (...args) { + const getExtConfigSync = require('../../platform/api/ext/index').getExtConfigSync + return getExtConfigSync(...args) + }, + vibrateShort (...args) { + const vibrateShort = require('../../platform/api/vibrate/index').vibrateShort + return vibrateShort(...args) + }, + vibrateLong (...args) { + const vibrateLong = require('../../platform/api/vibrate/index').vibrateLong + return vibrateLong(...args) + }, + onKeyboardHeightChange (...args) { + const onKeyboardHeightChange = require('../../platform/api/keyboard/index').onKeyboardHeightChange + return onKeyboardHeightChange(...args) + }, + offKeyboardHeightChange (...args) { + const offKeyboardHeightChange = require('../../platform/api/keyboard/index').offKeyboardHeightChange + return offKeyboardHeightChange(...args) + }, + hideKeyboard (...args) { + const hideKeyboard = require('../../platform/api/keyboard/index').hideKeyboard + return hideKeyboard(...args) + }, + getSetting (...args) { + const getSetting = require('../../platform/api/setting/index').getSetting + return getSetting(...args) + }, + openSetting (...args) { + const openSetting = require('../../platform/api/setting/index').openSetting + return openSetting(...args) + }, + enableAlertBeforeUnload (...args) { + const enableAlertBeforeUnload = require('../../platform/api/setting/index').enableAlertBeforeUnload + return enableAlertBeforeUnload(...args) + }, + disableAlertBeforeUnload (...args) { + const disableAlertBeforeUnload = require('../../platform/api/setting/index').disableAlertBeforeUnload + return disableAlertBeforeUnload(...args) + }, + getMenuButtonBoundingClientRect (...args) { + const getMenuButtonBoundingClientRect = require('../../platform/api/setting/index').getMenuButtonBoundingClientRect + return getMenuButtonBoundingClientRect(...args) + }, + createCameraContext (...args) { + const createCameraContext = require('../../platform/api/camera/index').createCameraContext + return createCameraContext(...args) + } +} diff --git a/packages/api-proxy/src/install.js b/packages/api-proxy/src/install.js index 1e3a2898cd..80fa26622b 100644 --- a/packages/api-proxy/src/install.js +++ b/packages/api-proxy/src/install.js @@ -1,6 +1,6 @@ -import * as platformApi from './platform' import { ENV_OBJ } from './common/js' import promisify from './common/js/promisify' +import dynamicApi from './common/js/dynamic' export default function install (target, options = {}) { const { @@ -9,7 +9,7 @@ export default function install (target, options = {}) { blackList = [], // 强制不变成 promise 格式的 api custom = {} // 自定义转化规则 } = options - const transedApi = Object.assign({}, ENV_OBJ, platformApi) + const transedApi = Object.assign({}, ENV_OBJ, dynamicApi) const promisedApi = usePromise ? promisify(transedApi, whiteList, blackList) : {} Object.assign(target, transedApi, promisedApi, custom[__mpx_mode__]) }