mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: events working
This commit is contained in:
parent
3b17953a82
commit
811878e364
12 changed files with 182 additions and 82 deletions
8
src/renderer/src/declaration.d.ts
vendored
8
src/renderer/src/declaration.d.ts
vendored
|
@ -1,4 +1,5 @@
|
|||
import type {
|
||||
AppUpdaterEvents,
|
||||
CatalogueCategory,
|
||||
CatalogueEntry,
|
||||
Game,
|
||||
|
@ -92,7 +93,12 @@ declare global {
|
|||
platform: NodeJS.Platform;
|
||||
|
||||
/* Splash */
|
||||
checkForUpdates: (cb: (value: AppUpdaterEvents) => void) => Promise<void>;
|
||||
onAutoUpdaterEvent: (
|
||||
cb: (event: AppUpdaterEvents) => void
|
||||
) => () => Electron.IpcRenderer;
|
||||
checkForUpdates: () => Promise<void>;
|
||||
restartAndInstallUpdate: () => Promise<void>;
|
||||
continueToMainWindow: () => Promise<void>;
|
||||
}
|
||||
|
||||
interface Window {
|
||||
|
|
|
@ -48,9 +48,9 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
|
|||
<Provider store={store}>
|
||||
<HashRouter>
|
||||
<Routes>
|
||||
<Route path="/" Component={Splash} />
|
||||
<Route path="/splash" Component={Splash} />
|
||||
<Route element={<App />}>
|
||||
<Route path="/teste" Component={Home} />
|
||||
<Route path="/" Component={Home} />
|
||||
<Route path="/catalogue" Component={Catalogue} />
|
||||
<Route path="/downloads" Component={Downloads} />
|
||||
<Route path="/game/:shop/:objectID" Component={GameDetails} />
|
||||
|
|
|
@ -14,5 +14,5 @@ export const main = style({
|
|||
});
|
||||
|
||||
export const splashIcon = style({
|
||||
width: "300px",
|
||||
width: "250px",
|
||||
});
|
||||
|
|
|
@ -3,22 +3,73 @@ import * as styles from "./splash.css";
|
|||
import { themeClass } from "../../theme.css";
|
||||
|
||||
import "../../app.css";
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { AppUpdaterEvents } from "@types";
|
||||
|
||||
document.body.classList.add(themeClass);
|
||||
|
||||
export default function Splash() {
|
||||
const [status, setStatus] = useState<AppUpdaterEvents | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
window.electron.checkForUpdates((event) => {
|
||||
console.log("-----------");
|
||||
console.log(event);
|
||||
});
|
||||
console.log("subscribing");
|
||||
const unsubscribe = window.electron.onAutoUpdaterEvent(
|
||||
(event: AppUpdaterEvents) => {
|
||||
console.log("event from screen: " + event.type);
|
||||
setStatus(event);
|
||||
switch (event.type) {
|
||||
case "download-progress":
|
||||
console.log(event.info);
|
||||
break;
|
||||
case "checking-for-updates":
|
||||
break;
|
||||
case "error":
|
||||
window.electron.continueToMainWindow();
|
||||
break;
|
||||
case "update-available":
|
||||
break;
|
||||
case "update-cancelled":
|
||||
window.electron.continueToMainWindow();
|
||||
break;
|
||||
case "update-downloaded":
|
||||
window.electron.restartAndInstallUpdate();
|
||||
break;
|
||||
case "update-not-available":
|
||||
window.electron.continueToMainWindow();
|
||||
break;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
window.electron.checkForUpdates();
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}, []);
|
||||
|
||||
const renderSwitch = () => {
|
||||
switch (status?.type) {
|
||||
case "download-progress":
|
||||
return (
|
||||
<>
|
||||
<p>Baixando</p>
|
||||
<p>{status.info.percent}</p>
|
||||
</>
|
||||
);
|
||||
case "checking-for-updates":
|
||||
return <p>Buscando atualizações</p>;
|
||||
case "update-available":
|
||||
return <p>Atualização encontrada</p>;
|
||||
default:
|
||||
return <></>;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<main className={styles.main}>
|
||||
<img src={icon} className={styles.splashIcon} alt="" />
|
||||
<p>Procurando atualizaçoes</p>
|
||||
{renderSwitch()}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue