Skip to content

Commit

Permalink
Merge pull request #15865 from xiaoyan428820/4.x
Browse files Browse the repository at this point in the history
fix: [harmony-hybrid]修复部分API调用原生报错问题
  • Loading branch information
qican777 authored Jun 11, 2024
2 parents 2905352 + 1e0be27 commit 812e97d
Show file tree
Hide file tree
Showing 40 changed files with 233 additions and 139 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import Taro from '@tarojs/taro'
import { View, Button, Text } from '@tarojs/components'
import { View } from '@tarojs/components'
import ButtonList from '@/components/buttonList'
import './index.scss'
import { TestConsole } from '@/util/util'
Expand Down Expand Up @@ -47,9 +47,6 @@ export default class Index extends React.Component {
TestConsole.consoleComplete.call(this, res, apiIndex)
},
})
.then((res) => {
TestConsole.consoleResult.call(this, res, apiIndex)
})
},
},
{
Expand All @@ -71,9 +68,6 @@ export default class Index extends React.Component {
TestConsole.consoleNormal('startRecord callback :', res)
},
})
.then((res) => {
TestConsole.consoleResult.call(this, res, apiIndex)
})
},
},
{
Expand All @@ -92,9 +86,6 @@ export default class Index extends React.Component {
TestConsole.consoleComplete.call(this, res, apiIndex)
},
})
.then((res) => {
TestConsole.consoleResult.call(this, res, apiIndex)
})
},
},
{
Expand All @@ -114,9 +105,6 @@ export default class Index extends React.Component {
TestConsole.consoleComplete.call(this, res, apiIndex)
},
})
.then((res) => {
TestConsole.consoleResult.call(this, res, apiIndex)
})
},
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import Taro from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import { View } from '@tarojs/components'
import ButtonList from '@/components/buttonList'
import './index.scss'

Expand All @@ -14,15 +14,21 @@ export default class Index extends React.Component {
list: [
{
id: 'startSoterAuthentication 指纹',
func: null,
func: () => {
this.startSoterAuthentication('fingerPrint')
},
},
{
id: 'startSoterAuthentication 人脸',
func: null,
func: () => {
this.startSoterAuthentication('facial')
},
},
{
id: 'startSoterAuthentication 声纹',
func: null,
func: () => {
this.startSoterAuthentication('speech')
},
},
{
id: 'checkIsSupportSoterAuthentication',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import Taro from '@tarojs/taro'

import native from '../../NativeApi'

/**
* 取消监听内存不足告警事件
*
* @canUse offMemoryWarning
* @null_implementation
*/
export const offMemoryWarning: typeof Taro.offMemoryWarning = (callback) => {
// @ts-ignore
if (native[offMemoryWarning]) {
// @ts-ignore
native.offMemoryWarning(callback)
}
export const offMemoryWarning: typeof Taro.offMemoryWarning = (_callback) => {

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ import Taro from '@tarojs/taro'
* @canUse onMemoryWarning
* @null_implementation
*/
export const onMemoryWarning: typeof Taro.onMemoryWarning = (callback) => {
// @ts-ignore
if (native[onMemoryWarning]) {
// @ts-ignore
native.onMemoryWarning((res: any) => {
const ret: Taro.onMemoryWarning.CallbackResult = {
level: res.level,
}
callback(ret)
})
}
export const onMemoryWarning: typeof Taro.onMemoryWarning = (_callback) => {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { asyncAndNotRelease, asyncAndRelease } from '../../harmony-native/ApiDecorator'

class NativeWifi {
@asyncAndRelease
connectWifi (_options: any):void {}

@asyncAndRelease
getConnectedWifi (_options: any):void {}

@asyncAndRelease
getWifiList (_options: any):void {}

@asyncAndRelease
offGetWifiList (_options: any):void {}

@asyncAndRelease
offWifiConnected (_options: any):void {}

@asyncAndRelease
offWifiConnectedWithPartialInfo (_options: any):void {}

@asyncAndNotRelease
onGetWifiList (_options: any):void {}

@asyncAndNotRelease
onWifiConnected (_options: any):void {}

@asyncAndNotRelease
onWifiConnectedWithPartialInfo (_options: any):void {}

@asyncAndRelease
startWifi (_options: any):void {}

@asyncAndRelease
stopWifi (_options: any):void {}
}

const nativeWifi = new NativeWifi()

export default nativeWifi

Check failure on line 40 in packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/NativeWifi.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 18.x (ubuntu-latest)

Newline required at end of file but not found

Check failure on line 40 in packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/NativeWifi.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 20.x (ubuntu-latest)

Newline required at end of file but not found

Check failure on line 40 in packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/NativeWifi.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js (macos-11)

Newline required at end of file but not found

Check failure on line 40 in packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/NativeWifi.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js (windows-latest)

Newline required at end of file but not found
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro'
import { getParameterError, shouldBeObject } from 'src/api/apis/utils'
import { MethodHandler } from 'src/api/apis/utils/handler'

import nativeWifi from './NativeWifi'

/**
* 连接 Wi-Fi
*
Expand Down Expand Up @@ -63,8 +65,7 @@ export const connectWifi: typeof Taro.connectWifi = (options) => {
)
}

// @ts-ignore
native.connectWifi({
nativeWifi.connectWifi({
SSID: SSID,
password: password,
BSSID: BSSID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro'
import { shouldBeObject } from 'src/api/apis/utils'
import { MethodHandler } from 'src/api/apis/utils/handler'

import nativeWifi from './NativeWifi'

/**
* 获取已连接中的 Wi-Fi 信息
*
Expand All @@ -20,8 +22,7 @@ export const getConnectedWifi: typeof Taro.getConnectedWifi = (options) => {
const handle = new MethodHandler({ name, success, fail, complete })

return new Promise((resolve, reject) => {
// @ts-ignore
native.getConnectedWifi({
nativeWifi.getConnectedWifi({
success: (res: any) => {
handle.success(res, { resolve, reject })
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro'
import { shouldBeObject } from 'src/api/apis/utils'
import { MethodHandler } from 'src/api/apis/utils/handler'

import nativeWifi from './NativeWifi'

/**
* 请求获取 Wi-Fi 列表
*
Expand All @@ -19,8 +21,7 @@ export const getWifiList: typeof Taro.getWifiList = (options) => {
const handle = new MethodHandler({ name, success, fail, complete })

return new Promise((resolve, reject) => {
// @ts-ignore
native.getWifiList({
nativeWifi.getWifiList({
success: (res: any) => {
handle.success(res, { resolve, reject })
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* 设置 wifiList 中 AP 的相关信息
*
* @canNotUse setWifiList
*/
export * from './connectWifi'
export * from './getConnectedWifi'
export * from './getWifiList'
Expand All @@ -14,7 +9,6 @@ export * from './onWifiConnected'
export * from './onWifiConnectedWithPartialInfo'
export * from './startWifi'
export * from './stopWifi'
export { setWifiList } from '@tarojs/taro-h5'

/**
* Wifi 信息(native 返回)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Taro from '@tarojs/taro'
import { shouldBeFunction } from 'src/api/apis/utils'

import nativeWifi from './NativeWifi'

/**
* 取消监听获取到 Wi-Fi 列表数据事件
*
Expand All @@ -17,6 +19,5 @@ export const offGetWifiList: typeof Taro.offGetWifiList = (callback) => {
return
}

// @ts-ignore
native.offGetWifiList(callback)
nativeWifi.offGetWifiList(callback)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Taro from '@tarojs/taro'
import { shouldBeFunction } from 'src/api/apis/utils'

import nativeWifi from './NativeWifi'

/**
* 取消监听连接上 Wi-Fi 的事件
*
Expand All @@ -17,8 +19,7 @@ export const offWifiConnected: typeof Taro.offWifiConnected = (callback) => {
return
}

// @ts-ignore
native.offWifiConnected((res: any) => {
nativeWifi.offWifiConnected((res: any) => {
const result: Taro.onWifiConnected.CallbackResult = {
/** Wi-Fi 信息 */
wifi: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Taro from '@tarojs/taro'
import { shouldBeFunction } from 'src/api/apis/utils'

import nativeWifi from './NativeWifi'

/**
* 取消监听连接上 Wi-Fi 的事件
*
Expand All @@ -17,8 +19,7 @@ export const offWifiConnectedWithPartialInfo: typeof Taro.offWifiConnectedWithPa
return
}

// @ts-ignore
native.offWifiConnectedWithPartialInfo((res: any) => {
nativeWifi.offWifiConnectedWithPartialInfo((res: any) => {
const result: Taro.onWifiConnectedWithPartialInfo.CallbackResult = {
/** 只包含 SSID 属性的 WifiInfo 对象 */
wifi: { SSID: res.wifi.SSID },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Taro from '@tarojs/taro'
import { shouldBeFunction } from 'src/api/apis/utils'

import nativeWifi from './NativeWifi'

/**
* 监听获取到 Wi-Fi 列表数据事件
*
Expand All @@ -18,6 +20,5 @@ export const onGetWifiList: typeof Taro.onGetWifiList = (callback) => {
return
}

// @ts-ignore
native.onGetWifiList(callback)
nativeWifi.onGetWifiList(callback)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Taro from '@tarojs/taro'
import { shouldBeFunction } from 'src/api/apis/utils'

import nativeWifi from './NativeWifi'

/**
* 监听连接上 Wi-Fi 的事件
*
Expand All @@ -18,8 +20,7 @@ export const onWifiConnected: typeof Taro.onWifiConnected = (callback) => {
return
}

// @ts-ignore
native.onWifiConnected((res: any) => {
nativeWifi.onWifiConnected((res: any) => {
const result: Taro.onWifiConnected.CallbackResult = {
/** Wi-Fi 信息 */
wifi: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Taro from '@tarojs/taro'
import { shouldBeFunction } from 'src/api/apis/utils'

import nativeWifi from './NativeWifi'

/**
* 监听连接上 Wi-Fi 的事件
*
Expand All @@ -18,8 +20,7 @@ export const onWifiConnectedWithPartialInfo: typeof Taro.onWifiConnectedWithPart
return
}

// @ts-ignore
native.onWifiConnectedWithPartialInfo((res: any) => {
nativeWifi.onWifiConnectedWithPartialInfo((res: any) => {
const result: Taro.onWifiConnectedWithPartialInfo.CallbackResult = {
/** 只包含 SSID 属性的 WifiInfo 对象 */
wifi: { SSID: res.wifi.SSID },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro'
import { shouldBeObject } from 'src/api/apis/utils'
import { MethodHandler } from 'src/api/apis/utils/handler'

import nativeWifi from './NativeWifi'

/**
* 初始化 Wi-Fi 模块
*
Expand All @@ -19,8 +21,7 @@ export const startWifi: typeof Taro.startWifi = (options) => {
const handle = new MethodHandler({ name, success, fail, complete })

return new Promise((resolve, reject) => {
// @ts-ignore
native.startWifi({
nativeWifi.startWifi({
success: (res: any) => {
handle.success(res, { resolve, reject })
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro'
import { shouldBeObject } from 'src/api/apis/utils'
import { MethodHandler } from 'src/api/apis/utils/handler'

import nativeWifi from './NativeWifi'

/**
* 关闭 Wi-Fi 模块
*
Expand All @@ -19,8 +21,7 @@ export const stopWifi: typeof Taro.stopWifi = (options) => {
const handle = new MethodHandler({ name, success, fail, complete })

return new Promise((resolve, reject) => {
// @ts-ignore
native.stopWifi({
nativeWifi.stopWifi({
success: (res: any) => {
handle.success(res, { resolve, reject })
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const getFileInfo: typeof Taro.getFileInfo = (options) => {

return new Promise<Taro.getFileInfo.FailCallbackResult | Taro.getFileInfo.SuccessCallbackResult>(
(resolve, reject) => {
// @ts-ignore
native.getFileInfo({
filePath: filePath,
digestAlgorithm: digestAlgorithm,
Expand Down
Loading

0 comments on commit 812e97d

Please sign in to comment.