feat: refactors

This commit is contained in:
Zamitto 2024-05-31 15:03:29 -03:00
parent 45f30a9208
commit 2038bd1fbe
6 changed files with 72 additions and 34 deletions

View file

@ -28,8 +28,6 @@ export const databasePath = path.join(
export const logsPath = path.join(app.getPath("appData"), "hydra", "logs");
export const releasesPageUrl = "https://github.com/hydralauncher/hydra";
export const seedsPath = app.isPackaged
? path.join(process.resourcesPath, "seeds")
: path.join(__dirname, "..", "..", "seeds");

View file

@ -10,8 +10,11 @@ const sendEvent = (event: AppUpdaterEvents) => {
WindowManager.mainWindow?.webContents.send("autoUpdaterEvent", event);
};
const sendEventsForDebug = false;
const mockValuesForDebug = () => {
sendEvent({ type: "update-available", info: { version: "1.3.0" } });
sendEvent({ type: "update-downloaded" });
};
const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
@ -19,15 +22,9 @@ const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
sendEvent({ type: "update-available", info });
});
if (process.platform !== "darwin") {
autoUpdater.once("update-downloaded", () => {
sendEvent({ type: "update-downloaded" });
});
}
if (app.isPackaged) {
autoUpdater.checkForUpdates();
} else {
} else if (sendEventsForDebug) {
mockValuesForDebug();
}
};

View file

@ -1,18 +1,13 @@
import { app } from "electron";
import { registerEvent } from "../register-event";
import updater from "electron-updater";
import { releasesPageUrl } from "@main/constants";
const { autoUpdater } = updater;
const restartAndInstallUpdate = async (_event: Electron.IpcMainInvokeEvent) => {
autoUpdater.removeAllListeners();
if (app.isPackaged) {
if (process.platform === "darwin") {
open(`${releasesPageUrl}`);
} else {
autoUpdater.quitAndInstall(true, true);
}
autoUpdater.quitAndInstall(true, true);
}
};

View file

@ -4,6 +4,12 @@ import { SyncIcon } from "@primer/octicons-react";
import * as styles from "./header.css";
import { AppUpdaterEvents } from "@types";
import { Link } from "../link/link";
export const releasesPageUrl =
"https://github.com/hydralauncher/hydra/releases";
const isMac = window.electron.platform === "darwin";
export function AutoUpdateSubHeader() {
const [showUpdateSubheader, setShowUpdateSubheader] = useState(false);
@ -17,7 +23,7 @@ export function AutoUpdateSubHeader() {
};
useEffect(() => {
if (window.electron.platform == "darwin") {
if (isMac) {
setNewVersionText(
t("version_available_download", { version: newVersion })
);
@ -33,6 +39,10 @@ export function AutoUpdateSubHeader() {
(event: AppUpdaterEvents) => {
if (event.type == "update-available") {
setNewVersion(event.info.version || "");
if (isMac) {
setShowUpdateSubheader(true);
}
}
if (event.type == "update-downloaded") {
@ -48,20 +58,25 @@ export function AutoUpdateSubHeader() {
};
}, []);
if (!showUpdateSubheader) return null;
return (
<>
{showUpdateSubheader && (
<header className={styles.subheader}>
<button
type="button"
className={styles.newVersionButton}
onClick={handleClickNewUpdate}
>
<SyncIcon size={12} />
<small>{newVersionText}</small>
</button>
</header>
<header className={styles.subheader}>
{isMac ? (
<Link to={releasesPageUrl} className={styles.newVersionLink}>
<SyncIcon size={12} />
<small>{newVersionText}</small>
</Link>
) : (
<button
type="button"
className={styles.newVersionButton}
onClick={handleClickNewUpdate}
>
<SyncIcon size={12} />
<small>{newVersionText}</small>
</button>
)}
</>
</header>
);
}

View file

@ -157,9 +157,17 @@ export const newVersionButton = style({
justifyContent: "center",
gap: `${SPACING_UNIT}px`,
color: vars.color.body,
borderBottom: "1px solid transparent",
fontSize: "13px",
":hover": {
borderBottom: `1px solid ${vars.color.body}`,
textDecoration: "underline",
cursor: "pointer",
},
});
export const newVersionLink = style({
display: "flex",
alignItems: "center",
gap: `${SPACING_UNIT}px`,
color: "#8e919b !important",
fontSize: "13px",
});