Fix: use jsBridge to delay test

This commit is contained in:
Dreamacro 2018-12-20 10:44:51 +08:00
parent ba2ec0d77f
commit 21fae29d84
2 changed files with 16 additions and 3 deletions

View File

@ -3,6 +3,7 @@ import classnames from 'classnames'
// import { Icon } from '@components'
import { BaseComponentProps, TagColors } from '@models'
import { getProxyDelay, Proxy as IProxy } from '@lib/request'
import { isClashX, jsBridge } from '@lib/jsBridge'
import { to, getLocalStorageItem, setLocalStorageItem, sample } from '@lib/helper'
import './style.scss'
@ -49,6 +50,14 @@ export class Proxy extends React.Component<ProxyProps , ProxyState> {
async componentDidMount () {
const { config } = this.props
if (isClashX()) {
const delay = await jsBridge.getProxyDelay(config.name)
if (delay === 0) {
return this.setState({ hasError: true })
}
return this.setState({ delay })
}
const [res, err] = await to(getProxyDelay(config.name))
if (err) {

View File

@ -150,15 +150,19 @@ export class JsBridge {
}
public getStartAtLogin () {
return this.callHandler<Boolean>('getStartAtLogin')
return this.callHandler<boolean>('getStartAtLogin')
}
public getProxyDelay (name: string) {
return this.callHandler<number>('speedTest', name)
}
public setStartAtLogin (data: boolean) {
return this.callHandler<Boolean>('setStartAtLogin', data)
return this.callHandler<boolean>('setStartAtLogin', data)
}
public isSystemProxySet () {
return this.callHandler<Boolean>('isSystemProxySet')
return this.callHandler<boolean>('isSystemProxySet')
}
}