mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-02 14:16:39 +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);
|
||||
}, [location]);
|
||||
|
||||
useInterval(() => {
|
||||
const lastCheckDate = useRef();
|
||||
const checkForUpdates = () => {
|
||||
lastCheckDate.current = Date.now();
|
||||
console.log('✨ Check app update');
|
||||
fetch('./version.json')
|
||||
.then((r) => r.json())
|
||||
|
@ -274,7 +276,21 @@ function App() {
|
|||
.catch((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 (
|
||||
<>
|
||||
|
|
Loading…
Reference in a new issue