fix: missing first call on check for updates

This commit is contained in:
Zamitto 2025-01-10 20:41:31 -03:00
parent e4fefdedb6
commit 8f1acb48a0
2 changed files with 14 additions and 8 deletions

View File

@ -1,7 +1,7 @@
import type { AppUpdaterEvent } from "@types"; import type { AppUpdaterEvent } from "@types";
import { registerEvent } from "../register-event"; import { registerEvent } from "../register-event";
import updater, { UpdateInfo } from "electron-updater"; import updater, { UpdateInfo } from "electron-updater";
import { WindowManager } from "@main/services"; import { logger, WindowManager } from "@main/services";
import { app } from "electron"; import { app } from "electron";
import { publishNotificationUpdateReadyToInstall } from "@main/services/notifications"; import { publishNotificationUpdateReadyToInstall } from "@main/services/notifications";
@ -36,7 +36,9 @@ const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
if (app.isPackaged) { if (app.isPackaged) {
autoUpdater.autoDownload = isAutoInstallAvailable; autoUpdater.autoDownload = isAutoInstallAvailable;
autoUpdater.checkForUpdates(); autoUpdater.checkForUpdates().then((result) => {
logger.log(`Check for updates result: ${result}`);
});
} else if (sendEventsForDebug) { } else if (sendEventsForDebug) {
mockValuesForDebug(); mockValuesForDebug();
} }

View File

@ -1,5 +1,5 @@
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
import { SyncIcon } from "@primer/octicons-react"; import { SyncIcon } from "@primer/octicons-react";
import { Link } from "../link/link"; import { Link } from "../link/link";
import * as styles from "./header.css"; import * as styles from "./header.css";
@ -40,18 +40,22 @@ export function AutoUpdateSubHeader() {
}; };
}, []); }, []);
useEffect(() => { const checkForUpdates = useCallback(() => {
const checkInterval = setInterval(() => {
window.electron.checkForUpdates().then((isAutoInstallAvailable) => { window.electron.checkForUpdates().then((isAutoInstallAvailable) => {
console.log("checking for updates");
setIsAutoInstallAvailable(isAutoInstallAvailable); setIsAutoInstallAvailable(isAutoInstallAvailable);
}); });
}, []);
useEffect(() => {
checkForUpdates();
const checkInterval = setInterval(() => {
checkForUpdates();
}, CHECK_FOR_UPDATES_INTERVAL); }, CHECK_FOR_UPDATES_INTERVAL);
return () => { return () => {
clearInterval(checkInterval); clearInterval(checkInterval);
}; };
}, []); }, [checkForUpdates]);
if (!newVersion) return null; if (!newVersion) return null;