feat: remove auto download if is portable version

This commit is contained in:
Zamitto 2024-06-08 21:24:53 -03:00
parent bcef86fd94
commit 8c1851bb4c
3 changed files with 30 additions and 19 deletions

View File

@ -12,6 +12,9 @@ const sendEvent = (event: AppUpdaterEvent) => {
const sendEventsForDebug = false; const sendEventsForDebug = false;
const isAutoInstallAvailable =
process.platform !== "darwin" && process.env.PORTABLE_EXECUTABLE_FILE == null;
const mockValuesForDebug = () => { const mockValuesForDebug = () => {
sendEvent({ type: "update-available", info: { version: "1.3.0" } }); sendEvent({ type: "update-available", info: { version: "1.3.0" } });
sendEvent({ type: "update-downloaded" }); sendEvent({ type: "update-downloaded" });
@ -27,10 +30,13 @@ const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
}); });
if (app.isPackaged) { if (app.isPackaged) {
autoUpdater.autoDownload = isAutoInstallAvailable;
autoUpdater.checkForUpdates(); autoUpdater.checkForUpdates();
} else if (sendEventsForDebug) { } else if (sendEventsForDebug) {
mockValuesForDebug(); mockValuesForDebug();
} }
return isAutoInstallAvailable;
}; };
registerEvent("checkForUpdates", checkForUpdates); registerEvent("checkForUpdates", checkForUpdates);

View File

@ -8,11 +8,10 @@ import { AppUpdaterEvent } from "@types";
export const releasesPageUrl = export const releasesPageUrl =
"https://github.com/hydralauncher/hydra/releases/latest"; "https://github.com/hydralauncher/hydra/releases/latest";
const isMac = window.electron.platform === "darwin";
export function AutoUpdateSubHeader() { export function AutoUpdateSubHeader() {
const [showUpdateSubheader, setShowUpdateSubheader] = useState(false); const [isReadyToInstall, setIsReadyToInstall] = useState(false);
const [newVersion, setNewVersion] = useState(""); const [newVersion, setNewVersion] = useState<string | null>(null);
const [isAutoInstallAvailable, setIsAutoInstallAvailable] = useState(false);
const { t } = useTranslation("header"); const { t } = useTranslation("header");
@ -25,37 +24,41 @@ export function AutoUpdateSubHeader() {
(event: AppUpdaterEvent) => { (event: AppUpdaterEvent) => {
if (event.type == "update-available") { if (event.type == "update-available") {
setNewVersion(event.info.version); setNewVersion(event.info.version);
if (isMac) {
setShowUpdateSubheader(true);
}
} }
if (event.type == "update-downloaded") { if (event.type == "update-downloaded") {
setShowUpdateSubheader(true); setIsReadyToInstall(true);
} }
} }
); );
window.electron.checkForUpdates(); window.electron.checkForUpdates().then((isAutoInstallAvailable) => {
setIsAutoInstallAvailable(isAutoInstallAvailable);
});
return () => { return () => {
unsubscribe(); unsubscribe();
}; };
}, []); }, []);
if (!showUpdateSubheader) return null; if (!newVersion) return null;
return ( if (!isAutoInstallAvailable) {
<header className={styles.subheader}> return (
{isMac ? ( <header className={styles.subheader}>
<Link to={releasesPageUrl} className={styles.newVersionLink}> <Link to={releasesPageUrl} className={styles.newVersionLink}>
<SyncIcon size={12} /> <SyncIcon size={12} />
<small> <small>
{t("version_available_download", { version: newVersion })} {t("version_available_download", { version: newVersion })}
</small> </small>
</Link> </Link>
) : ( </header>
);
}
if (isReadyToInstall) {
return (
<header className={styles.subheader}>
<button <button
type="button" type="button"
className={styles.newVersionButton} className={styles.newVersionButton}
@ -66,7 +69,9 @@ export function AutoUpdateSubHeader() {
{t("version_available_install", { version: newVersion })} {t("version_available_install", { version: newVersion })}
</small> </small>
</button> </button>
)} </header>
</header> );
); }
return null;
} }

View File

@ -94,7 +94,7 @@ declare global {
onAutoUpdaterEvent: ( onAutoUpdaterEvent: (
cb: (event: AppUpdaterEvent) => void cb: (event: AppUpdaterEvent) => void
) => () => Electron.IpcRenderer; ) => () => Electron.IpcRenderer;
checkForUpdates: () => Promise<void>; checkForUpdates: () => Promise<boolean>;
restartAndInstallUpdate: () => Promise<void>; restartAndInstallUpdate: () => Promise<void>;
} }