forked from XimeX/usrspace-browser-addon
check for online/offline events if fetching should be enabled
This commit is contained in:
parent
5f3af74c07
commit
944b99d1ad
|
@ -57,7 +57,29 @@ const fetchNewData = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchNewData();
|
let intervalHandler = null;
|
||||||
setInterval(() => {
|
|
||||||
|
const stopFetching = () => {
|
||||||
|
if (intervalHandler !== null) {
|
||||||
|
clearInterval(intervalHandler);
|
||||||
|
intervalHandler = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const startFetching = () => {
|
||||||
fetchNewData();
|
fetchNewData();
|
||||||
}, Config.refreshTimeout);
|
if (intervalHandler === null) {
|
||||||
|
intervalHandler = setInterval(() => {
|
||||||
|
fetchNewData();
|
||||||
|
}, Config.refreshTimeout);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('offline', () => {
|
||||||
|
stopFetching();
|
||||||
|
});
|
||||||
|
window.addEventListener('online', () => {
|
||||||
|
startFetching();
|
||||||
|
});
|
||||||
|
if (window.navigator.onLine) {
|
||||||
|
startFetching();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue