From db6fa1cc911f47c1167084e7a003f728a567f34c Mon Sep 17 00:00:00 2001 From: Prayag Prajapati Date: Thu, 11 Jan 2024 15:11:33 +0530 Subject: [PATCH 1/6] Upload build artifacts --- .github/workflows/continuous-integration.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1bfd2cd..4e1e0bc 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -112,3 +112,9 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }} TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }} + + - name: Upload build Artifacts + uses: actions/upload-artifact@v4 + with: + name: JellyPlayer-${{matrix.os}}-dev${{github.sha}} + path: src-tauri/target/release/bundle/* From 5feb6c2bb67a85755104c43428933da61d3f1289 Mon Sep 17 00:00:00 2001 From: DanCodes Date: Thu, 11 Jan 2024 11:32:08 +0000 Subject: [PATCH 2/6] feat: store access token instead of password --- src/main.tsx | 42 ++++++++++++++++++++------------------ src/routes/login/index.jsx | 4 ++-- src/utils/storage/user.ts | 6 +++--- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index aa87bbc..c497810 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,5 +1,10 @@ import { Api } from "@jellyfin/sdk"; -import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; +import { + QueryClient, + QueryClientProvider, + useQuery, +} from "@tanstack/react-query"; import { enqueueSnackbar } from "notistack"; import React from "react"; import ReactDOM from "react-dom/client"; @@ -33,24 +38,12 @@ const handleAuthError = async () => { setInitialRoute("/login/index"); }; -const authenticateUser = async ( - address: string, - api: Api, - user: UserStore["user"], -) => { +const authenticateUser = async (address: string, user: UserStore["user"]) => { try { - const auth = await api.authenticateUserByName(user.Name, user.Password); + console.log(user); + createApi(address, user.AccessToken); - if (auth.status !== 200 || !auth.data.AccessToken) { - enqueueSnackbar("Incorrect Username or Password!", { - variant: "error", - }); - - handleAuthError(); - } else { - createApi(address, auth.data.AccessToken); - setInitialRoute("/home"); - } + setInitialRoute("/home"); } catch (error) { console.error(error); setInitialRoute("/error"); @@ -64,7 +57,7 @@ const init = async () => { } const defaultServerOnDisk = await getDefaultServer(); - console.log(defaultServerOnDisk) + console.log(defaultServerOnDisk); if (defaultServerOnDisk) { const defaultServerInfo = await getServer(defaultServerOnDisk); @@ -84,14 +77,23 @@ const init = async () => { if (userOnDisk) { try { - const authApi = useApi.getState().api; + let authApi = useApi.getState().api; if (!authApi) { handleAuthError(); return; } - await authenticateUser(defaultServerInfo.address, authApi, userOnDisk); + await authenticateUser(defaultServerInfo.address, userOnDisk); + + authApi = useApi.getState().api!; + + const user = await getUserApi(authApi).getCurrentUser(); + + if (!user) { + await delUser(); + handleAuthError(); + } } catch (error) { console.error(error); handleAuthError(); diff --git a/src/routes/login/index.jsx b/src/routes/login/index.jsx index e020407..3b82ef9 100644 --- a/src/routes/login/index.jsx +++ b/src/routes/login/index.jsx @@ -122,7 +122,7 @@ export const LoginWithImage = () => { const user = await authUser(); sessionStorage.setItem("accessToken", user.data.AccessToken); if (rememberMe === true) { - saveUser(userName, password.password); + saveUser(userName, user.data.AccessToken); } event.emit("set-api-accessToken", api.basePath); setLoading(false); @@ -435,7 +435,7 @@ export const UserLoginManual = () => { const user = await authUser(); sessionStorage.setItem("accessToken", user.data.AccessToken); if (rememberMe === true) { - saveUser(userName, password.password); + saveUser(userName, user.data.AccessToken); } event.emit("set-api-accessToken", api.basePath); // setAccessToken(user.data.AccessToken) diff --git a/src/utils/storage/user.ts b/src/utils/storage/user.ts index f5a484f..ba5a667 100644 --- a/src/utils/storage/user.ts +++ b/src/utils/storage/user.ts @@ -3,7 +3,7 @@ import { Store } from "tauri-plugin-store-api"; export interface UserStore { user: { Name: string; - Password: string; + AccessToken: string; }; } @@ -12,10 +12,10 @@ const user = new Store(".user.dat"); /** * Set User details to .user.dat */ -const saveUser = async (userName: string, userPassword?: string) => { +const saveUser = async (userName: string, accessToken: string) => { user.set("user", { Name: userName, - Password: userPassword, + AccessToken: accessToken, }); await user.save(); From 1af7428869c41c0a773d733d9d2326b864118ade Mon Sep 17 00:00:00 2001 From: Prayag Prajapati Date: Thu, 11 Jan 2024 18:17:41 +0530 Subject: [PATCH 3/6] Fix artifact naminng in CI --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 4e1e0bc..7f002ce 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -116,5 +116,5 @@ jobs: - name: Upload build Artifacts uses: actions/upload-artifact@v4 with: - name: JellyPlayer-${{matrix.os}}-dev${{github.sha}} + name: JellyPlayer-${{ matrix.platform }}-dev${{ github.sha }} path: src-tauri/target/release/bundle/* From 4acf57cfd040a7a20319d858a911c22518eb2156 Mon Sep 17 00:00:00 2001 From: DanCodes Date: Thu, 11 Jan 2024 14:51:37 +0000 Subject: [PATCH 4/6] chore: cleanup code --- src/App.tsx | 1 - src/main.tsx | 9 +-------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index c1267d3..51b3abc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -161,7 +161,6 @@ function App() { undefined, ); - // biome-ignore lint/correctness/useExhaustiveDependencies: this dependency is required useEffect(() => { window.scrollTo(0, 0); }, [location.key]); diff --git a/src/main.tsx b/src/main.tsx index c497810..7230283 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,11 +1,5 @@ -import { Api } from "@jellyfin/sdk"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; -import { - QueryClient, - QueryClientProvider, - useQuery, -} from "@tanstack/react-query"; -import { enqueueSnackbar } from "notistack"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import React from "react"; import ReactDOM from "react-dom/client"; import { BrowserRouter as Router } from "react-router-dom"; @@ -40,7 +34,6 @@ const handleAuthError = async () => { const authenticateUser = async (address: string, user: UserStore["user"]) => { try { - console.log(user); createApi(address, user.AccessToken); setInitialRoute("/home"); From 9d78a5ed5d94792a6cf527ca27f27627f7f98d23 Mon Sep 17 00:00:00 2001 From: DanCodes Date: Thu, 11 Jan 2024 15:40:39 +0000 Subject: [PATCH 5/6] feat: move init to app --- src/App.tsx | 110 +++++++++++++++++++++++++++++++++- src/main.tsx | 111 +++++------------------------------ src/routes/library/index.jsx | 2 +- src/routes/login/index.jsx | 2 +- 4 files changed, 125 insertions(+), 100 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 51b3abc..10256dc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -95,16 +95,27 @@ import AudioPlayer from "./components/playback/audioPlayer/index.jsx"; // Utils import { useAudioPlayback } from "./utils/store/audioPlayback.js"; import { useBackdropStore } from "./utils/store/backdrop.js"; -import { useCentralStore } from "./utils/store/central.js"; +import { setInitialRoute, useCentralStore } from "./utils/store/central.js"; import { usePlaybackDataLoadStore } from "./utils/store/playback"; // 3rd Party +import { Api } from "@jellyfin/sdk"; +import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { CircularProgress } from "@mui/material"; import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; import { useSnackbar } from "notistack"; import { ErrorBoundary } from "react-error-boundary"; import { EasterEgg } from "./components/utils/easterEgg.jsx"; import { handleRelaunch } from "./utils/misc/relaunch"; +import { + delServer, + getAllServers, + getDefaultServer, + getServer, + setDefaultServer, +} from "./utils/storage/servers"; +import { UserStore, delUser, getUser } from "./utils/storage/user"; +import { createApi, useApi } from "./utils/store/api"; // const anim = { // initial: { @@ -138,7 +149,104 @@ import { handleRelaunch } from "./utils/misc/relaunch"; // ); // }; +const handleAuthError = async () => { + await delUser(); + setInitialRoute("/login/index"); +}; + +const authenticateUser = async (address: string, user: UserStore["user"]) => { + try { + createApi(address, user.AccessToken); + setInitialRoute("/home"); + } catch (error) { + console.error(error); + setInitialRoute("/error"); + } +}; + +const init = async () => { + if (window.location.pathname !== "/") { + window.location.href = "/"; + return; + } + + const defaultServerOnDisk = await getDefaultServer(); + + if (defaultServerOnDisk) { + const defaultServerInfo = await getServer(defaultServerOnDisk); + if (!defaultServerInfo) { + await setDefaultServer(null); + await delServer(defaultServerOnDisk); + + const servers = await getAllServers(); + + setInitialRoute(servers.length > 0 ? "/servers/list" : "/setup/server"); + + return; + } + + const userOnDisk = await getUser(); + createApi(defaultServerInfo.address, ""); + + if (userOnDisk) { + try { + let authApi = useApi.getState().api; + + if (!authApi) { + handleAuthError(); + return; + } + + await authenticateUser(defaultServerInfo.address, userOnDisk); + + authApi = useApi.getState().api!; + + const user = await getUserApi(authApi).getCurrentUser(); + + if (!user) { + await delUser(); + handleAuthError(); + } + } catch (error) { + console.error(error); + handleAuthError(); + } + } else { + setInitialRoute("/login/index"); + } + } else { + setInitialRoute("/setup/server"); + } +}; + function App() { + const [appReady, setAppReady] = useState(false); + + useEffect(() => { + init().then(() => { + setAppReady(true); + }); + }, []); + + if (!appReady) { + return ( +
+ +
+ ); + } + + return ; +} + +function AppReady() { const [audioPlayerVisible] = useAudioPlayback((state) => [state.display]); const { enqueueSnackbar } = useSnackbar(); diff --git a/src/main.tsx b/src/main.tsx index 7230283..866c021 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,25 +1,16 @@ -import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; -import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import React from "react"; import ReactDOM from "react-dom/client"; import { BrowserRouter as Router } from "react-router-dom"; + +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; + import App from "./App"; -import { - delServer, - getAllServers, - getDefaultServer, - getServer, - setDefaultServer, -} from "./utils/storage/servers"; -import { UserStore, delUser, getUser } from "./utils/storage/user"; -import { createApi, useApi } from "./utils/store/api"; -import { setInitialRoute } from "./utils/store/central"; const queryClient = new QueryClient({ defaultOptions: { queries: { networkMode: "always", - gcTime: 120000, + staleTime: 2 * 60 * 1000, // 2 minutes }, mutations: { networkMode: "always", @@ -27,88 +18,14 @@ const queryClient = new QueryClient({ }, }); -const handleAuthError = async () => { - await delUser(); - setInitialRoute("/login/index"); -}; +ReactDOM.createRoot(document.getElementById("root")!).render( + + + + + + + , +); -const authenticateUser = async (address: string, user: UserStore["user"]) => { - try { - createApi(address, user.AccessToken); - - setInitialRoute("/home"); - } catch (error) { - console.error(error); - setInitialRoute("/error"); - } -}; - -const init = async () => { - if (window.location.pathname !== "/") { - window.location.href = "/"; - return; - } - - const defaultServerOnDisk = await getDefaultServer(); - console.log(defaultServerOnDisk); - - if (defaultServerOnDisk) { - const defaultServerInfo = await getServer(defaultServerOnDisk); - if (!defaultServerInfo) { - await setDefaultServer(null); - await delServer(defaultServerOnDisk); - - const servers = await getAllServers(); - - setInitialRoute(servers.length > 0 ? "/servers/list" : "/setup/server"); - - return; - } - - const userOnDisk = await getUser(); - createApi(defaultServerInfo.address, ""); - - if (userOnDisk) { - try { - let authApi = useApi.getState().api; - - if (!authApi) { - handleAuthError(); - return; - } - - await authenticateUser(defaultServerInfo.address, userOnDisk); - - authApi = useApi.getState().api!; - - const user = await getUserApi(authApi).getCurrentUser(); - - if (!user) { - await delUser(); - handleAuthError(); - } - } catch (error) { - console.error(error); - handleAuthError(); - } - } else { - setInitialRoute("/login/index"); - } - } else { - setInitialRoute("/setup/server"); - } -}; - -init().then(() => { - ReactDOM.createRoot(document.getElementById("root")!).render( - - - - - - - , - ); - - document.querySelector(".app-loading")!.setAttribute("style", "display:none"); -}); +document.querySelector(".app-loading")!.setAttribute("style", "display:none"); diff --git a/src/routes/library/index.jsx b/src/routes/library/index.jsx index c1618dc..e16ecee 100644 --- a/src/routes/library/index.jsx +++ b/src/routes/library/index.jsx @@ -96,7 +96,7 @@ const LibraryView = () => { }, enabled: !!user.data, networkMode: "always", - gcTime: 0, + staleTime: 0, }); const [isPlayed, setIsPlayed] = useState(false); diff --git a/src/routes/login/index.jsx b/src/routes/login/index.jsx index 3b82ef9..bd922af 100644 --- a/src/routes/login/index.jsx +++ b/src/routes/login/index.jsx @@ -256,7 +256,7 @@ export const UserLogin = () => { const users = await getUserApi(api).getPublicUsers(); return users.data; }, - gcTime: 0, + staleTime: 0, }); const handleInitiateQuickConnect = useMutation({ From 9a5dce5ac9cdb3c0781e57816028ce2a03915554 Mon Sep 17 00:00:00 2001 From: DanCodes Date: Thu, 11 Jan 2024 15:50:48 +0000 Subject: [PATCH 6/6] style: fade out the loading screen --- index.html | 6 ++++++ src/main.tsx | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 2879328..80b072e 100644 --- a/index.html +++ b/index.html @@ -18,6 +18,12 @@ align-items: center; justify-content: center; flex-direction: column; + transition: opacity 0.25s ease-in-out; + } + + .app-loading.hidden { + opacity: 0; + pointer-events: none; } .app-loading-logo { diff --git a/src/main.tsx b/src/main.tsx index 866c021..86124b1 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -28,4 +28,4 @@ ReactDOM.createRoot(document.getElementById("root")!).render( , ); -document.querySelector(".app-loading")!.setAttribute("style", "display:none"); +document.querySelector(".app-loading")!.classList.toggle("hidden");