mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-21 21:29:20 +01:00
Fix update check
Change from 1-hour when visible (which is like impossible) to… every page visible debounced up to 1 hour + 30 min interval when visible
This commit is contained in:
parent
e6065403e5
commit
4ddd1d3219
1 changed files with 18 additions and 2 deletions
20
src/app.jsx
20
src/app.jsx
|
@ -264,7 +264,9 @@ function App() {
|
||||||
return !/^\/(login|welcome)/.test(pathname);
|
return !/^\/(login|welcome)/.test(pathname);
|
||||||
}, [location]);
|
}, [location]);
|
||||||
|
|
||||||
useInterval(() => {
|
const lastCheckDate = useRef();
|
||||||
|
const checkForUpdates = () => {
|
||||||
|
lastCheckDate.current = Date.now();
|
||||||
console.log('✨ Check app update');
|
console.log('✨ Check app update');
|
||||||
fetch('./version.json')
|
fetch('./version.json')
|
||||||
.then((r) => r.json())
|
.then((r) => r.json())
|
||||||
|
@ -274,7 +276,21 @@ function App() {
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
}, visible && 1000 * 60 * 60); // 1 hour
|
};
|
||||||
|
useInterval(() => checkForUpdates, visible && 1000 * 60 * 30); // 30 minutes
|
||||||
|
usePageVisibility((visible) => {
|
||||||
|
if (visible) {
|
||||||
|
if (!lastCheckDate.current) {
|
||||||
|
checkForUpdates();
|
||||||
|
} else {
|
||||||
|
const diff = Date.now() - lastCheckDate.current;
|
||||||
|
if (diff > 1000 * 60 * 60) {
|
||||||
|
// 1 hour
|
||||||
|
checkForUpdates();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
Loading…
Reference in a new issue