mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-16 10:28:29 -07:00
* client: add update timeout
This commit is contained in:
parent
9cffe865ec
commit
24f582d36d
@ -263,5 +263,6 @@
|
|||||||
"dns_providers": "Here is a <0>list of known DNS providers</0> to choose from.",
|
"dns_providers": "Here is a <0>list of known DNS providers</0> to choose from.",
|
||||||
"update_now": "Update now",
|
"update_now": "Update now",
|
||||||
"update_failed": "Update failed",
|
"update_failed": "Update failed",
|
||||||
|
"update_failed_try_later": "Update failed, please try again later",
|
||||||
"processing_update": "Please wait, AdGuard Home is being updated"
|
"processing_update": "Please wait, AdGuard Home is being updated"
|
||||||
}
|
}
|
@ -2,6 +2,7 @@ import { createAction } from 'redux-actions';
|
|||||||
import round from 'lodash/round';
|
import round from 'lodash/round';
|
||||||
import { t } from 'i18next';
|
import { t } from 'i18next';
|
||||||
import { showLoading, hideLoading } from 'react-redux-loading-bar';
|
import { showLoading, hideLoading } from 'react-redux-loading-bar';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
import { normalizeHistory, normalizeFilteringStatus, normalizeLogs, normalizeTextarea } from '../helpers/helpers';
|
import { normalizeHistory, normalizeFilteringStatus, normalizeLogs, normalizeTextarea } from '../helpers/helpers';
|
||||||
import { SETTINGS_NAMES, CHECK_TIMEOUT } from '../helpers/constants';
|
import { SETTINGS_NAMES, CHECK_TIMEOUT } from '../helpers/constants';
|
||||||
@ -163,14 +164,43 @@ export const getUpdate = () => async (dispatch) => {
|
|||||||
try {
|
try {
|
||||||
await apiClient.getUpdate();
|
await apiClient.getUpdate();
|
||||||
|
|
||||||
const timer = setInterval(async () => {
|
const checkUpdate = async (attempts) => {
|
||||||
const dnsStatus = await apiClient.getGlobalStatus();
|
let count = attempts || 1;
|
||||||
if (dnsStatus) {
|
let timeout;
|
||||||
clearInterval(timer);
|
|
||||||
|
if (count > 60) {
|
||||||
|
dispatch(addErrorToast({ error: 'update_failed_try_later' }));
|
||||||
|
dispatch(getUpdateFailure());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rmTimeout = t => t && clearTimeout(t);
|
||||||
|
const setRecursiveTimeout = (time, ...args) => setTimeout(
|
||||||
|
checkUpdate,
|
||||||
|
time,
|
||||||
|
...args,
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(count);
|
||||||
|
|
||||||
|
axios.get('control/status')
|
||||||
|
.then((response) => {
|
||||||
|
rmTimeout(timeout);
|
||||||
|
if (response) {
|
||||||
dispatch(getUpdateSuccess());
|
dispatch(getUpdateSuccess());
|
||||||
window.location.reload(true);
|
window.location.reload(true);
|
||||||
}
|
}
|
||||||
}, CHECK_TIMEOUT);
|
timeout = setRecursiveTimeout(CHECK_TIMEOUT, count += 1);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
rmTimeout(timeout);
|
||||||
|
timeout = setRecursiveTimeout(CHECK_TIMEOUT, count += 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
checkUpdate();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(addErrorToast({ error: 'update_failed' }));
|
dispatch(addErrorToast({ error: 'update_failed' }));
|
||||||
dispatch(getUpdateFailure());
|
dispatch(getUpdateFailure());
|
||||||
|
Loading…
Reference in New Issue
Block a user