feat: check for updates every 60 minutes

This commit is contained in:
Zamitto 2025-01-07 11:57:29 -03:00
parent 3f8a4407ef
commit 33e1de7748

View File

@ -4,10 +4,13 @@ import { SyncIcon } from "@primer/octicons-react";
import { Link } from "../link/link";
import * as styles from "./header.css";
import type { AppUpdaterEvent } from "@types";
import { minutesToMilliseconds } from "date-fns";
export const releasesPageUrl =
"https://github.com/hydralauncher/hydra/releases/latest";
const CHECK_FOR_UPDATES_INTERVAL = minutesToMilliseconds(60);
export function AutoUpdateSubHeader() {
const [isReadyToInstall, setIsReadyToInstall] = useState(false);
const [newVersion, setNewVersion] = useState<string | null>(null);
@ -32,15 +35,24 @@ export function AutoUpdateSubHeader() {
}
);
window.electron.checkForUpdates().then((isAutoInstallAvailable) => {
setIsAutoInstallAvailable(isAutoInstallAvailable);
});
return () => {
unsubscribe();
};
}, []);
useEffect(() => {
const checkInterval = setInterval(() => {
window.electron.checkForUpdates().then((isAutoInstallAvailable) => {
console.log("checking for updates");
setIsAutoInstallAvailable(isAutoInstallAvailable);
});
}, CHECK_FOR_UPDATES_INTERVAL);
return () => {
clearInterval(checkInterval);
};
}, []);
if (!newVersion) return null;
if (!isAutoInstallAvailable) {