diff --git a/src/containers/Proxies/components/Proxy/index.tsx b/src/containers/Proxies/components/Proxy/index.tsx index 9d44244..6eaf6ee 100644 --- a/src/containers/Proxies/components/Proxy/index.tsx +++ b/src/containers/Proxies/components/Proxy/index.tsx @@ -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 { 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) { diff --git a/src/lib/jsBridge.ts b/src/lib/jsBridge.ts index bb8f260..976d9ae 100644 --- a/src/lib/jsBridge.ts +++ b/src/lib/jsBridge.ts @@ -150,15 +150,19 @@ export class JsBridge { } public getStartAtLogin () { - return this.callHandler('getStartAtLogin') + return this.callHandler('getStartAtLogin') + } + + public getProxyDelay (name: string) { + return this.callHandler('speedTest', name) } public setStartAtLogin (data: boolean) { - return this.callHandler('setStartAtLogin', data) + return this.callHandler('setStartAtLogin', data) } public isSystemProxySet () { - return this.callHandler('isSystemProxySet') + return this.callHandler('isSystemProxySet') } }