From 2038bd1fbe0945f6242e9b97c2447300bebcd33a Mon Sep 17 00:00:00 2001
From: Zamitto <167933696+zamitto@users.noreply.github.com>
Date: Fri, 31 May 2024 15:03:29 -0300
Subject: [PATCH] feat: refactors
---
src/main/constants.ts | 2 -
.../events/autoupdater/check-for-updates.ts | 11 ++---
.../autoupdater/restart-and-install-update.ts | 7 +--
.../header/auto-update-sub-header.tsx | 43 +++++++++++++------
.../src/components/header/header.css.ts | 12 +++++-
yarn.lock | 31 +++++++++++--
6 files changed, 72 insertions(+), 34 deletions(-)
diff --git a/src/main/constants.ts b/src/main/constants.ts
index 1b29d01f..de1ccb60 100644
--- a/src/main/constants.ts
+++ b/src/main/constants.ts
@@ -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");
diff --git a/src/main/events/autoupdater/check-for-updates.ts b/src/main/events/autoupdater/check-for-updates.ts
index d48824ee..5d10b7dd 100644
--- a/src/main/events/autoupdater/check-for-updates.ts
+++ b/src/main/events/autoupdater/check-for-updates.ts
@@ -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();
}
};
diff --git a/src/main/events/autoupdater/restart-and-install-update.ts b/src/main/events/autoupdater/restart-and-install-update.ts
index d109ae78..2dbef98f 100644
--- a/src/main/events/autoupdater/restart-and-install-update.ts
+++ b/src/main/events/autoupdater/restart-and-install-update.ts
@@ -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);
}
};
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 8c7f9433..3735f830 100644
--- a/src/renderer/src/components/header/auto-update-sub-header.tsx
+++ b/src/renderer/src/components/header/auto-update-sub-header.tsx
@@ -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 && (
-
-
-
+
+ {isMac ? (
+
+
+ {newVersionText}
+
+ ) : (
+
)}
- >
+
);
}
diff --git a/src/renderer/src/components/header/header.css.ts b/src/renderer/src/components/header/header.css.ts
index 6ad2e2ef..a76e77f6 100644
--- a/src/renderer/src/components/header/header.css.ts
+++ b/src/renderer/src/components/header/header.css.ts
@@ -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",
+});
diff --git a/yarn.lock b/yarn.lock
index 56e24fb7..00d29c7c 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5488,7 +5488,16 @@ stat-mode@^1.0.0:
resolved "https://registry.yarnpkg.com/stat-mode/-/stat-mode-1.0.0.tgz#68b55cb61ea639ff57136f36b216a291800d1465"
integrity sha512-jH9EhtKIjuXZ2cWxmXS8ZP80XyC3iasQxMDV8jzhNJpfDb7VbQLVW4Wvsxz9QZvzV+G4YoSfBUVKDOyxLzi/sg==
-"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
+"string-width-cjs@npm:string-width@^4.2.0":
+ version "4.2.3"
+ resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
+ integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
+ dependencies:
+ emoji-regex "^8.0.0"
+ is-fullwidth-code-point "^3.0.0"
+ strip-ansi "^6.0.1"
+
+string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -5559,7 +5568,14 @@ string_decoder@^1.1.1:
dependencies:
safe-buffer "~5.2.0"
-"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
+"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
+ version "6.0.1"
+ resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
+ integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
+ dependencies:
+ ansi-regex "^5.0.1"
+
+strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -6128,7 +6144,16 @@ word-wrap@^1.2.5:
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==
-"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
+"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
+ version "7.0.0"
+ resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
+ integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
+ dependencies:
+ ansi-styles "^4.0.0"
+ string-width "^4.1.0"
+ strip-ansi "^6.0.0"
+
+wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==