Skip to content

Commit

Permalink
修复修改配置BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
perrornet committed Feb 12, 2019
1 parent a1067c7 commit 3297ed4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
def enableProguardInReleaseBuilds = true
6 changes: 4 additions & 2 deletions project/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ requestCameraPermission();

const Config = {
"download_path": RNFS.ExternalDirectoryPath,
"conf_file_path": `${RNFS.ExternalDirectoryPath}/.GetAnything.Conf`,
"host": "http://23ss464660.iok.la",
"default_host":"http://23ss464660.iok.la",
"server_download_path": "/GetVideoUrl",
Expand All @@ -58,11 +59,12 @@ const Config = {
};

function reloadConf(){
RNFS.readFile(`${RNFS.ExternalDirectoryPath}/GetAnything.Conf`).then((data) =>{
RNFS.readFile(Config.conf_file_path).then((data) =>{
Config.host = data
}).catch((err) => {
// 创建文件
RNFS.writeFile(`${RNFS.ExternalDirectoryPath}/GetAnything.Conf`, Config.host)
console.error(err);
RNFS.writeFile(Config.conf_file_path, Config.host)
});
}
reloadConf();
Expand Down
14 changes: 9 additions & 5 deletions project/pages/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class SettingScreen extends React.Component {
super(props);
this.state = {
Value:"",
reload:"",
reload: false,
};
}

Expand All @@ -56,7 +56,7 @@ export default class SettingScreen extends React.Component {
}
console.warn(this.state.Value);
if (this.state.Value.match("http") == null || this.state.Value.substring(0, 4) != "http"){
Alert.alert("修改配置出错", "输入Host非法,应该以http或https开头,示例:http://23ss464660.iok.la")
Alert.alert("修改配置出错", "输入Host非法,应该以http或https开头,示例:http://23ss464660.iok.la");
return
}
// 连接服务器测试是否可用
Expand All @@ -65,9 +65,13 @@ export default class SettingScreen extends React.Component {
}).then(response => response.text()).then(data => {
console.warn(data);
if (data == "ok"){
RNFS.writeFile(`${RNFS.ExternalDirectoryPath}/GetAnything.Conf`, Config.host);
Config.host = this.state.Value;
this.refs.toast.show(`已修改服务器Host:${Config.host}`, 3000);
RNFS.writeFile(Config.conf_file_path, this.state.Value)
.then(_ => {
Alert.alert("修改配置成功", `已修改服务器HOST: ${Config.host}`);
this.setState({reload: !this.state.reload});
Config.host = this.state.Value;
});

}else{
Alert.alert("修改配置失败", `${this.state.Value}服务器未能响应,请检查服务是否启动。`)
}
Expand Down

0 comments on commit 3297ed4

Please sign in to comment.