/** @format */ import React, { useState, useEffect } from "react"; import useKonami from "react-use-konami"; import { ThemeProvider } from "@mui/material/styles"; import { SnackbarProvider } from "notistack"; import { Routes, Route, useNavigate, useLocation, Outlet, Navigate, } 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"; // Theming import CssBaseline from "@mui/material/CssBaseline"; import { theme } from "./theme"; import "./styles/global.scss"; // MUI import Dialog from "@mui/material/Dialog"; import DialogActions from "@mui/material/DialogActions"; import DialogContent from "@mui/material/DialogContent"; import DialogContentText from "@mui/material/DialogContentText"; 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"; import ServerList from "./routes/setup/serverList/index.jsx"; import Home from "./routes/home"; import { UserLogin, LoginWithImage, UserLoginManual } from "./routes/login"; import LibraryView from "./routes/library"; import ItemDetail from "./routes/item"; import SeriesTitlePage from "./routes/series/index.jsx"; import FavoritePage from "./routes/favorite/index.jsx"; import Settings from "./routes/settings"; import About from "./routes/about"; import SearchPage from "./routes/search"; import { VideoPlayer } from "./routes/player/videoPlayer.jsx"; import Markdown from "react-markdown"; import { SideMenu } from "./components/menu/sidemenu.jsx"; import { AppBar } from "./components/appBar/appBar.jsx"; // Fonts import "@fontsource/noto-sans/100.css"; import "@fontsource/noto-sans/100-italic.css"; import "@fontsource/noto-sans/200.css"; import "@fontsource/noto-sans/200-italic.css"; import "@fontsource/noto-sans/300.css"; import "@fontsource/noto-sans/300-italic.css"; import "@fontsource/noto-sans/400.css"; import "@fontsource/noto-sans/400-italic.css"; import "@fontsource/noto-sans/500.css"; import "@fontsource/noto-sans/500-italic.css"; import "@fontsource/noto-sans/600.css"; import "@fontsource/noto-sans/600-italic.css"; import "@fontsource/noto-sans/700.css"; import "@fontsource/noto-sans/700-italic.css"; import "@fontsource/noto-sans/800.css"; import "@fontsource/noto-sans/800-italic.css"; import "@fontsource/noto-sans/900.css"; import "@fontsource/noto-sans/900-italic.css"; import "material-symbols"; import "@fontsource-variable/jetbrains-mono"; import { useBackdropStore } from "./utils/store/backdrop.js"; import { usePlaybackDataLoadStore } from "./utils/store/playback.js"; import BoxSetTitlePage from "./routes/boxset/index.jsx"; import PersonTitlePage from "./routes/person/index.jsx"; import MusicAlbumTitlePage from "./routes/album/index.jsx"; import AudioPlayer from "./components/playback/audioPlayer/index.jsx"; import { useAudioPlayback } from "./utils/store/audioPlayback.js"; import ArtistTitlePage from "./routes/artist/index.jsx"; import EpisodeTitlePage from "./routes/episode/index.jsx"; import PlaylistTitlePage from "./routes/playlist/index.jsx"; import { useApi } from "./utils/store/api.js"; 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"; import { ErrorBoundary } from "react-error-boundary"; import { ErrorNotice } from "./components/notices/errorNotice/errorNotice.jsx"; const anim = { initial: { transform: "scale(0.98)", opacity: 0, }, animate: { transform: "scale(1)", opacity: 1, }, exit: { transform: "sscale(1.02)", opacity: 0, }, }; const LoginRoute = () => { const navigate = useNavigate(); const [api] = useApi((state) => [state.api]); const usersList = useQuery({ queryKey: ["public-users"], queryFn: async () => { const result = await getUserApi(api).getPublicUsers(); return result.data; }, enabled: Boolean(api), }); if (usersList.isSuccess && !usersList.isFetching) { if (usersList.data.length > 0) { navigate("/login/users"); } else { navigate("/login/manual"); } } return (
); }; const AnimationWrapper = () => { return ( ); }; // 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, ]); const handleRelaunch = async (event, reason) => { if (reason && reason == "backdropClick") { return; } await relaunch(); }; const location = useLocation(); useEffect(() => { window.scrollTo(0, 0); }, [location.key]); const [audioPlayerVisible] = useAudioPlayback((state) => [state.display]); const [backdropUrl, backdropId] = useBackdropStore((state) => [ state.backdropUrl, state.backdropId, ]); const [backdropLoading, setBackdropLoading] = useState(true); const [easterEgg, setEasterEgg] = useState(false); const sixtyNine = () => { setEasterEgg(true); }; useKonami(sixtyNine, { code: [ "ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "b", "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( `Update found : ${manifest?.version}, ${manifest?.date}`, ); // 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]); const navigate = useNavigate(); if (!initialRoute) { return (
); } else if (initialRoute) { return ( {playbackDataLoading && ( )} {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)} sx={{ background: "black", }} > {/* Show Dialog if server not reachable */}
{ setBackdropLoading(true); }} onLoad={() => { setBackdropLoading(false); }} loading="eager" style={{ transition: "opacity 0.8s", }} />
{/* */} {/* } > */} } // element={<>} /> Unable to reach server Unable to connect to the jellyfin server. } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } errorElement={
Error
} /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* */}
); } } export default App;