feat: refresh gpgui helper download UI

This commit is contained in:
Kevin Yue committed 2026-08-07 23:11:09 +08:00
1 parent 32cd228c02
commit cd8eb1d9eb
8 files changed
+188 -84

No files matched your search

+62 -70
View File
@@ -7,104 +7,99 @@ import "./styles.css";
const appWindow = getCurrentWindow();
function useUpdateProgress() {
export default function App() {
const [error, setError] = useState(false);
const [progress, setProgress] = useState<number | null>(null);
useEffect(() => {
const unlisten = appWindow.listen("app://update-progress", (event) => {
setProgress(event.payload as number);
});
const unlisteners: Array<() => void> = [];
let disposed = false;
return () => {
unlisten.then((unlisten) => unlisten());
const startUpdate = async () => {
const progressUnlisten = await appWindow.listen("app://update-progress", (event) => {
setProgress(event.payload as number);
});
const errorUnlisten = await appWindow.listen("app://update-error", () => {
setError(true);
});
if (disposed) {
progressUnlisten();
errorUnlisten();
return;
}
unlisteners.push(progressUnlisten, errorUnlisten);
await appWindow.emit("app://update");
};
}, []);
return progress;
}
export default function App() {
const [error, setError] = useState(false);
useEffect(() => {
appWindow.emit("app://update");
const unlisten = appWindow.listen("app://update-error", () => {
setError(true);
});
void startUpdate();
return () => {
unlisten.then((unlisten) => unlisten());
disposed = true;
unlisteners.forEach((unlisten) => unlisten());
};
}, []);
const handleRetry = () => {
setError(false);
setProgress(null);
appWindow.emit("app://update");
};
return (
<>
<CssBaseline />
<Box
sx={{ position: "absolute", inset: 0 }}
display="flex"
alignItems="center"
px={2}
data-tauri-drag-region
>
<Box display="flex" alignItems="center" flex="1" data-tauri-drag-region>
<Box
component="img"
src={logo}
alt="logo"
sx={{ width: "4rem", height: "4rem" }}
data-tauri-drag-region
/>
<Box flex={1} ml={2}>
{error ? <DownloadFailed onRetry={handleRetry} /> : <DownloadIndicator />}
</Box>
<Box className="update-window" data-tauri-drag-region>
<Box
component="img"
src={logo}
alt="GPGUI"
className="update-logo"
data-tauri-drag-region
/>
<Box className="update-content" data-tauri-drag-region>
{error ? <DownloadFailed onRetry={handleRetry} /> : <DownloadIndicator progress={progress} />}
</Box>
</Box>
</>
);
}
function DownloadIndicator() {
const progress = useUpdateProgress();
function DownloadIndicator({ progress }: { progress: number | null }) {
return (
<>
<Typography variant="h1" fontSize="1rem" data-tauri-drag-region>
Updating the GUI components...
<Box className="update-status" data-tauri-drag-region>
<Typography component="h1" className="update-title" data-tauri-drag-region>
Downloading GPGUI
</Typography>
<Box mt={1}>
<LinearProgressWithLabel value={progress} />
</Box>
</>
<Typography className="update-description" data-tauri-drag-region>
This may take a moment.
</Typography>
<LinearProgressWithLabel value={progress} />
</Box>
);
}
function DownloadFailed({ onRetry }: { onRetry: () => void }) {
return (
<>
<Typography variant="h1" fontSize="1rem" data-tauri-drag-region>
Failed to update the GUI components.
<Box className="update-status error-status" data-tauri-drag-region>
<Typography component="h1" className="update-title" data-tauri-drag-region>
GPGUI couldn’t be downloaded
</Typography>
<Box mt={1} data-tauri-drag-region>
<Box className="error-actions" data-tauri-drag-region>
<Typography className="update-description" data-tauri-drag-region>
Check your connection and try again.
</Typography>
<Button
variant="contained"
color="primary"
size="small"
onClick={onRetry}
sx={{
textTransform: "none",
}}
className="retry-button"
>
Retry
</Button>
</Box>
</>
</Box>
);
}
@@ -112,24 +107,21 @@ function LinearProgressWithLabel(props: { value: number | null }) {
const { value } = props;
return (
<Box sx={{ display: "flex", alignItems: "center" }}>
<Box flex="1">
<Box className="progress-row">
<Box className="progress-track">
<LinearProgress
variant={value === null ? "indeterminate" : "determinate"}
value={value ?? 0}
sx={{
py: 1.2,
".MuiLinearProgress-bar": {
transition: "none",
},
}}
className="progress-bar"
aria-label="Update progress"
/>
</Box>
{value !== null && (
<Box sx={{ minWidth: 35, textAlign: "right", ml: 1 }}>
<Typography variant="body2" color="text.secondary">{`${Math.round(value)}%`}</Typography>
</Box>
)}
<Typography
className={`progress-label${value === null ? " progress-label-hidden" : ""}`}
aria-hidden={value === null}
>
{value === null ? "100%" : `${Math.round(value)}%`}
</Typography>
</Box>
);
}
@@ -4,7 +4,123 @@ body,
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
-webkit-user-select: none;
user-select: none;
cursor: default;
}
body {
background: #f6f5f4;
color: #2e3436;
font-family:
Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.update-window {
box-sizing: border-box;
display: flex;
align-items: center;
width: 100%;
height: 100%;
padding: 16px 18px;
gap: 15px;
background: #f6f5f4;
}
.update-logo {
flex: 0 0 auto;
width: 48px;
height: 48px;
}
.update-content,
.update-status {
min-width: 0;
width: 100%;
}
.update-title.MuiTypography-root {
color: #2e3436;
font-size: 16px;
font-weight: 600;
line-height: 1.25;
letter-spacing: -0.01em;
}
.update-description.MuiTypography-root {
margin-top: 3px;
color: #5e5c64;
font-size: 12px;
line-height: 1.4;
}
.progress-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 9px;
}
.progress-track {
flex: 1;
min-width: 0;
}
.progress-bar.MuiLinearProgress-root {
height: 6px;
overflow: hidden;
border-radius: 3px;
background-color: #d5d3d1;
}
.progress-bar .MuiLinearProgress-bar {
border-radius: 3px;
background: #3584e4;
transition: transform 180ms ease-out;
}
.progress-label.MuiTypography-root {
min-width: 36px;
color: #3d3846;
font-size: 12px;
font-variant-numeric: tabular-nums;
font-weight: 500;
text-align: right;
}
.progress-label-hidden.MuiTypography-root {
visibility: hidden;
}
.error-status .update-title.MuiTypography-root {
color: #9c2f2f;
}
.error-actions {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-top: 8px;
}
.error-actions .update-description.MuiTypography-root {
margin-top: 0;
}
.retry-button.MuiButton-root {
min-width: 68px;
border-radius: 8px;
background: #3584e4;
box-shadow: none;
font-size: 12px;
font-weight: 600;
line-height: 1.5;
text-transform: none;
}
.retry-button.MuiButton-root:hover {
background: #1c71d8;
box-shadow: none;
}