2022-09-30 15:17:12 +02:00
|
|
|
import { Alert } from "react-native";
|
2022-09-29 15:03:47 +02:00
|
|
|
// Lodash
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
// Http Client
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
// Network Infos
|
|
|
|
|
import NetInfo from "@react-native-community/netinfo";
|
|
|
|
|
// Translations
|
|
|
|
|
import i18n from "../../I18n";
|
2022-09-29 16:22:58 +02:00
|
|
|
// Database
|
|
|
|
|
import { Setting } from "../../Database";
|
2022-09-30 16:21:14 +02:00
|
|
|
// FileSytem
|
|
|
|
|
import * as FileSystem from 'expo-file-system';
|
|
|
|
|
|
2022-09-29 15:03:47 +02:00
|
|
|
const api_token = 'toto';
|
|
|
|
|
|
2022-09-28 18:08:39 +02:00
|
|
|
class InstallController {
|
|
|
|
|
|
|
|
|
|
getConfig(url) {
|
2022-09-29 15:03:47 +02:00
|
|
|
NetInfo.fetch().then(state => {
|
|
|
|
|
if (state.isConnected) {
|
|
|
|
|
axios({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: url + '/api/settings',
|
|
|
|
|
responseType: 'json',
|
|
|
|
|
params: {
|
|
|
|
|
token: api_token
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.then(function (response) {
|
2022-09-30 17:13:43 +02:00
|
|
|
if (response.data) {
|
|
|
|
|
if (response.data.status === "OK") {
|
|
|
|
|
_.forEach(response.data.datas, function (value, key) {
|
|
|
|
|
switch (key) {
|
|
|
|
|
case "MainColor":
|
|
|
|
|
Setting.add({ key: key, value: value });
|
|
|
|
|
break;
|
|
|
|
|
case "SquaredLogo":
|
|
|
|
|
case "RectangleLogo":
|
|
|
|
|
case "BackgroundImage":
|
|
|
|
|
case "HomeButtonImage":
|
|
|
|
|
FileSystem.downloadAsync(
|
|
|
|
|
url + "/" + value,
|
|
|
|
|
FileSystem.documentDirectory + key + '.png'
|
|
|
|
|
)
|
|
|
|
|
.then(({ uri }) => {
|
|
|
|
|
console.log('Finished downloading to ', uri);
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
Alert.alert(i18n.t("alert.error"), i18n.t("install.resource_dl_error") + key);
|
|
|
|
|
console.error(error);
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Alert.alert(i18n.t("alert.info"), i18n.t("install.install_complete"));
|
|
|
|
|
} else {
|
|
|
|
|
Alert.alert(i18n.t("alert.error"), i18n.t("alert.error_has_occurred"));
|
|
|
|
|
}
|
2022-09-29 15:03:47 +02:00
|
|
|
}
|
2022-09-30 17:13:43 +02:00
|
|
|
})
|
2022-09-29 15:03:47 +02:00
|
|
|
.catch(function (error) {
|
2022-09-29 16:22:58 +02:00
|
|
|
console.log(error)
|
2022-09-30 17:13:43 +02:00
|
|
|
Alert.alert(i18n.t("alert.error"), i18n.t("alert.error_has_occurred"));
|
|
|
|
|
})
|
2022-09-29 15:03:47 +02:00
|
|
|
} else {
|
2022-09-30 17:13:43 +02:00
|
|
|
Alert.alert(i18n.t("alert.error"), i18n.t("error.tablet_not_connected_internet"));
|
2022-09-29 15:03:47 +02:00
|
|
|
}
|
|
|
|
|
});
|
2022-09-28 18:08:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default new InstallController();
|