mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: handle auto update for macos
This commit is contained in:
parent
2138aa9711
commit
45f30a9208
9 changed files with 92 additions and 56 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "hydralauncher",
|
"name": "hydralauncher",
|
||||||
"version": "1.2.4",
|
"version": "1.2.3",
|
||||||
"description": "Hydra",
|
"description": "Hydra",
|
||||||
"main": "./out/main/index.js",
|
"main": "./out/main/index.js",
|
||||||
"author": "Los Broxas",
|
"author": "Los Broxas",
|
||||||
|
|
|
@ -29,7 +29,8 @@
|
||||||
"downloads": "Downloads",
|
"downloads": "Downloads",
|
||||||
"search_results": "Search results",
|
"search_results": "Search results",
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
"version_available": "Version {{version}} available. Click here to restart and install."
|
"version_available_install": "Version {{version}} available. Click here to restart and install.",
|
||||||
|
"version_available_download": "Version {{version}} available. Click here to download."
|
||||||
},
|
},
|
||||||
"bottom_panel": {
|
"bottom_panel": {
|
||||||
"no_downloads_in_progress": "No downloads in progress",
|
"no_downloads_in_progress": "No downloads in progress",
|
||||||
|
|
|
@ -29,7 +29,8 @@
|
||||||
"downloads": "Descargas",
|
"downloads": "Descargas",
|
||||||
"search_results": "Resultados de búsqueda",
|
"search_results": "Resultados de búsqueda",
|
||||||
"settings": "Ajustes",
|
"settings": "Ajustes",
|
||||||
"version_available": "Version {{version}} disponible. Haz clic aquí para reiniciar e instalar."
|
"version_available_install": "Version {{version}} disponible. Haz clic aquí para reiniciar e instalar.",
|
||||||
|
"version_available_download": "Version {{version}} disponible. Haz clic aquí para descargar."
|
||||||
},
|
},
|
||||||
"bottom_panel": {
|
"bottom_panel": {
|
||||||
"no_downloads_in_progress": "Sin descargas en progreso",
|
"no_downloads_in_progress": "Sin descargas en progreso",
|
||||||
|
|
|
@ -29,7 +29,8 @@
|
||||||
"search_results": "Resultados da busca",
|
"search_results": "Resultados da busca",
|
||||||
"settings": "Ajustes",
|
"settings": "Ajustes",
|
||||||
"home": "Início",
|
"home": "Início",
|
||||||
"version_available": "Versão {{version}} disponível. Clique aqui para reiniciar e instalar."
|
"version_available_install": "Versão {{version}} disponível. Clique aqui para reiniciar e instalar.",
|
||||||
|
"version_available_download": "Versão {{version}} disponível. Clique aqui para fazer o download."
|
||||||
},
|
},
|
||||||
"bottom_panel": {
|
"bottom_panel": {
|
||||||
"no_downloads_in_progress": "Sem downloads em andamento",
|
"no_downloads_in_progress": "Sem downloads em andamento",
|
||||||
|
|
|
@ -28,6 +28,8 @@ 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");
|
||||||
|
|
|
@ -15,13 +15,15 @@ const mockValuesForDebug = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
|
const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||||
autoUpdater
|
autoUpdater.once("update-available", (info: UpdateInfo) => {
|
||||||
.once("update-available", (info: UpdateInfo) => {
|
sendEvent({ type: "update-available", info });
|
||||||
sendEvent({ type: "update-available", info });
|
});
|
||||||
})
|
|
||||||
.once("update-downloaded", () => {
|
if (process.platform !== "darwin") {
|
||||||
|
autoUpdater.once("update-downloaded", () => {
|
||||||
sendEvent({ type: "update-downloaded" });
|
sendEvent({ type: "update-downloaded" });
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (app.isPackaged) {
|
if (app.isPackaged) {
|
||||||
autoUpdater.checkForUpdates();
|
autoUpdater.checkForUpdates();
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
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) {
|
||||||
autoUpdater.quitAndInstall(true, true);
|
if (process.platform === "darwin") {
|
||||||
|
open(`${releasesPageUrl}`);
|
||||||
|
} else {
|
||||||
|
autoUpdater.quitAndInstall(true, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { SyncIcon } from "@primer/octicons-react";
|
||||||
|
|
||||||
|
import * as styles from "./header.css";
|
||||||
|
import { AppUpdaterEvents } from "@types";
|
||||||
|
|
||||||
|
export function AutoUpdateSubHeader() {
|
||||||
|
const [showUpdateSubheader, setShowUpdateSubheader] = useState(false);
|
||||||
|
const [newVersion, setNewVersion] = useState("");
|
||||||
|
const [newVersionText, setNewVersionText] = useState("");
|
||||||
|
|
||||||
|
const { t } = useTranslation("header");
|
||||||
|
|
||||||
|
const handleClickNewUpdate = () => {
|
||||||
|
window.electron.restartAndInstallUpdate();
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (window.electron.platform == "darwin") {
|
||||||
|
setNewVersionText(
|
||||||
|
t("version_available_download", { version: newVersion })
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setNewVersionText(
|
||||||
|
t("version_available_install", { version: newVersion })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [t, newVersion]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const unsubscribe = window.electron.onAutoUpdaterEvent(
|
||||||
|
(event: AppUpdaterEvents) => {
|
||||||
|
if (event.type == "update-available") {
|
||||||
|
setNewVersion(event.info.version || "");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type == "update-downloaded") {
|
||||||
|
setShowUpdateSubheader(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
window.electron.checkForUpdates();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
unsubscribe();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{showUpdateSubheader && (
|
||||||
|
<header className={styles.subheader}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={styles.newVersionButton}
|
||||||
|
onClick={handleClickNewUpdate}
|
||||||
|
>
|
||||||
|
<SyncIcon size={12} />
|
||||||
|
<small>{newVersionText}</small>
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,18 +1,13 @@
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import {
|
import { ArrowLeftIcon, SearchIcon, XIcon } from "@primer/octicons-react";
|
||||||
ArrowLeftIcon,
|
|
||||||
SearchIcon,
|
|
||||||
SyncIcon,
|
|
||||||
XIcon,
|
|
||||||
} from "@primer/octicons-react";
|
|
||||||
|
|
||||||
import { useAppDispatch, useAppSelector } from "@renderer/hooks";
|
import { useAppDispatch, useAppSelector } from "@renderer/hooks";
|
||||||
|
|
||||||
import * as styles from "./header.css";
|
import * as styles from "./header.css";
|
||||||
import { clearSearch } from "@renderer/features";
|
import { clearSearch } from "@renderer/features";
|
||||||
import { AppUpdaterEvents } from "@types";
|
import { AutoUpdateSubHeader } from "./auto-update-sub-header";
|
||||||
|
|
||||||
export interface HeaderProps {
|
export interface HeaderProps {
|
||||||
onSearch: (query: string) => void;
|
onSearch: (query: string) => void;
|
||||||
|
@ -40,9 +35,6 @@ export function Header({ onSearch, onClear, search }: HeaderProps) {
|
||||||
|
|
||||||
const [isFocused, setIsFocused] = useState(false);
|
const [isFocused, setIsFocused] = useState(false);
|
||||||
|
|
||||||
const [showUpdateSubheader, setShowUpdateSubheader] = useState(false);
|
|
||||||
const [newVersion, setNewVersion] = useState("");
|
|
||||||
|
|
||||||
const { t } = useTranslation("header");
|
const { t } = useTranslation("header");
|
||||||
|
|
||||||
const title = useMemo(() => {
|
const title = useMemo(() => {
|
||||||
|
@ -58,30 +50,6 @@ export function Header({ onSearch, onClear, search }: HeaderProps) {
|
||||||
}
|
}
|
||||||
}, [location.pathname, search, dispatch]);
|
}, [location.pathname, search, dispatch]);
|
||||||
|
|
||||||
const handleClickRestartAndUpdate = () => {
|
|
||||||
window.electron.restartAndInstallUpdate();
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const unsubscribe = window.electron.onAutoUpdaterEvent(
|
|
||||||
(event: AppUpdaterEvents) => {
|
|
||||||
if (event.type == "update-available") {
|
|
||||||
setNewVersion(event.info.version || "");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type == "update-downloaded") {
|
|
||||||
setShowUpdateSubheader(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
window.electron.checkForUpdates();
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
unsubscribe();
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const focusInput = () => {
|
const focusInput = () => {
|
||||||
setIsFocused(true);
|
setIsFocused(true);
|
||||||
inputRef.current?.focus();
|
inputRef.current?.focus();
|
||||||
|
@ -158,18 +126,7 @@ export function Header({ onSearch, onClear, search }: HeaderProps) {
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</header>
|
</header>
|
||||||
{showUpdateSubheader && (
|
<AutoUpdateSubHeader />
|
||||||
<header className={styles.subheader}>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className={styles.newVersionButton}
|
|
||||||
onClick={handleClickRestartAndUpdate}
|
|
||||||
>
|
|
||||||
<SyncIcon size={12} />
|
|
||||||
<small>{t("version_available", { version: newVersion })}</small>
|
|
||||||
</button>
|
|
||||||
</header>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue