feat: progress bar and trying to animate

This commit is contained in:
Zamitto 2024-05-20 13:17:55 -03:00
parent f90dd82cbd
commit 3062b88f4a
4 changed files with 58 additions and 18 deletions

View File

@ -65,11 +65,11 @@ const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
total: total, total: total,
delta: 123, delta: 123,
transferred: (total * i) / 5, transferred: (total * i) / 5,
percent: (total * i) / 5 / total, percent: ((total * i) / 5 / total) * 100,
bytesPerSecond: 4568, bytesPerSecond: 4568,
}, },
}); });
await sleep(500); await sleep(1000);
} }
sendEvent({ type: "update-downloaded" }); sendEvent({ type: "update-downloaded" });

View File

@ -57,8 +57,8 @@ export class WindowManager {
if (this.splashWindow) return; if (this.splashWindow) return;
this.splashWindow = new BrowserWindow({ this.splashWindow = new BrowserWindow({
width: 400, width: 380,
height: 400, height: 380,
frame: false, frame: false,
alwaysOnTop: false, alwaysOnTop: false,
webPreferences: { webPreferences: {

View File

@ -1,12 +1,11 @@
import { style } from "@vanilla-extract/css"; import { style } from "@vanilla-extract/css";
import { SPACING_UNIT } from "../../theme.css"; import { SPACING_UNIT, vars } from "../../theme.css";
export const main = style({ export const main = style({
width: "100%", width: "100%",
height: "100%", height: "100%",
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
gap: `${SPACING_UNIT * 3}px`,
padding: `${SPACING_UNIT * 3}px`, padding: `${SPACING_UNIT * 3}px`,
flex: "1", flex: "1",
overflowY: "auto", overflowY: "auto",
@ -14,5 +13,41 @@ export const main = style({
}); });
export const splashIcon = style({ export const splashIcon = style({
width: "250px", width: "75%",
});
export const updateInfoSection = style({
width: "100%",
display: "flex",
flexDirection: "column",
gap: `${SPACING_UNIT * 2}px`,
flex: "1",
overflowY: "auto",
alignItems: "center",
justifyContent: "center",
});
export const progressBarContainer = style({
width: "100%",
height: "18px",
borderRadius: "24px",
display: "flex",
alignItems: "center",
position: "relative",
justifyContent: "center",
backgroundColor: vars.color.darkBackground,
border: `solid 1px ${vars.color.border}`,
overflow: "hidden",
});
export const progressBarFill = style({
position: "absolute",
transition: "width 0.1s",
height: "100%",
left: 0,
background: vars.color.background,
});
export const progressBarText = style({
zIndex: 2,
}); });

View File

@ -16,14 +16,9 @@ export default function Splash() {
console.log("subscribing"); console.log("subscribing");
const unsubscribe = window.electron.onAutoUpdaterEvent( const unsubscribe = window.electron.onAutoUpdaterEvent(
(event: AppUpdaterEvents) => { (event: AppUpdaterEvents) => {
console.log("event from screen: " + event.type);
setStatus(event); setStatus(event);
switch (event.type) { switch (event.type) {
case "download-progress":
console.log(event.info);
break;
case "checking-for-updates":
break;
case "error": case "error":
window.electron.continueToMainWindow(); window.electron.continueToMainWindow();
break; break;
@ -55,14 +50,24 @@ export default function Splash() {
case "download-progress": case "download-progress":
return ( return (
<> <>
<p>Baixando atualização {newVersion}</p> <p>Baixando versão {newVersion}</p>
<p>{status.info.percent.toFixed(2)} %</p> <div className={styles.progressBarContainer}>
<div
className={styles.progressBarFill}
style={{ width: `${status.info.percent}%` }}
></div>
<span className={styles.progressBarText}>
{status.info.percent.toFixed(2)} %
</span>
</div>
</> </>
); );
case "checking-for-updates": case "checking-for-updates":
return <p>Buscando atualizações</p>; return <p>Buscando atualizações</p>;
case "update-available": case "update-available":
return <p>Atualização {status.info.version} encontrada</p>; return <p>Versão {status.info.version} encontrada</p>;
case "update-downloaded":
return <p>Reiniciando e aplicando atualização</p>;
default: default:
return <></>; return <></>;
} }
@ -70,8 +75,8 @@ export default function Splash() {
return ( return (
<main className={styles.main}> <main className={styles.main}>
<img src={icon} className={styles.splashIcon} alt="" /> <img src={icon} className={styles.splashIcon} alt="Hydra Logo" />
{renderSwitch()} <section className={styles.updateInfoSection}>{renderSwitch()}</section>
</main> </main>
); );
} }