Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(devtools): added network configuration UI on RN and binding JS -…
…> Java -> Go
- Loading branch information
Showing
12 changed files
with
254 additions
and
105 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
client/react-native/android/.settings/org.eclipse.buildship.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#Tue Oct 23 12:06:28 CEST 2018 | ||
#Mon Nov 05 13:28:04 CET 2018 | ||
connection.project.dir= |
2 changes: 1 addition & 1 deletion
2
client/react-native/android/app/.settings/org.eclipse.buildship.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#Tue Oct 23 12:06:28 CEST 2018 | ||
#Mon Nov 05 13:28:04 CET 2018 | ||
connection.project.dir=.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
client/react-native/common/components/Screens/Settings/Devtools/Network/Config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
import React, { PureComponent } from 'react' | ||
import { Switch, NativeModules } from 'react-native' | ||
import { Menu, Header } from '../../../../Library' | ||
|
||
export default class Network extends PureComponent { | ||
static navigationOptions = ({ navigation }) => { | ||
return { | ||
header: ( | ||
<Header | ||
navigation={navigation} | ||
title='Network configuration' | ||
titleIcon='sliders' | ||
rightBtnIcon={'save'} | ||
onPressRightBtn={ | ||
navigation.state.params && navigation.state.params.updateConfig | ||
} | ||
backBtn | ||
/> | ||
), | ||
} | ||
} | ||
|
||
state = { | ||
loaded: false, | ||
default_trans: false, | ||
bluetooth_trans: false, | ||
default_bootstrap: false, | ||
custom_bootstrap: [], | ||
mdns: false, | ||
relay: false, | ||
} | ||
|
||
currentConfig = undefined | ||
|
||
hasConfigChanged = () => { | ||
if ( | ||
this.currentConfig !== undefined && | ||
(this.state.default_trans !== this.currentConfig.DefaultTransport || | ||
this.state.bluetooth_trans !== this.currentConfig.BluetoothTransport || | ||
this.state.default_bootstrap !== this.currentConfig.DefaultBootstrap || | ||
this.state.custom_bootstrap !== this.currentConfig.CustomBootstrap || | ||
this.state.mdns !== this.currentConfig.MDNS || | ||
this.state.relay !== this.currentConfig.Relay) | ||
) { | ||
this.props.navigation.setParams({ | ||
updateConfig: this.updateConfig, | ||
}) | ||
} else { | ||
this.props.navigation.setParams({ | ||
updateConfig: undefined, | ||
}) | ||
} | ||
} | ||
|
||
updateConfig = async () => { | ||
try { | ||
let config = { | ||
DefaultTransport: this.state.default_trans, | ||
BluetoothTransport: this.state.bluetooth_trans, | ||
DefaultBootstrap: this.state.default_bootstrap, | ||
CustomBootstrap: this.state.custom_bootstrap, | ||
MDNS: this.state.mdns, | ||
Relay: this.state.relay, | ||
} | ||
let json = JSON.stringify(config) | ||
|
||
await NativeModules.CoreModule.updateNetworkConfig(json) | ||
|
||
this.currentConfig = config | ||
this.props.navigation.setParams({ | ||
updateConfig: undefined, | ||
}) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
|
||
getCurrentConfig = async () => { | ||
try { | ||
let json = await NativeModules.CoreModule.getNetworkConfig() | ||
this.currentConfig = JSON.parse(json) | ||
|
||
this.setState({ | ||
loaded: true, | ||
default_trans: this.currentConfig.DefaultTransport, | ||
bluetooth_trans: this.currentConfig.BluetoothTransport, | ||
default_bootstrap: this.currentConfig.DefaultBootstrap, | ||
custom_bootstrap: this.currentConfig.CustomBootstrap, | ||
mdns: this.currentConfig.MDNS, | ||
relay: this.currentConfig.Relay, | ||
}) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
|
||
componentDidMount () { | ||
this.getCurrentConfig() | ||
} | ||
|
||
render () { | ||
return ( | ||
<Menu> | ||
<Menu.Section title='Transports' customMarginTop={24}> | ||
<Menu.Item | ||
title='Default (TCP and Websocket)' | ||
customRight={ | ||
<Switch | ||
justify='end' | ||
disabled={!this.state.loaded} | ||
value={this.state.default_trans} | ||
onValueChange={value => { | ||
this.setState({ default_trans: value }, () => { | ||
this.hasConfigChanged() | ||
}) | ||
}} | ||
/> | ||
} | ||
/> | ||
<Menu.Item | ||
title='Bluetooth (crash if On -> Off ; #514)' | ||
customRight={ | ||
<Switch | ||
justify='end' | ||
disabled={!this.state.loaded} | ||
value={this.state.bluetooth_trans} | ||
onValueChange={value => { | ||
this.setState({ bluetooth_trans: value }, () => { | ||
this.hasConfigChanged() | ||
}) | ||
}} | ||
/> | ||
} | ||
/> | ||
</Menu.Section> | ||
<Menu.Section title='Bootstrap'> | ||
<Menu.Item | ||
title='Default bootstrap' | ||
customRight={ | ||
<Switch | ||
justify='end' | ||
disabled={!this.state.loaded} | ||
value={this.state.default_bootstrap} | ||
onValueChange={value => { | ||
this.setState({ default_bootstrap: value }, () => { | ||
this.hasConfigChanged() | ||
}) | ||
}} | ||
/> | ||
} | ||
/> | ||
<Menu.Item | ||
title='Custom bootstrap (not implem. yet)' | ||
onPress={() => this.hasConfigChanged()} | ||
/> | ||
</Menu.Section> | ||
<Menu.Section title='Miscellaneous'> | ||
<Menu.Item | ||
title='Multicast DNS' | ||
customRight={ | ||
<Switch | ||
justify='end' | ||
disabled={!this.state.loaded} | ||
value={this.state.mdns} | ||
onValueChange={value => { | ||
this.setState({ mdns: value }, () => { | ||
this.hasConfigChanged() | ||
}) | ||
}} | ||
/> | ||
} | ||
/> | ||
<Menu.Item | ||
title='Berty relay' | ||
customRight={ | ||
<Switch | ||
justify='end' | ||
disabled={!this.state.loaded} | ||
value={this.state.relay} | ||
onValueChange={value => { | ||
this.setState({ relay: value }, () => { | ||
this.hasConfigChanged() | ||
}) | ||
}} | ||
/> | ||
} | ||
/> | ||
</Menu.Section> | ||
</Menu> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
client/react-native/common/components/Screens/Settings/Devtools/Network/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createSubStackNavigator } from '../../../../../helpers/react-navigation' | ||
import Network from './Network' | ||
import Peers from './Peers' | ||
import Config from './Config' | ||
|
||
export default createSubStackNavigator( | ||
{ | ||
'network/list': Network, | ||
'network/config': Config, | ||
'network/peers': Peers, | ||
}, | ||
{ | ||
initialRouteName: 'network/list', | ||
} | ||
) |
33 changes: 0 additions & 33 deletions
33
client/react-native/common/components/Screens/Settings/Devtools/Networks/List.js
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
client/react-native/common/components/Screens/Settings/Devtools/Networks/index.js
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
client/react-native/common/components/Screens/Settings/Devtools/Peers.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.