Merge branch 'main' into feature/adding-animation-to-game-details

This commit is contained in:
Chubby Granny Chaser 2024-06-12 00:01:17 +01:00 committed by GitHub
commit 5cd497d0c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 19 deletions

View File

@ -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);

View File

@ -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<string | null>(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 (
<header className={styles.subheader}>
{isMac ? (
if (!isAutoInstallAvailable) {
return (
<header className={styles.subheader}>
<Link to={releasesPageUrl} className={styles.newVersionLink}>
<SyncIcon size={12} />
<small>
{t("version_available_download", { version: newVersion })}
</small>
</Link>
) : (
</header>
);
}
if (isReadyToInstall) {
return (
<header className={styles.subheader}>
<button
type="button"
className={styles.newVersionButton}
@ -66,7 +69,9 @@ export function AutoUpdateSubHeader() {
{t("version_available_install", { version: newVersion })}
</small>
</button>
)}
</header>
);
</header>
);
}
return null;
}

View File

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