diff --git a/src/main/events/autoupdater/check-for-updates.ts b/src/main/events/autoupdater/check-for-updates.ts index ef2597b8..f7e37481 100644 --- a/src/main/events/autoupdater/check-for-updates.ts +++ b/src/main/events/autoupdater/check-for-updates.ts @@ -12,6 +12,9 @@ const sendEvent = (event: AppUpdaterEvent) => { const sendEventsForDebug = false; +const isAutoInstallAvailable = + process.platform !== "darwin" && process.env.PORTABLE_EXECUTABLE_FILE == null; + const mockValuesForDebug = () => { sendEvent({ type: "update-available", info: { version: "1.3.0" } }); sendEvent({ type: "update-downloaded" }); @@ -27,10 +30,13 @@ const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => { }); if (app.isPackaged) { + autoUpdater.autoDownload = isAutoInstallAvailable; autoUpdater.checkForUpdates(); } else if (sendEventsForDebug) { mockValuesForDebug(); } + + return isAutoInstallAvailable; }; registerEvent("checkForUpdates", checkForUpdates); diff --git a/src/renderer/src/components/header/auto-update-sub-header.tsx b/src/renderer/src/components/header/auto-update-sub-header.tsx index 73c02b84..8e390946 100644 --- a/src/renderer/src/components/header/auto-update-sub-header.tsx +++ b/src/renderer/src/components/header/auto-update-sub-header.tsx @@ -8,11 +8,10 @@ import { AppUpdaterEvent } from "@types"; export const releasesPageUrl = "https://github.com/hydralauncher/hydra/releases/latest"; -const isMac = window.electron.platform === "darwin"; - export function AutoUpdateSubHeader() { - const [showUpdateSubheader, setShowUpdateSubheader] = useState(false); - const [newVersion, setNewVersion] = useState(""); + const [isReadyToInstall, setIsReadyToInstall] = useState(false); + const [newVersion, setNewVersion] = useState(null); + const [isAutoInstallAvailable, setIsAutoInstallAvailable] = useState(false); const { t } = useTranslation("header"); @@ -25,37 +24,41 @@ export function AutoUpdateSubHeader() { (event: AppUpdaterEvent) => { if (event.type == "update-available") { setNewVersion(event.info.version); - - if (isMac) { - setShowUpdateSubheader(true); - } } if (event.type == "update-downloaded") { - setShowUpdateSubheader(true); + setIsReadyToInstall(true); } } ); - window.electron.checkForUpdates(); + window.electron.checkForUpdates().then((isAutoInstallAvailable) => { + setIsAutoInstallAvailable(isAutoInstallAvailable); + }); return () => { unsubscribe(); }; }, []); - if (!showUpdateSubheader) return null; + if (!newVersion) return null; - return ( -
- {isMac ? ( + if (!isAutoInstallAvailable) { + return ( +
{t("version_available_download", { version: newVersion })} - ) : ( +
+ ); + } + + if (isReadyToInstall) { + return ( +
- )} -
- ); +
+ ); + } + + return null; } diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index f908f39e..9b1dd20f 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -94,7 +94,7 @@ declare global { onAutoUpdaterEvent: ( cb: (event: AppUpdaterEvent) => void ) => () => Electron.IpcRenderer; - checkForUpdates: () => Promise; + checkForUpdates: () => Promise; restartAndInstallUpdate: () => Promise; }