From 49d256a51f46c6d7bd9e978f6e65609caeec899f Mon Sep 17 00:00:00 2001 From: chs97 <623528324@qq.com> Date: Tue, 30 Oct 2018 15:12:34 +0800 Subject: [PATCH] fix(setting): fix systemproxy & startatlogin jsbridge --- src/containers/Settings/index.tsx | 28 ++++++++++++++++++++++++---- src/lib/jsBridge.ts | 16 ++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/containers/Settings/index.tsx b/src/containers/Settings/index.tsx index f139cc9..374962b 100644 --- a/src/containers/Settings/index.tsx +++ b/src/containers/Settings/index.tsx @@ -8,7 +8,7 @@ import { updateConfig } from '@lib/request' import { setLocalStorageItem, to } from '@lib/helper' import { rootStores } from '@lib/createStore' import './style.scss' -import { isClashX } from '@lib/jsBridge' +import { isClashX, jsBridge } from '@lib/jsBridge' class Settings extends React.Component { state = { @@ -21,7 +21,8 @@ class Settings extends React.Component { externalControllerHost: '127.0.0.1', externalControllerPort: '8080', externalControllerSecret: '', - showEditDrawer: false + showEditDrawer: false, + isClashX: false } languageOptions: ButtonSelectOptions[] = [{ label: '中文', value: 'zh' }, { label: 'English', value: 'en' }] @@ -66,9 +67,26 @@ class Settings extends React.Component { } } + handleStartAtLoginChange = async (state: boolean) => { + await jsBridge.setStartAtLogin(state) + this.setState({ startAtLogin: state }) + } + + handleSetSystemProxy = async (state: boolean) => { + await jsBridge.setSystemProxy(state) + this.setState({ setAsSystemProxy: state }) + } + async componentDidMount () { if (isClashX()) { await rootStores.config.fetchAndParseConfig() + const startAtLogin = await jsBridge.getStartAtLogin() + const setAsSystemProxy = await jsBridge.isSystemProxySet() + this.setState({ + startAtLogin, + setAsSystemProxy, + isClashX: true + }) } else { await rootStores.config.fetchConfig() } @@ -87,6 +105,7 @@ class Settings extends React.Component { render () { const { t, lng } = this.props const { + isClashX, startAtLogin, setAsSystemProxy, allowConnectFromLan, @@ -113,7 +132,7 @@ class Settings extends React.Component { {t('labels.startAtLogin')} - this.setState({ startAtLogin })} /> + {t('labels.language')} @@ -128,8 +147,9 @@ class Settings extends React.Component { this.setState({ setAsSystemProxy })} + onChange={this.handleSetSystemProxy} /> diff --git a/src/lib/jsBridge.ts b/src/lib/jsBridge.ts index 6dfd4cd..8ac8965 100644 --- a/src/lib/jsBridge.ts +++ b/src/lib/jsBridge.ts @@ -144,6 +144,22 @@ export class JsBridge { public writeConfigWithString (data: string) { return this.callHandler('writeConfigWithString', data) } + + public setSystemProxy (data: boolean) { + return this.callHandler('setSystemProxy', data) + } + + public getStartAtLogin () { + return this.callHandler('getStartAtLogin') + } + + public setStartAtLogin (data: boolean) { + return this.callHandler('setStartAtLogin', data) + } + + public isSystemProxySet () { + return this.callHandler('isSystemProxySet') + } } export function setupJsBridge (callback) {