From 3db6249f7174e8376b3afc7ec5b0ea772012f895 Mon Sep 17 00:00:00 2001 From: Prayag Prajapati Date: Sun, 10 Dec 2023 14:21:56 +0530 Subject: [PATCH] Add Updater UI #231 --- latest.json | 2 +- src-tauri/tauri.conf.json | 2 +- src/App.jsx | 136 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 2 deletions(-) diff --git a/latest.json b/latest.json index 3d2bb8a9..4ec296d0 100644 --- a/latest.json +++ b/latest.json @@ -1,5 +1,5 @@ { - "version": "0.0.2", + "version": "0.0.1", "notes": "See the assets to download and install this version.", "pub_date": "2023-12-08T10:15:47.030Z", "platforms": { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 20feecfb..929f1e18 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -104,7 +104,7 @@ "endpoints": [ "https://raw.githack.com/prayag17/JellyPlayer/main/latest.json" ], - "dialog": true, + "dialog": false, "pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDk5QkE0QjMzOEQyRUI5M0MKUldROHVTNk5NMHU2bVMvS3VNRWZHRzhuWE1TRlg3WHI1VHBtZjFvVy80alZ2UHc4T3BqcHVGOWwK" }, "windows": [ diff --git a/src/App.jsx b/src/App.jsx index 888171a5..21f5e751 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -16,6 +16,11 @@ import { } from "react-router-dom"; import { AnimatePresence, motion } from "framer-motion"; +import { + checkUpdate, + installUpdate, + onUpdaterEvent, +} from "@tauri-apps/api/updater"; import { relaunch } from "@tauri-apps/api/process"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; @@ -34,6 +39,10 @@ import DialogTitle from "@mui/material/DialogTitle"; import Button from "@mui/material/Button"; import Slide from "@mui/material/Slide"; import LinearProgress from "@mui/material/LinearProgress"; +import IconButton from "@mui/material/IconButton"; +import SvgIcon from "@mui/material/SvgIcon"; +import Typography from "@mui/material/Typography"; +import LoadingButton from "@mui/lab/LoadingButton"; // Routes import { ServerSetup } from "./routes/setup/server"; @@ -91,6 +100,7 @@ import { useQuery } from "@tanstack/react-query"; import { CircularProgress } from "@mui/material"; import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; import { useCentralStore } from "./utils/store/central.js"; +import { useSnackbar } from "notistack"; const anim = { initial: { @@ -158,6 +168,14 @@ const AnimationWrapper = () => { ); }; +// const unlisten = await onUpdaterEvent(({ error, status }) => { +// // This will log all updater events, including status updates and errors. +// console.log("Updater event", error, status); +// }); + +// // you need to call unlisten if your handler goes out of scope, for example if the component is unmounted. +// unlisten(); + function App() { const [playbackDataLoading] = usePlaybackDataLoadStore((state) => [ state.isPending, @@ -204,6 +222,43 @@ function App() { "a", ], }); + const { enqueueSnackbar } = useSnackbar(); + + const [updateDialog, setUpdateDialog] = useState(false); + + /** + * @type {[import("@tauri-apps/api/updater.js").UpdateManifest, React.Dispatch]} + */ + const [updateInfo, setUpdateInfo] = useState(null); + + const [updateDialogButton, setUpdateDialogButton] = useState(false); + + useEffect(() => { + async function checkForUpdates() { + try { + const { shouldUpdate, manifest } = await checkUpdate(); + + if (shouldUpdate) { + setUpdateInfo(manifest); + setUpdateDialog(true); + // You could show a dialog asking the user if they want to install the update here. + console.log( + `Installing update ${manifest?.version}, ${manifest?.date}, ${manifest?.body}`, + ); + + // Install the update. This will also restart the app on Windows! + // await installUpdate(); + + // On macOS and Linux you will need to restart the app manually. + // You could use this step to display another confirmation dialog. + // await relaunch(); + } + } catch (error) { + console.error(error); + } + } + checkForUpdates(); + }, []); const [initialRoute] = useCentralStore((state) => [state.initialRoute]); @@ -237,6 +292,87 @@ function App() { }} /> )} + + {Boolean(updateInfo) && ( + <> + + Update Available! + + v{updateInfo.version} + + + + + {updateInfo.body} + + + + + + + + + + + + { + setUpdateDialogButton( + true, + ); + await installUpdate(); + enqueueSnackbar( + "Update has been installed! You need to relaunch JellyPlayer.", + { + variant: "success", + }, + ); + await relaunch(); + }} + > + Update + + + + )} + setEasterEgg(false)}