mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: refactors
This commit is contained in:
parent
45f30a9208
commit
2038bd1fbe
6 changed files with 72 additions and 34 deletions
|
@ -28,8 +28,6 @@ export const databasePath = path.join(
|
||||||
|
|
||||||
export const logsPath = path.join(app.getPath("appData"), "hydra", "logs");
|
export const logsPath = path.join(app.getPath("appData"), "hydra", "logs");
|
||||||
|
|
||||||
export const releasesPageUrl = "https://github.com/hydralauncher/hydra";
|
|
||||||
|
|
||||||
export const seedsPath = app.isPackaged
|
export const seedsPath = app.isPackaged
|
||||||
? path.join(process.resourcesPath, "seeds")
|
? path.join(process.resourcesPath, "seeds")
|
||||||
: path.join(__dirname, "..", "..", "seeds");
|
: path.join(__dirname, "..", "..", "seeds");
|
||||||
|
|
|
@ -10,8 +10,11 @@ const sendEvent = (event: AppUpdaterEvents) => {
|
||||||
WindowManager.mainWindow?.webContents.send("autoUpdaterEvent", event);
|
WindowManager.mainWindow?.webContents.send("autoUpdaterEvent", event);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sendEventsForDebug = false;
|
||||||
|
|
||||||
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" });
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
|
const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||||
|
@ -19,15 +22,9 @@ const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||||
sendEvent({ type: "update-available", info });
|
sendEvent({ type: "update-available", info });
|
||||||
});
|
});
|
||||||
|
|
||||||
if (process.platform !== "darwin") {
|
|
||||||
autoUpdater.once("update-downloaded", () => {
|
|
||||||
sendEvent({ type: "update-downloaded" });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (app.isPackaged) {
|
if (app.isPackaged) {
|
||||||
autoUpdater.checkForUpdates();
|
autoUpdater.checkForUpdates();
|
||||||
} else {
|
} else if (sendEventsForDebug) {
|
||||||
mockValuesForDebug();
|
mockValuesForDebug();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import updater from "electron-updater";
|
import updater from "electron-updater";
|
||||||
import { releasesPageUrl } from "@main/constants";
|
|
||||||
|
|
||||||
const { autoUpdater } = updater;
|
const { autoUpdater } = updater;
|
||||||
|
|
||||||
const restartAndInstallUpdate = async (_event: Electron.IpcMainInvokeEvent) => {
|
const restartAndInstallUpdate = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||||
autoUpdater.removeAllListeners();
|
autoUpdater.removeAllListeners();
|
||||||
if (app.isPackaged) {
|
if (app.isPackaged) {
|
||||||
if (process.platform === "darwin") {
|
autoUpdater.quitAndInstall(true, true);
|
||||||
open(`${releasesPageUrl}`);
|
|
||||||
} else {
|
|
||||||
autoUpdater.quitAndInstall(true, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,12 @@ import { SyncIcon } from "@primer/octicons-react";
|
||||||
|
|
||||||
import * as styles from "./header.css";
|
import * as styles from "./header.css";
|
||||||
import { AppUpdaterEvents } from "@types";
|
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() {
|
export function AutoUpdateSubHeader() {
|
||||||
const [showUpdateSubheader, setShowUpdateSubheader] = useState(false);
|
const [showUpdateSubheader, setShowUpdateSubheader] = useState(false);
|
||||||
|
@ -17,7 +23,7 @@ export function AutoUpdateSubHeader() {
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (window.electron.platform == "darwin") {
|
if (isMac) {
|
||||||
setNewVersionText(
|
setNewVersionText(
|
||||||
t("version_available_download", { version: newVersion })
|
t("version_available_download", { version: newVersion })
|
||||||
);
|
);
|
||||||
|
@ -33,6 +39,10 @@ export function AutoUpdateSubHeader() {
|
||||||
(event: AppUpdaterEvents) => {
|
(event: AppUpdaterEvents) => {
|
||||||
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") {
|
||||||
|
@ -48,20 +58,25 @@ export function AutoUpdateSubHeader() {
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
if (!showUpdateSubheader) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<header className={styles.subheader}>
|
||||||
{showUpdateSubheader && (
|
{isMac ? (
|
||||||
<header className={styles.subheader}>
|
<Link to={releasesPageUrl} className={styles.newVersionLink}>
|
||||||
<button
|
<SyncIcon size={12} />
|
||||||
type="button"
|
<small>{newVersionText}</small>
|
||||||
className={styles.newVersionButton}
|
</Link>
|
||||||
onClick={handleClickNewUpdate}
|
) : (
|
||||||
>
|
<button
|
||||||
<SyncIcon size={12} />
|
type="button"
|
||||||
<small>{newVersionText}</small>
|
className={styles.newVersionButton}
|
||||||
</button>
|
onClick={handleClickNewUpdate}
|
||||||
</header>
|
>
|
||||||
|
<SyncIcon size={12} />
|
||||||
|
<small>{newVersionText}</small>
|
||||||
|
</button>
|
||||||
)}
|
)}
|
||||||
</>
|
</header>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,9 +157,17 @@ export const newVersionButton = style({
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
gap: `${SPACING_UNIT}px`,
|
gap: `${SPACING_UNIT}px`,
|
||||||
color: vars.color.body,
|
color: vars.color.body,
|
||||||
borderBottom: "1px solid transparent",
|
fontSize: "13px",
|
||||||
":hover": {
|
":hover": {
|
||||||
borderBottom: `1px solid ${vars.color.body}`,
|
textDecoration: "underline",
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const newVersionLink = style({
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: `${SPACING_UNIT}px`,
|
||||||
|
color: "#8e919b !important",
|
||||||
|
fontSize: "13px",
|
||||||
|
});
|
||||||
|
|
31
yarn.lock
31
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"
|
resolved "https://registry.yarnpkg.com/stat-mode/-/stat-mode-1.0.0.tgz#68b55cb61ea639ff57136f36b216a291800d1465"
|
||||||
integrity sha512-jH9EhtKIjuXZ2cWxmXS8ZP80XyC3iasQxMDV8jzhNJpfDb7VbQLVW4Wvsxz9QZvzV+G4YoSfBUVKDOyxLzi/sg==
|
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"
|
version "4.2.3"
|
||||||
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
|
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
|
||||||
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
|
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
|
||||||
|
@ -5559,7 +5568,14 @@ string_decoder@^1.1.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
safe-buffer "~5.2.0"
|
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"
|
version "6.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
|
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
|
||||||
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
|
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"
|
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
|
||||||
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==
|
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"
|
version "7.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
|
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
|
||||||
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
|
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue