diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 59145c6f..8564b01d 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -243,6 +243,7 @@ "try_again": "Please, try again", "signout_modal_title": "Are you sure?", "cancel": "Cancel", - "signout": "Sign Out" + "signout": "Sign Out", + "playing_for": "Playing for {{amount}}" } } diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.json index 18ff1356..209279e2 100644 --- a/src/locales/pt/translation.json +++ b/src/locales/pt/translation.json @@ -243,6 +243,7 @@ "try_again": "Por favor, tente novamente", "cancel": "Cancelar", "signout": "Sair da conta", - "signout_modal_title": "Tem certeza?" + "signout_modal_title": "Tem certeza?", + "playing_for": "Jogando por {{amount}}" } } diff --git a/src/main/events/profile/update-profile.ts b/src/main/events/profile/update-profile.ts index 5a485a99..68d18c1b 100644 --- a/src/main/events/profile/update-profile.ts +++ b/src/main/events/profile/update-profile.ts @@ -27,8 +27,6 @@ const updateProfile = async ( displayName: string, newProfileImagePath: string | null ): Promise => { - console.log(newProfileImagePath); - if (!newProfileImagePath) { return (await patchUserProfile(displayName)).data; } diff --git a/src/main/services/hydra-api.ts b/src/main/services/hydra-api.ts index 31e69a8f..5cb94d9d 100644 --- a/src/main/services/hydra-api.ts +++ b/src/main/services/hydra-api.ts @@ -64,7 +64,7 @@ export class HydraApi { this.instance.interceptors.request.use( (request) => { console.log(" ---- REQUEST -----"); - console.log(request.method, request.url, request.data); + console.log(request.method, request.url, request.headers, request.data); return request; }, (error) => { diff --git a/src/renderer/src/app.tsx b/src/renderer/src/app.tsx index 71065545..ba98a653 100644 --- a/src/renderer/src/app.tsx +++ b/src/renderer/src/app.tsx @@ -21,6 +21,7 @@ import { closeToast, setUserDetails, setProfileBackground, + setRunningGame, } from "@renderer/features"; export interface AppProps { @@ -29,7 +30,7 @@ export interface AppProps { export function App() { const contentRef = useRef(null); - const { updateLibrary } = useLibrary(); + const { updateLibrary, library } = useLibrary(); const { clearDownload, setLastPacket } = useDownload(); @@ -95,6 +96,30 @@ export function App() { }); }, [dispatch, fetchUserDetails]); + useEffect(() => { + const unsubscribe = window.electron.onGamesRunning((gamesIds) => { + if (gamesIds.length) { + const lastGame = gamesIds.at(-1); + const libraryGame = library.find((library) => library.id == lastGame); + + if (libraryGame) { + dispatch( + setRunningGame({ + ...libraryGame, + sessionStartTimestamp: new Date().getTime(), + }) + ); + return; + } + } + dispatch(setRunningGame(null)); + }); + + return () => { + unsubscribe(); + }; + }, [dispatch]); + useEffect(() => { const listeners = [ window.electron.onSignIn(() => { diff --git a/src/renderer/src/components/sidebar/sidebar-profile.tsx b/src/renderer/src/components/sidebar/sidebar-profile.tsx index 4a89eff1..a7f8ea78 100644 --- a/src/renderer/src/components/sidebar/sidebar-profile.tsx +++ b/src/renderer/src/components/sidebar/sidebar-profile.tsx @@ -2,7 +2,7 @@ import { useNavigate } from "react-router-dom"; import { PersonIcon } from "@primer/octicons-react"; import * as styles from "./sidebar-profile.css"; -import { useUserDetails } from "@renderer/hooks"; +import { useAppSelector, useUserDetails } from "@renderer/hooks"; import { useMemo } from "react"; export function SidebarProfile() { @@ -10,6 +10,8 @@ export function SidebarProfile() { const { userDetails, profileBackground } = useUserDetails(); + const { runningGame } = useAppSelector((state) => state.runningGame); + const handleButtonClick = () => { if (userDetails === null) { window.electron.openExternal("https://auth.hydra.losbroxas.org"); @@ -48,7 +50,21 @@ export function SidebarProfile() {

{userDetails ? userDetails.displayName : "Sign in"}

+ + {userDetails && runningGame && ( +
+ {runningGame.title} +
+ )} + + {userDetails && runningGame && ( + + )} ); diff --git a/src/renderer/src/context/game-details/game-details.context.tsx b/src/renderer/src/context/game-details/game-details.context.tsx index fa8309f3..e55a5340 100644 --- a/src/renderer/src/context/game-details/game-details.context.tsx +++ b/src/renderer/src/context/game-details/game-details.context.tsx @@ -111,13 +111,13 @@ export function GameDetailsContextProvider({ useEffect(() => { const listeners = [ window.electron.onGamesRunning((gamesIds) => { - const newIsGameRunning = !!game?.id && gamesIds.includes(game.id); + const updatedIsGameRunning = !!game?.id && gamesIds.includes(game.id); - if (isGameRunning != newIsGameRunning) { + if (isGameRunning != updatedIsGameRunning) { updateGame(); } - setisGameRunning(newIsGameRunning); + setisGameRunning(updatedIsGameRunning); }), ]; diff --git a/src/renderer/src/features/index.ts b/src/renderer/src/features/index.ts index f3132520..fdc23e68 100644 --- a/src/renderer/src/features/index.ts +++ b/src/renderer/src/features/index.ts @@ -5,3 +5,4 @@ export * from "./download-slice"; export * from "./window-slice"; export * from "./toast-slice"; export * from "./user-details-slice"; +export * from "./running-game-slice"; diff --git a/src/renderer/src/features/running-game-slice.ts b/src/renderer/src/features/running-game-slice.ts new file mode 100644 index 00000000..1f432989 --- /dev/null +++ b/src/renderer/src/features/running-game-slice.ts @@ -0,0 +1,22 @@ +import { PayloadAction, createSlice } from "@reduxjs/toolkit"; +import { RunningGame } from "@types"; + +export interface RunningGameState { + runningGame: RunningGame | null; +} + +const initialState: RunningGameState = { + runningGame: null, +}; + +export const runningGameSlice = createSlice({ + name: "running-game", + initialState, + reducers: { + setRunningGame: (state, action: PayloadAction) => { + state.runningGame = action.payload; + }, + }, +}); + +export const { setRunningGame } = runningGameSlice.actions; diff --git a/src/renderer/src/pages/user/user.css.ts b/src/renderer/src/pages/user/user.css.ts index 3a9b4c86..f46e2416 100644 --- a/src/renderer/src/pages/user/user.css.ts +++ b/src/renderer/src/pages/user/user.css.ts @@ -72,6 +72,7 @@ export const profileAvatarEditOverlay = style({ export const profileInformation = style({ display: "flex", flexDirection: "column", + gap: `${SPACING_UNIT}px`, alignItems: "flex-start", color: "#c0c1c7", }); diff --git a/src/renderer/src/pages/user/user.tsx b/src/renderer/src/pages/user/user.tsx index bce22211..1068635e 100644 --- a/src/renderer/src/pages/user/user.tsx +++ b/src/renderer/src/pages/user/user.tsx @@ -28,8 +28,6 @@ export const User = () => { getUserProfile(); }, [getUserProfile]); - console.log(userProfile); - return (
diff --git a/src/renderer/src/store.ts b/src/renderer/src/store.ts index 9bc0c950..d01c54a5 100644 --- a/src/renderer/src/store.ts +++ b/src/renderer/src/store.ts @@ -7,6 +7,7 @@ import { userPreferencesSlice, toastSlice, userDetailsSlice, + runningGameSlice, } from "@renderer/features"; export const store = configureStore({ @@ -18,6 +19,7 @@ export const store = configureStore({ download: downloadSlice.reducer, toast: toastSlice.reducer, userDetails: userDetailsSlice.reducer, + runningGame: runningGameSlice.reducer, }, }); diff --git a/src/types/index.ts b/src/types/index.ts index 153fdc9e..cda9bf72 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -127,6 +127,14 @@ export interface Game { export type LibraryGame = Omit; +export interface RunningGame { + title: string; + iconUrl: string; + objectID: string; + shop: GameShop; + sessionStartTimestamp: number; +} + export interface DownloadProgress { downloadSpeed: number; timeRemaining: number;