Skip to content

Commit

Permalink
Merge pull request #576 from hydralauncher/build/win-portable-release
Browse files Browse the repository at this point in the history
build: add windows portable version
  • Loading branch information
zamitto authored Jun 9, 2024
2 parents d2aef7c + bc82cf2 commit abd33d7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
6 changes: 6 additions & 0 deletions src/main/events/autoupdater/check-for-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
Expand All @@ -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);
41 changes: 23 additions & 18 deletions src/renderer/src/components/header/auto-update-sub-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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}
Expand All @@ -66,7 +69,9 @@ export function AutoUpdateSubHeader() {
{t("version_available_install", { version: newVersion })}
</small>
</button>
)}
</header>
);
</header>
);
}

return null;
}
2 changes: 1 addition & 1 deletion src/renderer/src/declaration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ declare global {
onAutoUpdaterEvent: (
cb: (event: AppUpdaterEvent) => void
) => () => Electron.IpcRenderer;
checkForUpdates: () => Promise<void>;
checkForUpdates: () => Promise<boolean>;
restartAndInstallUpdate: () => Promise<void>;
}

Expand Down

0 comments on commit abd33d7

Please sign in to comment.