feat: implement a new updator

This commit is contained in:
--remove-section committed 2026-02-03 01:20:33 +05:30
1 parent 73e3b865ab
commit 1defb53945
13 files changed
+1042 -94

No files matched your search

+256 -69
View File
@@ -1,18 +1,19 @@
import { LoadingButton } from "@mui/lab";
import {
Box,
Button,
Chip,
CircularProgress,
Dialog,
DialogActions,
DialogContent,
DialogContentText,
DialogTitle,
Link,
Stack,
Typography,
} from "@mui/material";
import { relaunch } from "@tauri-apps/plugin-process";
import { type Update, check } from "@tauri-apps/plugin-updater";
import { open } from "@tauri-apps/plugin-shell";
import { check, type Update } from "@tauri-apps/plugin-updater";
import { useSnackbar } from "notistack";
import React, { useLayoutEffect, useState } from "react";
import React, { useCallback, useLayoutEffect, useState } from "react";
export default function Updater() {
const [updateDialog, setUpdateDialog] = useState(false);
@@ -23,8 +24,8 @@ export default function Updater() {
async function checkForUpdates() {
try {
const update = await check();
if (update?.available) {
if (update) {
// console.log(update);
setUpdateInfo(update);
setUpdateDialog(true);
@@ -37,95 +38,281 @@ export default function Updater() {
checkForUpdates();
}, []);
const { enqueueSnackbar } = useSnackbar();
const [downloadProgress, setDownloadProgress] = useState(0);
const [downloadSize, setDownloadSize] = useState(0);
const handleUpdate = useCallback(async () => {
try {
setUpdateDialogButton(true);
await updateInfo?.downloadAndInstall((e) => {
switch (e.event) {
case "Started":
setDownloadSize(e.data.contentLength ?? 0);
break;
case "Progress":
setDownloadProgress((s) => s + e.data.chunkLength);
break;
case "Finished":
setDownloadProgress(downloadSize);
break;
}
});
enqueueSnackbar(
"Update has been installed! You need to relaunch Blink.",
{
variant: "success",
},
);
await relaunch();
} catch (error) {
console.error(error);
enqueueSnackbar(`Failed to update Blink. ${error}`, { variant: "error" });
}
setUpdateDialogButton(false);
}, [enqueueSnackbar, updateInfo, downloadSize]);
if (!updateInfo) return null;
return (
<Dialog
open={updateDialog}
maxWidth="xs"
PaperProps={{
style: {
borderRadius: "20px",
fullWidth
slotProps={{
paper: {
className: "glass",
style: {
borderRadius: "24px",
overflow: "hidden",
},
},
className: "glass",
}}
sx={{
"& img": {
width: "100%",
backdrop: {
style: {
backdropFilter: "blur(5px)",
backgroundColor: "rgba(0, 0, 0, 0.5)",
},
},
}}
>
<DialogTitle variant="h5" align="center" textAlign={"center"}>
Update Available!
</DialogTitle>
<Box
sx={{
position: "absolute",
top: 0,
left: 0,
right: 0,
height: "140px",
opacity: 0.5,
background: (theme) =>
`linear-gradient(135deg, ${theme.palette.primary.main} 0%, ${theme.palette.secondary.main} 100%)`,
zIndex: 0,
filter: "blur(40px)",
transform: "translateY(-50%) scale(1.5)",
}}
/>
<DialogContent
className="flex flex-center"
style={{ gap: "0.5em", padding: "0 2em 1em 2em", flexWrap: "wrap" }}
sx={{ position: "relative", zIndex: 1, pt: 5, pb: 3, px: 3 }}
>
<Chip
icon={<span className="material-symbols-rounded">update</span>}
label={`v${updateInfo.currentVersion}`}
variant="outlined"
/>
<span className="material-symbols-rounded">arrow_right_alt</span>
<Chip
icon={<span className="material-symbols-rounded">update</span>}
label={`v${updateInfo.version}`}
variant="outlined"
/>
<DialogContentText sx={{ width: "100%" }}>
<Link
href={`https://github.com/prayag17/Blink/releases/v${updateInfo.version}`}
target="_blank"
<Stack alignItems="center" spacing={3}>
<Box
sx={{
width: 72,
height: 72,
borderRadius: "50%",
display: "flex",
alignItems: "center",
justifyContent: "center",
background: (theme) =>
`linear-gradient(135deg, ${theme.palette.primary.main} 0%, ${theme.palette.secondary.main} 100%)`,
boxShadow: (theme) =>
`0 10px 25px -5px ${theme.palette.primary.main}80`,
mb: 1,
}}
>
Open changelog
</Link>
</DialogContentText>
<span
className="material-symbols-rounded"
style={{ fontSize: "36px", color: "white" }}
>
rocket_launch
</span>
</Box>
<Stack spacing={1} textAlign="center">
<Typography
variant="h5"
fontWeight="900"
sx={{
background: (theme) =>
`linear-gradient(135deg, ${theme.palette.primary.light} 0%, ${theme.palette.secondary.light} 100%)`,
backgroundClip: "text",
WebkitBackgroundClip: "text",
color: "transparent",
}}
>
Update Available
</Typography>
<Typography
variant="body2"
color="text.secondary"
sx={{ maxWidth: "25ch" }}
>
A new version of Blink is ready for you.
</Typography>
</Stack>
<Stack
direction="row"
alignItems="center"
justifyContent="space-between"
sx={{
width: "100%",
bgcolor: "rgba(255,255,255,0.03)",
borderRadius: 4,
p: 2.5,
border: "1px solid rgba(255,255,255,0.05)",
}}
>
<Stack>
<Typography
variant="caption"
color="text.secondary"
sx={{ mb: 0.5 }}
>
Current
</Typography>
<Typography variant="subtitle1" fontWeight="bold">
v{updateInfo.currentVersion}
</Typography>
</Stack>
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "center",
width: 32,
height: 32,
borderRadius: "50%",
bgcolor: "rgba(255,255,255,0.05)",
}}
>
<span
className="material-symbols-rounded"
style={{
fontSize: "16px",
color: "rgba(255,255,255,0.5)",
}}
>
arrow_forward
</span>
</Box>
<Stack alignItems="flex-end">
<Typography
variant="caption"
color="primary.main"
sx={{ mb: 0.5 }}
>
New Version
</Typography>
<Typography
variant="subtitle1"
fontWeight="bold"
color="primary.main"
>
v{updateInfo.version}
</Typography>
</Stack>
</Stack>
<Button
onClick={() =>
open(
`https://github.com/prayag17/Blink/releases/v${updateInfo.version}`,
)
}
size="small"
sx={{
textTransform: "none",
cursor: "pointer",
color: "text.secondary",
borderRadius: "100px",
px: 2,
"&:hover": {
color: "primary.main",
bgcolor: "rgba(255,255,255,0.05)",
},
}}
endIcon={
<span
className="material-symbols-rounded"
style={{ fontSize: 16 }}
>
open_in_new
</span>
}
>
See what's new
</Button>
</Stack>
</DialogContent>
<DialogActions
style={{
padding: "1em",
sx={{
p: 3,
pt: 0,
justifyContent: "space-between",
gap: 1.5,
}}
className="flex flex-center"
>
{/* <Button
variant="outlined"
//@ts-ignore
color="white"
disabled={updateDialogButton}
onClick={() => setUpdateDialog(false)}
>
changelog
</Button> */}
<Button
color="error"
variant="contained"
disabled={updateDialogButton}
color="inherit"
size="large"
onClick={() => setUpdateDialog(false)}
style={{ borderRadius: "10px" }}
disableElevation
sx={{
borderRadius: "14px",
flex: 1,
color: "text.secondary",
height: 48,
"&:hover": {
bgcolor: "rgba(255,255,255,0.05)",
color: "text.primary",
},
}}
>
close
Later
</Button>
<LoadingButton
style={{ borderRadius: "10px" }}
color="success"
<Button
size="large"
variant="contained"
loading={updateDialogButton}
loadingIndicator="Updating..."
loadingIndicator={
<CircularProgress
size={24}
color="inherit"
value={downloadProgress / downloadSize}
/>
}
disableElevation
onClick={async () => {
setUpdateDialogButton(true);
await updateInfo.downloadAndInstall();
enqueueSnackbar("Update has been installed! You need to relaunch Blink.", {
variant: "success",
});
await relaunch();
onClick={handleUpdate}
sx={{
borderRadius: "14px",
flex: 1,
height: 48,
background: (theme) =>
`linear-gradient(135deg, ${theme.palette.primary.main} 0%, ${theme.palette.secondary.main} 100%)`,
boxShadow: (theme) =>
`0 8px 20px -5px ${theme.palette.primary.main}60`,
"&:hover": {
background: (theme) =>
`linear-gradient(135deg, ${theme.palette.primary.main} 0%, ${theme.palette.secondary.main} 100%)`,
opacity: 0.9,
boxShadow: (theme) =>
`0 12px 25px -5px ${theme.palette.primary.main}80`,
},
}}
>
Update
</LoadingButton>
</Button>
</DialogActions>
</Dialog>
);