Skip to content

Commit

Permalink
补全debug api
Browse files Browse the repository at this point in the history
  • Loading branch information
58liuyang committed Apr 28, 2024
1 parent 015a044 commit 99d36e0
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ common/autoinstallers/*/.npmrc

target/
debug/
!packages/taro-platform-harmony-hybrid/src/api/apis/base/debug

# Binding artifacts
artifacts
Expand All @@ -84,4 +85,4 @@ artifacts
*.node

# harmony-hybrid extend-h5-apis file
packages/taro-platform-harmony-hybrid/src/api/apis/extend-h5-apis.ts
packages/taro-platform-harmony-hybrid/src/api/apis/extend-h5-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@
"verticalAccuracy": true
}
},
"getLogManager": false,
"getLogManager": true,
"getMenuButtonBoundingClientRect": {
"return": {
"left": true,
Expand Down Expand Up @@ -958,7 +958,7 @@
"getPrivacySetting": false,
"getQQRunData": false,
"getRandomValues": false,
"getRealtimeLogManager": false,
"getRealtimeLogManager": true,
"getRecorderManager": true,
"getRendererUserAgent": false,
"getSavedFileInfo": {
Expand Down Expand Up @@ -1755,7 +1755,7 @@
"setCustomDress": false,
"setDocumentTitle": false,
"setEnable1v1Chat": false,
"setEnableDebug": false,
"setEnableDebug": true,
"setInnerAudioOption": false,
"setKeepScreenOn": {
"object": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const asyncAndRelease = window.MethodChannel && window.MethodChannel.jsBridgeMod
// @ts-ignore
const asyncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: true, autoRelease: false }) || (target => target)

export let judgeUseAxios = false
// export let judgeUseAxios = false
class NativeApi {
// @ts-ignore
@(syncAndRelease)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Taro from '@tarojs/api'

/**
* 获取日志管理器对象
*
* @canUse getLogManager
* @null_implementation
*/
export const getLogManager: typeof Taro.getLogManager = () => {
return new LogManager()
}

/**
* 日志管理器
*
* @canUse LogManager
* @null_implementation
*/
class LogManager implements Taro.LogManager {
debug (): void {

}

info (): void {

}

log (): void {

}

warn (): void {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import Taro from '@tarojs/api'

/**
* 获取实时日志管理器对象
*
* @canUse getRealtimeLogManager
* @null_implementation
*/
export const getRealtimeLogManager: typeof Taro.getRealtimeLogManager = () => {
return new RealtimeLogManager()
}

/**
* 实时日志管理器
*
* @canUse RealtimeLogManager
* @null_implementation
*/
class RealtimeLogManager implements Taro.RealtimeLogManager {
addFilterMsg (): void {

}

error (): void {

}

in (): void {

}

info (): void {

}

setFilterMsg (): void {

}

tag (tagName: string): RealtimeTagLogManager {
return new RealtimeTagLogManager(tagName)
}

warn (): void {

}
}

/**
* 给定标签的实时日志管理器
*
* @canUse RealtimeTagLogManager
* @null_implementation
*/
class RealtimeTagLogManager implements Taro.RealtimeTagLogManager {
_tagName: string

constructor (tagName: string) {
this._tagName = tagName
}

addFilterMsg (_msg): void {

}

error (_key, _value): void {

}

info (_key, _value): void {

}

setFilterMsg (_msg): void {

}

warn (_key, _value): void {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 设置是否打开调试开关
export * from './setEnableDebug'

// 获取实时日志管理器对象
export * from './getRealtimeLogManager'

// 获取日志管理器对象
export * from './getLogManager'

/**
* 向调试面板中打印日志。console 是一个全局对象,可以直接访问。
*
* @canUse console
* @__class [debug, error, group, groupEnd, info, log, warn]
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Taro from '@tarojs/api'

import { shouldBeObject } from '../../utils'
import { MethodHandler } from '../../utils/handler'

/**
* 设置是否打开调试开关
*
* @canUse setEnableDebug
* @null_implementation
*/
export const setEnableDebug: typeof Taro.setEnableDebug = (options) => {
const name = 'setEnableDebug'

return new Promise((resolve, reject) => {
// options must be an Object
const isObject = shouldBeObject(options)
if (!isObject.flag) {
const res = { errMsg: `${name}:fail ${isObject.msg}` }
console.error(res.errMsg)
return reject(res)
}
const { success, fail, complete } = options as Exclude<typeof options, undefined>
const handle = new MethodHandler<{
errMsg?: string
}>({ name, success, fail, complete })
try {
handle.success({
errMsg: 'ok'
}, { resolve, reject })
} catch (error) {
handle.fail({
errMsg: 'fail'
}, { resolve, reject })
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export const env = {
export * from './system'

Check failure on line 22 in packages/taro-platform-harmony-hybrid/src/api/apis/base/index.ts

View workflow job for this annotation

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

Run autofix to sort these exports!

Check failure on line 22 in packages/taro-platform-harmony-hybrid/src/api/apis/base/index.ts

View workflow job for this annotation

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

Run autofix to sort these exports!

Check failure on line 22 in packages/taro-platform-harmony-hybrid/src/api/apis/base/index.ts

View workflow job for this annotation

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

Run autofix to sort these exports!

Check failure on line 22 in packages/taro-platform-harmony-hybrid/src/api/apis/base/index.ts

View workflow job for this annotation

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

Run autofix to sort these exports!
export * from './update'
export * from './weapp/life-cycle'
export * from './debug/index'
18 changes: 0 additions & 18 deletions packages/taro-platform-harmony-hybrid/src/api/apis/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1478,30 +1478,12 @@
* @canNotUse updateWeChatApp
*/

/**
* 获取日志管理器对象
*
* @canNotUse getLogManager
*/

/**
* 程序测速上报
*
* @canNotUse getPerformance
*/

/**
* 获取实时日志管理器对象
*
* @canNotUse getRealtimeLogManager
*/

/**
* 设置是否打开调试开关
*
* @canNotUse setEnableDebug
*/

/**
* 插屏广告组件类
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { request as h5Request } from '@tarojs/taro-h5'

import { request as nativeReuqest } from './nativeRequest'


Expand All @@ -7,8 +8,8 @@ import { request as nativeReuqest } from './nativeRequest'
* @param options 请求选项
* @param useNativeRequest 默认使用true
*/
export function request(options: any, useNativeRequest: boolean = true){
return useNativeRequest ? nativeReuqest(options) : h5Request(options);
export function request (options: any, useNativeRequest: boolean = false) {
return useNativeRequest ? nativeReuqest(options) : h5Request(options)
}


Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Taro from '@tarojs/api'
import { isFunction } from '@tarojs/shared'

import { NativeRequest } from '../../interface/NativeRequest'
import native, { judgeUseAxios } from '../../NativeApi'
import native from '../../NativeApi'
import { getParameterError, shouldBeObject } from '../../utils'

export const _request = (options) => {
Expand Down Expand Up @@ -46,7 +46,7 @@ export const _request = (options) => {
reject(res)
},
})
task = judgeUseAxios ? taskID : NativeRequest.getRequestTask(taskID)
task = NativeRequest.getRequestTask(taskID)
}) as any

result.onHeadersReceived = task.onHeadersReceived.bind(task)
Expand Down

0 comments on commit 99d36e0

Please sign in to comment.