From e933cec888293e9650f8d508f3034845691d31e6 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Wed, 19 Jun 2024 14:37:26 -0300 Subject: [PATCH 01/19] feat: process watcher send list of running process --- src/main/services/process-watcher.ts | 16 ++++++++-------- src/preload/index.ts | 16 +++++----------- .../game-details/game-details.context.tsx | 12 ++++++------ src/renderer/src/declaration.d.ts | 5 +++-- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index ea1b6355..a9ac18d0 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -40,10 +40,6 @@ export const watchProcesses = async () => { const zero = gamesPlaytime.get(game.id) ?? 0; const delta = performance.now() - zero; - if (WindowManager.mainWindow) { - WindowManager.mainWindow.webContents.send("on-playtime", game.id); - } - await gameRepository.update(game.id, { playTimeInMilliseconds: game.playTimeInMilliseconds + delta, lastTimePlayed: new Date(), @@ -53,10 +49,14 @@ export const watchProcesses = async () => { gamesPlaytime.set(game.id, performance.now()); } else if (gamesPlaytime.has(game.id)) { gamesPlaytime.delete(game.id); - - if (WindowManager.mainWindow) { - WindowManager.mainWindow.webContents.send("on-game-close", game.id); - } } } + + if (WindowManager.mainWindow) { + const gamesRunningIds = Array.from(gamesPlaytime.keys()); + WindowManager.mainWindow.webContents.send( + "on-games-running", + gamesRunningIds + ); + } }; diff --git a/src/preload/index.ts b/src/preload/index.ts index 1fe259c8..f649c543 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -84,17 +84,11 @@ contextBridge.exposeInMainWorld("electron", { ipcRenderer.invoke("deleteGameFolder", gameId), getGameByObjectID: (objectID: string) => ipcRenderer.invoke("getGameByObjectID", objectID), - onPlaytime: (cb: (gameId: number) => void) => { - const listener = (_event: Electron.IpcRendererEvent, gameId: number) => - cb(gameId); - ipcRenderer.on("on-playtime", listener); - return () => ipcRenderer.removeListener("on-playtime", listener); - }, - onGameClose: (cb: (gameId: number) => void) => { - const listener = (_event: Electron.IpcRendererEvent, gameId: number) => - cb(gameId); - ipcRenderer.on("on-game-close", listener); - return () => ipcRenderer.removeListener("on-game-close", listener); + onGamesRunning: (cb: (gamesId: number[]) => void) => { + const listener = (_event: Electron.IpcRendererEvent, gamesId: number[]) => + cb(gamesId); + ipcRenderer.on("on-games-running", listener); + return () => ipcRenderer.removeListener("on-games-running", listener); }, /* Hardware */ 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 ad32f987..fa8309f3 100644 --- a/src/renderer/src/context/game-details/game-details.context.tsx +++ b/src/renderer/src/context/game-details/game-details.context.tsx @@ -110,14 +110,14 @@ export function GameDetailsContextProvider({ useEffect(() => { const listeners = [ - window.electron.onGameClose(() => { - if (isGameRunning) setisGameRunning(false); - }), - window.electron.onPlaytime((gameId) => { - if (gameId === game?.id) { - if (!isGameRunning) setisGameRunning(true); + window.electron.onGamesRunning((gamesIds) => { + const newIsGameRunning = !!game?.id && gamesIds.includes(game.id); + + if (isGameRunning != newIsGameRunning) { updateGame(); } + + setisGameRunning(newIsGameRunning); }), ]; diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 968a7a72..a3ff0ad1 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -71,8 +71,9 @@ declare global { removeGame: (gameId: number) => Promise; deleteGameFolder: (gameId: number) => Promise; getGameByObjectID: (objectID: string) => Promise; - onPlaytime: (cb: (gameId: number) => void) => () => Electron.IpcRenderer; - onGameClose: (cb: (gameId: number) => void) => () => Electron.IpcRenderer; + onGamesRunning: ( + cb: (gamesId: number[]) => void + ) => () => Electron.IpcRenderer; /* User preferences */ getUserPreferences: () => Promise; From 4a59a5217480de6c4479a55ecf85675e60813d2c Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Wed, 19 Jun 2024 19:07:36 -0300 Subject: [PATCH 02/19] feat: show running game on sidebar --- src/locales/en/translation.json | 3 ++- src/locales/pt/translation.json | 3 ++- src/main/events/profile/update-profile.ts | 2 -- src/main/services/hydra-api.ts | 2 +- src/renderer/src/app.tsx | 27 ++++++++++++++++++- .../components/sidebar/sidebar-profile.tsx | 18 ++++++++++++- .../game-details/game-details.context.tsx | 6 ++--- src/renderer/src/features/index.ts | 1 + .../src/features/running-game-slice.ts | 22 +++++++++++++++ src/renderer/src/pages/user/user.css.ts | 1 + src/renderer/src/pages/user/user.tsx | 2 -- src/renderer/src/store.ts | 2 ++ src/types/index.ts | 8 ++++++ 13 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 src/renderer/src/features/running-game-slice.ts 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; From 56c36074007412ca668a2c6bd58a6f9d7dad5701 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Wed, 19 Jun 2024 20:01:50 -0300 Subject: [PATCH 03/19] game background image profile page --- src/locales/en/translation.json | 3 +- src/locales/pt/translation.json | 3 +- src/renderer/src/app.tsx | 2 +- .../components/sidebar/sidebar-profile.css.ts | 2 + .../components/sidebar/sidebar-profile.tsx | 5 +- src/renderer/src/pages/user/user-content.tsx | 60 ++++++++++++++++++- src/renderer/src/pages/user/user.css.ts | 3 +- src/types/index.ts | 1 + 8 files changed, 71 insertions(+), 8 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 8564b01d..a3b6cd09 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -16,7 +16,8 @@ "filter": "Filter library", "home": "Home", "queued": "{{title}} (Queued)", - "game_has_no_executable": "Game has no executable selected" + "game_has_no_executable": "Game has no executable selected", + "signin": "Sign in" }, "header": { "search": "Search games", diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.json index 209279e2..bb53cb23 100644 --- a/src/locales/pt/translation.json +++ b/src/locales/pt/translation.json @@ -16,7 +16,8 @@ "filter": "Filtrar biblioteca", "home": "Início", "queued": "{{title}} (Na fila)", - "game_has_no_executable": "Jogo não possui executável selecionado" + "game_has_no_executable": "Jogo não possui executável selecionado", + "signin": "Login" }, "header": { "search": "Buscar jogos", diff --git a/src/renderer/src/app.tsx b/src/renderer/src/app.tsx index ba98a653..3d7437b6 100644 --- a/src/renderer/src/app.tsx +++ b/src/renderer/src/app.tsx @@ -118,7 +118,7 @@ export function App() { return () => { unsubscribe(); }; - }, [dispatch]); + }, [dispatch, library]); useEffect(() => { const listeners = [ diff --git a/src/renderer/src/components/sidebar/sidebar-profile.css.ts b/src/renderer/src/components/sidebar/sidebar-profile.css.ts index 9681c866..7fe6e4ec 100644 --- a/src/renderer/src/components/sidebar/sidebar-profile.css.ts +++ b/src/renderer/src/components/sidebar/sidebar-profile.css.ts @@ -20,6 +20,7 @@ export const profileButtonContent = style({ alignItems: "center", gap: `${SPACING_UNIT + SPACING_UNIT / 2}px`, height: "40px", + width: "100%", }); export const profileAvatar = style({ @@ -39,6 +40,7 @@ export const profileButtonInformation = style({ display: "flex", flexDirection: "column", alignItems: "flex-start", + flex: "1", }); export const statusBadge = style({ diff --git a/src/renderer/src/components/sidebar/sidebar-profile.tsx b/src/renderer/src/components/sidebar/sidebar-profile.tsx index a7f8ea78..2f4dc600 100644 --- a/src/renderer/src/components/sidebar/sidebar-profile.tsx +++ b/src/renderer/src/components/sidebar/sidebar-profile.tsx @@ -4,10 +4,13 @@ import * as styles from "./sidebar-profile.css"; import { useAppSelector, useUserDetails } from "@renderer/hooks"; import { useMemo } from "react"; +import { useTranslation } from "react-i18next"; export function SidebarProfile() { const navigate = useNavigate(); + const { t } = useTranslation("sidebar"); + const { userDetails, profileBackground } = useUserDetails(); const { runningGame } = useAppSelector((state) => state.runningGame); @@ -48,7 +51,7 @@ export function SidebarProfile() {

- {userDetails ? userDetails.displayName : "Sign in"} + {userDetails ? userDetails.displayName : t("signin")}

{userDetails && runningGame && ( diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index 5b4798e7..ff5b879b 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -6,7 +6,7 @@ import { SPACING_UNIT, vars } from "@renderer/theme.css"; import { useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import SteamLogo from "@renderer/assets/steam-logo.svg?react"; -import { useDate, useUserDetails } from "@renderer/hooks"; +import { useAppSelector, useDate, useUserDetails } from "@renderer/hooks"; import { useNavigate } from "react-router-dom"; import { buildGameDetailsPath } from "@renderer/helpers"; import { PersonIcon, TelescopeIcon } from "@primer/octicons-react"; @@ -32,6 +32,8 @@ export function UserContent({ const [showEditProfileModal, setShowEditProfileModal] = useState(false); const [showSignOutModal, setShowSignOutModal] = useState(false); + const { runningGame } = useAppSelector((state) => state.runningGame); + const navigate = useNavigate(); const numberFormatter = useMemo(() => { @@ -98,10 +100,27 @@ export function UserContent({
+
+
+
{userProfile.profileImageUrl ? (

{userProfile.displayName}

+ {isMe && runningGame && ( +
+
+

{runningGame.title}

+
+ + {t("playing_for", { + amount: formatDistance( + runningGame.sessionStartTimestamp, + new Date() + ), + })} + +
+ )}
{isMe && ( -
+
Date: Wed, 19 Jun 2024 20:09:37 -0300 Subject: [PATCH 04/19] add cover --- src/renderer/src/pages/user/user-content.tsx | 22 +++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index ff5b879b..7d74f50a 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -8,7 +8,7 @@ import { useTranslation } from "react-i18next"; import SteamLogo from "@renderer/assets/steam-logo.svg?react"; import { useAppSelector, useDate, useUserDetails } from "@renderer/hooks"; import { useNavigate } from "react-router-dom"; -import { buildGameDetailsPath } from "@renderer/helpers"; +import { buildGameDetailsPath, steamUrlBuilder } from "@renderer/helpers"; import { PersonIcon, TelescopeIcon } from "@primer/octicons-react"; import { Button } from "@renderer/components"; import { UserEditProfileModal } from "./user-edit-modal"; @@ -111,15 +111,17 @@ export function UserContent({ inset: 0, }} >
-
+ {runningGame && ( +
+ )}
{userProfile.profileImageUrl ? ( From fc8e62cdeae4f32df5edd8ab7331607274476cd0 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Wed, 19 Jun 2024 20:41:35 -0300 Subject: [PATCH 05/19] background --- package.json | 1 + .../components/sidebar/sidebar-profile.tsx | 1 + src/renderer/src/helpers.ts | 11 ++++++++-- src/renderer/src/hooks/use-user-details.ts | 6 ++--- src/renderer/src/pages/user/user-content.tsx | 22 +++++++++---------- src/types/index.ts | 1 - yarn.lock | 19 ++++++++++++++++ 7 files changed, 44 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 89fb8c42..39a177e9 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "@electron-toolkit/tsconfig": "^1.0.1", "@swc/core": "^1.4.16", "@types/auto-launch": "^5.0.5", + "@types/color": "^3.0.6", "@types/jsdom": "^21.1.6", "@types/lodash-es": "^4.17.12", "@types/node": "^20.12.7", diff --git a/src/renderer/src/components/sidebar/sidebar-profile.tsx b/src/renderer/src/components/sidebar/sidebar-profile.tsx index 2f4dc600..f8d2225e 100644 --- a/src/renderer/src/components/sidebar/sidebar-profile.tsx +++ b/src/renderer/src/components/sidebar/sidebar-profile.tsx @@ -63,6 +63,7 @@ export function SidebarProfile() { {userDetails && runningGame && ( {runningGame.title} - new Color(color).darken(amount).toString(); +export const darkenColor = ( + color: string, + amount: number, + alpha: number = 1 +) => { + const newColor = new Color(color).darken(amount).alpha(alpha).toString(); + console.log(color, newColor); + return newColor; +}; diff --git a/src/renderer/src/hooks/use-user-details.ts b/src/renderer/src/hooks/use-user-details.ts index 75de473f..e17ad95f 100644 --- a/src/renderer/src/hooks/use-user-details.ts +++ b/src/renderer/src/hooks/use-user-details.ts @@ -36,8 +36,7 @@ export function useUserDetails() { format: "hex", }); - const profileBackground = `linear-gradient(135deg, ${darkenColor(output as string, 0.6)}, ${darkenColor(output as string, 0.8)})`; - + const profileBackground = `linear-gradient(135deg, ${darkenColor(output as string, 0.6)}, ${darkenColor(output as string, 0.8, 0.9)})`; dispatch(setProfileBackground(profileBackground)); window.localStorage.setItem( @@ -45,7 +44,8 @@ export function useUserDetails() { JSON.stringify({ ...userDetails, profileBackground }) ); } else { - dispatch(setProfileBackground(null)); + const profileBackground = `#151515e6`; + dispatch(setProfileBackground(profileBackground)); window.localStorage.setItem("userDetails", JSON.stringify(userDetails)); } diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index 7d74f50a..2148f7e2 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -104,6 +104,17 @@ export function UserContent({ position: "relative", }} > + {runningGame && ( +
+ )} +
- {runningGame && ( -
- )}
{userProfile.profileImageUrl ? ( diff --git a/src/types/index.ts b/src/types/index.ts index ecf53548..cda9bf72 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -133,7 +133,6 @@ export interface RunningGame { objectID: string; shop: GameShop; sessionStartTimestamp: number; - cover: string; } export interface DownloadProgress { diff --git a/yarn.lock b/yarn.lock index b822ab1d..1e03e6ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1251,6 +1251,25 @@ "@types/node" "*" "@types/responselike" "^1.0.0" +"@types/color-convert@*": + version "2.0.3" + resolved "https://registry.yarnpkg.com/@types/color-convert/-/color-convert-2.0.3.tgz#e93f5c991eda87a945058b47044f5f0008b0dce9" + integrity sha512-2Q6wzrNiuEvYxVQqhh7sXM2mhIhvZR/Paq4FdsQkOMgWsCIkKvSGj8Le1/XalulrmgOzPMqNa0ix+ePY4hTrfg== + dependencies: + "@types/color-name" "*" + +"@types/color-name@*": + version "1.1.4" + resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.4.tgz#e002611ff627347818d440a05e81650e9a4053b8" + integrity sha512-hulKeREDdLFesGQjl96+4aoJSHY5b2GRjagzzcqCfIrWhe5vkCqIvrLbqzBaI1q94Vg8DNJZZqTR5ocdWmWclg== + +"@types/color@^3.0.6": + version "3.0.6" + resolved "https://registry.yarnpkg.com/@types/color/-/color-3.0.6.tgz#29c27a99d4de2975e1676712679a0bd7f646a3fb" + integrity sha512-NMiNcZFRUAiUUCCf7zkAelY8eV3aKqfbzyFQlXpPIEeoNDbsEHGpb854V3gzTsGKYj830I5zPuOwU/TP5/cW6A== + dependencies: + "@types/color-convert" "*" + "@types/conventional-commits-parser@^5.0.0": version "5.0.0" resolved "https://registry.yarnpkg.com/@types/conventional-commits-parser/-/conventional-commits-parser-5.0.0.tgz#8c9d23e0b415b24b91626d07017303755d542dc8" From 188fe4537aa5447ba9502d78a4f620170aee1f95 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Wed, 19 Jun 2024 22:05:22 -0300 Subject: [PATCH 06/19] feat: game session start time stamp --- src/main/services/process-watcher.ts | 8 +++++-- src/preload/index.ts | 9 +++++--- src/renderer/src/app.tsx | 12 ++++++----- .../game-details/game-details.context.tsx | 21 +++++++++---------- src/renderer/src/declaration.d.ts | 5 +++-- src/renderer/src/helpers.ts | 11 ++-------- src/renderer/src/hooks/use-user-details.ts | 5 ++++- src/renderer/src/pages/user/user-content.tsx | 2 +- src/types/index.ts | 6 ++++++ 9 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 40f55c48..1be5c748 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -5,6 +5,7 @@ import { gameRepository } from "@main/repository"; import { getProcesses } from "@main/helpers"; import { WindowManager } from "./window-manager"; import { createGame, updateGamePlaytime } from "./library-sync"; +import { RunningGameEvent } from "@types"; const gamesPlaytime = new Map< number, @@ -96,10 +97,13 @@ export const watchProcesses = async () => { } if (WindowManager.mainWindow) { - const gamesRunningIds = Array.from(gamesPlaytime.keys()); + const runningGames = Array.from(gamesPlaytime.entries()).map((entry) => { + return { id: entry[0], sessionStartTimestamp: entry[1].firstTick }; + }); + WindowManager.mainWindow.webContents.send( "on-games-running", - gamesRunningIds + runningGames as RunningGameEvent ); } }; diff --git a/src/preload/index.ts b/src/preload/index.ts index a5378495..b5c46470 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -8,6 +8,7 @@ import type { UserPreferences, AppUpdaterEvent, StartGameDownloadPayload, + RunningGameEvent, } from "@types"; contextBridge.exposeInMainWorld("electron", { @@ -84,9 +85,11 @@ contextBridge.exposeInMainWorld("electron", { ipcRenderer.invoke("deleteGameFolder", gameId), getGameByObjectID: (objectID: string) => ipcRenderer.invoke("getGameByObjectID", objectID), - onGamesRunning: (cb: (gamesId: number[]) => void) => { - const listener = (_event: Electron.IpcRendererEvent, gamesId: number[]) => - cb(gamesId); + onRunningGames: (cb: (runningGames: RunningGameEvent) => void) => { + const listener = ( + _event: Electron.IpcRendererEvent, + runningGames: RunningGameEvent + ) => cb(runningGames); ipcRenderer.on("on-games-running", listener); return () => ipcRenderer.removeListener("on-games-running", listener); }, diff --git a/src/renderer/src/app.tsx b/src/renderer/src/app.tsx index 93e7eb81..af58497a 100644 --- a/src/renderer/src/app.tsx +++ b/src/renderer/src/app.tsx @@ -97,16 +97,18 @@ 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); + const unsubscribe = window.electron.onRunningGames((runningGames) => { + if (runningGames.length) { + const lastGame = runningGames[runningGames.length - 1]; + const libraryGame = library.find( + (library) => library.id === lastGame.id + ); if (libraryGame) { dispatch( setRunningGame({ ...libraryGame, - sessionStartTimestamp: new Date().getTime(), + sessionStartTimestamp: lastGame.sessionStartTimestamp, }) ); return; 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 e55a5340..1431190e 100644 --- a/src/renderer/src/context/game-details/game-details.context.tsx +++ b/src/renderer/src/context/game-details/game-details.context.tsx @@ -109,20 +109,19 @@ export function GameDetailsContextProvider({ }, [objectID, gameTitle, dispatch]); useEffect(() => { - const listeners = [ - window.electron.onGamesRunning((gamesIds) => { - const updatedIsGameRunning = !!game?.id && gamesIds.includes(game.id); + const unsubscribe = window.electron.onRunningGames((gamesIds) => { + const updatedIsGameRunning = + !!game?.id && + !!gamesIds.find((runningGame) => runningGame.id == game.id); - if (isGameRunning != updatedIsGameRunning) { - updateGame(); - } - - setisGameRunning(updatedIsGameRunning); - }), - ]; + if (isGameRunning != updatedIsGameRunning) { + updateGame(); + } + setisGameRunning(updatedIsGameRunning); + }); return () => { - listeners.forEach((unsubscribe) => unsubscribe()); + unsubscribe(); }; }, [game?.id, isGameRunning, updateGame]); diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 1e983738..cbc7b62e 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -14,6 +14,7 @@ import type { RealDebridUser, DownloadSource, UserProfile, + RunningGameEvent, } from "@types"; import type { DiskSpace } from "check-disk-space"; @@ -71,8 +72,8 @@ declare global { removeGame: (gameId: number) => Promise; deleteGameFolder: (gameId: number) => Promise; getGameByObjectID: (objectID: string) => Promise; - onGamesRunning: ( - cb: (gamesId: number[]) => void + onRunningGames: ( + cb: (runningGames: RunningGameEvent) => void ) => () => Electron.IpcRenderer; onLibraryBatchComplete: (cb: () => void) => () => Electron.IpcRenderer; diff --git a/src/renderer/src/helpers.ts b/src/renderer/src/helpers.ts index 9b6344a7..d37612d4 100644 --- a/src/renderer/src/helpers.ts +++ b/src/renderer/src/helpers.ts @@ -43,12 +43,5 @@ export const buildGameDetailsPath = ( return `/game/${game.shop}/${game.objectID}?${searchParams.toString()}`; }; -export const darkenColor = ( - color: string, - amount: number, - alpha: number = 1 -) => { - const newColor = new Color(color).darken(amount).alpha(alpha).toString(); - console.log(color, newColor); - return newColor; -}; +export const darkenColor = (color: string, amount: number, alpha: number = 1) => + new Color(color).darken(amount).alpha(alpha).toString(); diff --git a/src/renderer/src/hooks/use-user-details.ts b/src/renderer/src/hooks/use-user-details.ts index e17ad95f..d73e2a07 100644 --- a/src/renderer/src/hooks/use-user-details.ts +++ b/src/renderer/src/hooks/use-user-details.ts @@ -47,7 +47,10 @@ export function useUserDetails() { const profileBackground = `#151515e6`; dispatch(setProfileBackground(profileBackground)); - window.localStorage.setItem("userDetails", JSON.stringify(userDetails)); + window.localStorage.setItem( + "userDetails", + JSON.stringify({ ...userDetails, profileBackground }) + ); } }, [dispatch] diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index 2148f7e2..8557ba82 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -159,7 +159,7 @@ export function UserContent({ {t("playing_for", { amount: formatDistance( runningGame.sessionStartTimestamp, - new Date() + performance.now() ), })} diff --git a/src/types/index.ts b/src/types/index.ts index cda9bf72..ffc07b8a 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -127,7 +127,13 @@ export interface Game { export type LibraryGame = Omit; +export type RunningGameEvent = { + id: number; + sessionStartTimestamp: number; +}[]; + export interface RunningGame { + id: number; title: string; iconUrl: string; objectID: string; From c01c589f2a270444672d1588554e713dbea9e7d1 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Wed, 19 Jun 2024 23:03:52 -0300 Subject: [PATCH 07/19] fix: add missin hook dependency --- src/renderer/src/app.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/src/app.tsx b/src/renderer/src/app.tsx index af58497a..2dc1b12c 100644 --- a/src/renderer/src/app.tsx +++ b/src/renderer/src/app.tsx @@ -140,7 +140,7 @@ export function App() { return () => { listeners.forEach((unsubscribe) => unsubscribe()); }; - }, [fetchUserDetails, updateUserDetails, clearUserDetails]); + }, [fetchUserDetails, updateUserDetails, clearUserDetails, updateLibrary]); const handleSearch = useCallback( (query: string) => { From 94a25a23839752fc68e9a7c3a60f632467bcec09 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:04:24 -0300 Subject: [PATCH 08/19] fix border radius for profile background with game hero --- src/renderer/src/pages/user/user-content.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index 8557ba82..1dd7a203 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -104,13 +104,14 @@ export function UserContent({ position: "relative", }} > - {runningGame && ( + {runningGame && isMe && (
)} @@ -120,6 +121,7 @@ export function UserContent({ background: profileContentBoxBackground, position: "absolute", inset: 0, + borderRadius: "4px", }} >
From 570259c5c75cddf000585c7a286a36fd72e87648 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:06:30 -0300 Subject: [PATCH 09/19] remove unused on-game-close event --- src/main/services/process-watcher.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 1be5c748..4bf02b66 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -89,10 +89,6 @@ export const watchProcesses = async () => { gameRepository.update({ objectID: game.objectID }, { remoteId }); }); } - - if (WindowManager.mainWindow) { - WindowManager.mainWindow.webContents.send("on-game-close", game.id); - } } } From 0fe57fbc3b60b0f89903e051a63a4814e2c3f9d2 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:37:37 -0300 Subject: [PATCH 10/19] side bar css --- src/renderer/src/components/sidebar/sidebar-profile.css.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/renderer/src/components/sidebar/sidebar-profile.css.ts b/src/renderer/src/components/sidebar/sidebar-profile.css.ts index 7fe6e4ec..a4eb32b1 100644 --- a/src/renderer/src/components/sidebar/sidebar-profile.css.ts +++ b/src/renderer/src/components/sidebar/sidebar-profile.css.ts @@ -41,6 +41,7 @@ export const profileButtonInformation = style({ flexDirection: "column", alignItems: "flex-start", flex: "1", + minWidth: 0, }); export const statusBadge = style({ From b3ca63c62a1c000f068c0b8dde6b820bbb6ff2ce Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:45:12 -0300 Subject: [PATCH 11/19] fix: sidebar with dib display name --- src/renderer/src/components/sidebar/sidebar-profile.css.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/renderer/src/components/sidebar/sidebar-profile.css.ts b/src/renderer/src/components/sidebar/sidebar-profile.css.ts index a4eb32b1..5f3c16da 100644 --- a/src/renderer/src/components/sidebar/sidebar-profile.css.ts +++ b/src/renderer/src/components/sidebar/sidebar-profile.css.ts @@ -58,4 +58,8 @@ export const statusBadge = style({ export const profileButtonTitle = style({ fontWeight: "bold", fontSize: vars.size.body, + width: "100%", + overflow: "hidden", + textOverflow: "ellipsis", + whiteSpace: "nowrap", }); From d347991e0b47fae86b3e9da3eaa1fcea429b1dad Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:27:09 -0300 Subject: [PATCH 12/19] fix: game session duration calculation --- src/main/services/process-watcher.ts | 5 ++++- src/renderer/src/app.tsx | 2 +- src/renderer/src/hooks/use-date.ts | 17 ++++++++++++++++- src/renderer/src/pages/user/user-content.tsx | 11 ++++++----- src/types/index.ts | 4 ++-- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 4bf02b66..b17a594f 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -94,7 +94,10 @@ export const watchProcesses = async () => { if (WindowManager.mainWindow) { const runningGames = Array.from(gamesPlaytime.entries()).map((entry) => { - return { id: entry[0], sessionStartTimestamp: entry[1].firstTick }; + return { + id: entry[0], + sessionDurationInMillis: entry[1].firstTick - performance.now(), + }; }); WindowManager.mainWindow.webContents.send( diff --git a/src/renderer/src/app.tsx b/src/renderer/src/app.tsx index 2dc1b12c..33e02bf5 100644 --- a/src/renderer/src/app.tsx +++ b/src/renderer/src/app.tsx @@ -108,7 +108,7 @@ export function App() { dispatch( setRunningGame({ ...libraryGame, - sessionStartTimestamp: lastGame.sessionStartTimestamp, + sessionDurationInMillis: lastGame.sessionDurationInMillis, }) ); return; diff --git a/src/renderer/src/hooks/use-date.ts b/src/renderer/src/hooks/use-date.ts index f5e8204e..9b60a4a0 100644 --- a/src/renderer/src/hooks/use-date.ts +++ b/src/renderer/src/hooks/use-date.ts @@ -1,4 +1,4 @@ -import { formatDistance } from "date-fns"; +import { formatDistance, subMilliseconds } from "date-fns"; import type { FormatDistanceOptions } from "date-fns"; import { ptBR, @@ -52,5 +52,20 @@ export function useDate() { return ""; } }, + + formatDistanceInMillis: ( + millis: number, + baseDate: string | number | Date, + options?: FormatDistanceOptions + ) => { + try { + return formatDistance(subMilliseconds(new Date(), millis), baseDate, { + ...options, + locale: getDateLocale(), + }); + } catch (err) { + return ""; + } + }, }; } diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index 1dd7a203..31e68328 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -42,7 +42,7 @@ export function UserContent({ }); }, [i18n.language]); - const { formatDistance } = useDate(); + const { formatDistance, formatDistanceInMillis } = useDate(); const formatPlayTime = () => { const seconds = userProfile.libraryGames.reduce( @@ -107,7 +107,8 @@ export function UserContent({ {runningGame && isMe && (
{t("playing_for", { - amount: formatDistance( - runningGame.sessionStartTimestamp, - performance.now() + amount: formatDistanceInMillis( + runningGame.sessionDurationInMillis, + new Date().getTime() ), })} diff --git a/src/types/index.ts b/src/types/index.ts index ffc07b8a..e024bffc 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -129,7 +129,7 @@ export type LibraryGame = Omit; export type RunningGameEvent = { id: number; - sessionStartTimestamp: number; + sessionDurationInMillis: number; }[]; export interface RunningGame { @@ -138,7 +138,7 @@ export interface RunningGame { iconUrl: string; objectID: string; shop: GameShop; - sessionStartTimestamp: number; + sessionDurationInMillis: number; } export interface DownloadProgress { From f019820458d2d0c58669e24e1cc765b800fc92a0 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:48:26 -0300 Subject: [PATCH 13/19] fix: game session duration calculation --- src/main/services/process-watcher.ts | 2 +- src/renderer/src/hooks/use-date.ts | 2 +- src/renderer/src/pages/user/user-content.tsx | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index b17a594f..5bc81d26 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -96,7 +96,7 @@ export const watchProcesses = async () => { const runningGames = Array.from(gamesPlaytime.entries()).map((entry) => { return { id: entry[0], - sessionDurationInMillis: entry[1].firstTick - performance.now(), + sessionDurationInMillis: performance.now() - entry[1].firstTick, }; }); diff --git a/src/renderer/src/hooks/use-date.ts b/src/renderer/src/hooks/use-date.ts index 9b60a4a0..01f55610 100644 --- a/src/renderer/src/hooks/use-date.ts +++ b/src/renderer/src/hooks/use-date.ts @@ -53,7 +53,7 @@ export function useDate() { } }, - formatDistanceInMillis: ( + formatDiffInMillis: ( millis: number, baseDate: string | number | Date, options?: FormatDistanceOptions diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index 31e68328..98aad705 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -42,7 +42,7 @@ export function UserContent({ }); }, [i18n.language]); - const { formatDistance, formatDistanceInMillis } = useDate(); + const { formatDistance, formatDiffInMillis } = useDate(); const formatPlayTime = () => { const seconds = userProfile.libraryGames.reduce( @@ -160,9 +160,9 @@ export function UserContent({
{t("playing_for", { - amount: formatDistanceInMillis( + amount: formatDiffInMillis( runningGame.sessionDurationInMillis, - new Date().getTime() + new Date() ), })} From 48e05dcaa5cbf1cb24f9625ead03a17e23a06681 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 20 Jun 2024 12:05:38 -0300 Subject: [PATCH 14/19] update background transparency --- src/renderer/src/components/sidebar/sidebar-profile.css.ts | 1 + src/renderer/src/hooks/use-user-details.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/sidebar/sidebar-profile.css.ts b/src/renderer/src/components/sidebar/sidebar-profile.css.ts index 5f3c16da..c5347c26 100644 --- a/src/renderer/src/components/sidebar/sidebar-profile.css.ts +++ b/src/renderer/src/components/sidebar/sidebar-profile.css.ts @@ -59,6 +59,7 @@ export const profileButtonTitle = style({ fontWeight: "bold", fontSize: vars.size.body, width: "100%", + textAlign: "left", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", diff --git a/src/renderer/src/hooks/use-user-details.ts b/src/renderer/src/hooks/use-user-details.ts index d73e2a07..1d8257f4 100644 --- a/src/renderer/src/hooks/use-user-details.ts +++ b/src/renderer/src/hooks/use-user-details.ts @@ -36,7 +36,7 @@ export function useUserDetails() { format: "hex", }); - const profileBackground = `linear-gradient(135deg, ${darkenColor(output as string, 0.6)}, ${darkenColor(output as string, 0.8, 0.9)})`; + const profileBackground = `linear-gradient(135deg, ${darkenColor(output as string, 0.6)}, ${darkenColor(output as string, 0.8, 0.7)})`; dispatch(setProfileBackground(profileBackground)); window.localStorage.setItem( @@ -44,7 +44,7 @@ export function useUserDetails() { JSON.stringify({ ...userDetails, profileBackground }) ); } else { - const profileBackground = `#151515e6`; + const profileBackground = `#151515B3`; dispatch(setProfileBackground(profileBackground)); window.localStorage.setItem( From 973db98090514a23b44c1ab2e81a4d9f13cfad4f Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 20 Jun 2024 12:20:13 -0300 Subject: [PATCH 15/19] fix: padding adjustment --- src/renderer/src/pages/user/user.css.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/renderer/src/pages/user/user.css.ts b/src/renderer/src/pages/user/user.css.ts index def3045d..6ec28b94 100644 --- a/src/renderer/src/pages/user/user.css.ts +++ b/src/renderer/src/pages/user/user.css.ts @@ -4,7 +4,6 @@ import { style } from "@vanilla-extract/css"; export const wrapper = style({ padding: "24px", width: "100%", - height: "100%", display: "flex", flexDirection: "column", gap: `${SPACING_UNIT * 3}px`, From a02eac4ecbe0204321412e6fb3197a83ebe9d57a Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:19:40 -0300 Subject: [PATCH 16/19] fix: adjust i18n --- src/locales/en/translation.json | 3 +-- src/locales/pt/translation.json | 1 - src/renderer/src/pages/user/user-content.tsx | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index a3b6cd09..9dd14580 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -230,7 +230,6 @@ "amount_hours": "{{amount}} hours", "amount_minutes": "{{amount}} minutes", "last_time_played": "Last played {{period}}", - "sign_out": "Sign out", "activity": "Recent activity", "library": "Library", "total_play_time": "Total playtime: {{amount}}", @@ -244,7 +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 bb53cb23..7289119a 100644 --- a/src/locales/pt/translation.json +++ b/src/locales/pt/translation.json @@ -230,7 +230,6 @@ "amount_hours": "{{amount}} horas", "amount_minutes": "{{amount}} minutos", "last_time_played": "Jogou {{period}}", - "sign_out": "Sair da conta", "activity": "Atividade recente", "library": "Biblioteca", "total_play_time": "Tempo total de jogo: {{amount}}", diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index 98aad705..6a541375 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -195,7 +195,7 @@ export function UserContent({ theme="danger" onClick={() => setShowSignOutModal(true)} > - {t("sign_out")} + {t("signout")}
From 67f8b609babec30c9a23a74ae55ad231d086d2e8 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:39:10 -0300 Subject: [PATCH 17/19] fix: sign_out and sign_in --- src/locales/en/translation.json | 6 +++--- src/locales/pt/translation.json | 6 +++--- src/renderer/src/components/sidebar/sidebar-profile.tsx | 2 +- src/renderer/src/pages/user/user-content.tsx | 2 +- src/renderer/src/pages/user/user-signout-modal.tsx | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 9dd14580..eab4bc92 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -17,7 +17,7 @@ "home": "Home", "queued": "{{title}} (Queued)", "game_has_no_executable": "Game has no executable selected", - "signin": "Sign in" + "sign_in": "Sign in" }, "header": { "search": "Search games", @@ -241,9 +241,9 @@ "edit_profile": "Edit Profile", "saved_successfully": "Saved successfully", "try_again": "Please, try again", - "signout_modal_title": "Are you sure?", + "sign_out_modal_title": "Are you sure?", "cancel": "Cancel", - "signout": "Sign out", + "sign_out": "Sign out", "playing_for": "Playing for {{amount}}" } } diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.json index 7289119a..910d965c 100644 --- a/src/locales/pt/translation.json +++ b/src/locales/pt/translation.json @@ -17,7 +17,7 @@ "home": "Início", "queued": "{{title}} (Na fila)", "game_has_no_executable": "Jogo não possui executável selecionado", - "signin": "Login" + "sign_in": "Login" }, "header": { "search": "Buscar jogos", @@ -242,8 +242,8 @@ "saved_successfully": "Salvo com sucesso", "try_again": "Por favor, tente novamente", "cancel": "Cancelar", - "signout": "Sair da conta", - "signout_modal_title": "Tem certeza?", + "sign_out": "Sair da conta", + "sign_out_modal_title": "Tem certeza?", "playing_for": "Jogando por {{amount}}" } } diff --git a/src/renderer/src/components/sidebar/sidebar-profile.tsx b/src/renderer/src/components/sidebar/sidebar-profile.tsx index f8d2225e..859c904b 100644 --- a/src/renderer/src/components/sidebar/sidebar-profile.tsx +++ b/src/renderer/src/components/sidebar/sidebar-profile.tsx @@ -51,7 +51,7 @@ export function SidebarProfile() {

- {userDetails ? userDetails.displayName : t("signin")} + {userDetails ? userDetails.displayName : t("sign_in")}

{userDetails && runningGame && ( diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index 6a541375..98aad705 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -195,7 +195,7 @@ export function UserContent({ theme="danger" onClick={() => setShowSignOutModal(true)} > - {t("signout")} + {t("sign_out")}
diff --git a/src/renderer/src/pages/user/user-signout-modal.tsx b/src/renderer/src/pages/user/user-signout-modal.tsx index a6c40630..5e05a61e 100644 --- a/src/renderer/src/pages/user/user-signout-modal.tsx +++ b/src/renderer/src/pages/user/user-signout-modal.tsx @@ -19,7 +19,7 @@ export const UserSignOutModal = ({ <>
From 468af807b0d45fa1ca5fc5a44858b6dbcdd25554 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:49:33 -0300 Subject: [PATCH 18/19] feat: signout modal text --- src/renderer/src/pages/user/user-content.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index 98aad705..a11415ad 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -188,7 +188,7 @@ export function UserContent({ > <>
- {userDetails && runningGame && ( + {userDetails && gameRunning && ( {runningGame.title} )}
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 1431190e..19d2cc72 100644 --- a/src/renderer/src/context/game-details/game-details.context.tsx +++ b/src/renderer/src/context/game-details/game-details.context.tsx @@ -109,10 +109,10 @@ export function GameDetailsContextProvider({ }, [objectID, gameTitle, dispatch]); useEffect(() => { - const unsubscribe = window.electron.onRunningGames((gamesIds) => { + const unsubscribe = window.electron.onGamesRunning((gamesIds) => { const updatedIsGameRunning = !!game?.id && - !!gamesIds.find((runningGame) => runningGame.id == game.id); + !!gamesIds.find((gameRunning) => gameRunning.id == game.id); if (isGameRunning != updatedIsGameRunning) { updateGame(); diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index cbc7b62e..ad03f1ff 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -14,7 +14,6 @@ import type { RealDebridUser, DownloadSource, UserProfile, - RunningGameEvent, } from "@types"; import type { DiskSpace } from "check-disk-space"; @@ -72,8 +71,10 @@ declare global { removeGame: (gameId: number) => Promise; deleteGameFolder: (gameId: number) => Promise; getGameByObjectID: (objectID: string) => Promise; - onRunningGames: ( - cb: (runningGames: RunningGameEvent) => void + onGamesRunning: ( + cb: ( + gamesRunning: Pick[] + ) => void ) => () => Electron.IpcRenderer; onLibraryBatchComplete: (cb: () => void) => () => Electron.IpcRenderer; diff --git a/src/renderer/src/features/running-game-slice.ts b/src/renderer/src/features/running-game-slice.ts index 1f432989..b3fb0a9d 100644 --- a/src/renderer/src/features/running-game-slice.ts +++ b/src/renderer/src/features/running-game-slice.ts @@ -1,22 +1,22 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit"; -import { RunningGame } from "@types"; +import { GameRunning } from "@types"; -export interface RunningGameState { - runningGame: RunningGame | null; +export interface GameRunningState { + gameRunning: GameRunning | null; } -const initialState: RunningGameState = { - runningGame: null, +const initialState: GameRunningState = { + gameRunning: null, }; -export const runningGameSlice = createSlice({ +export const gameRunningSlice = createSlice({ name: "running-game", initialState, reducers: { - setRunningGame: (state, action: PayloadAction) => { - state.runningGame = action.payload; + setGameRunning: (state, action: PayloadAction) => { + state.gameRunning = action.payload; }, }, }); -export const { setRunningGame } = runningGameSlice.actions; +export const { setGameRunning } = gameRunningSlice.actions; diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index a11415ad..3802b110 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -32,7 +32,7 @@ export function UserContent({ const [showEditProfileModal, setShowEditProfileModal] = useState(false); const [showSignOutModal, setShowSignOutModal] = useState(false); - const { runningGame } = useAppSelector((state) => state.runningGame); + const { gameRunning } = useAppSelector((state) => state.gameRunning); const navigate = useNavigate(); @@ -104,10 +104,10 @@ export function UserContent({ position: "relative", }} > - {runningGame && isMe && ( + {gameRunning && isMe && (

{userProfile.displayName}

- {isMe && runningGame && ( + {isMe && gameRunning && (
-

{runningGame.title}

+

{gameRunning.title}

{t("playing_for", { amount: formatDiffInMillis( - runningGame.sessionDurationInMillis, + gameRunning.sessionDurationInMillis, new Date() ), })} diff --git a/src/renderer/src/store.ts b/src/renderer/src/store.ts index d01c54a5..0f2bee9f 100644 --- a/src/renderer/src/store.ts +++ b/src/renderer/src/store.ts @@ -7,7 +7,7 @@ import { userPreferencesSlice, toastSlice, userDetailsSlice, - runningGameSlice, + gameRunningSlice, } from "@renderer/features"; export const store = configureStore({ @@ -19,7 +19,7 @@ export const store = configureStore({ download: downloadSlice.reducer, toast: toastSlice.reducer, userDetails: userDetailsSlice.reducer, - runningGame: runningGameSlice.reducer, + gameRunning: gameRunningSlice.reducer, }, }); diff --git a/src/types/index.ts b/src/types/index.ts index e024bffc..c1da0d08 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -127,12 +127,7 @@ export interface Game { export type LibraryGame = Omit; -export type RunningGameEvent = { - id: number; - sessionDurationInMillis: number; -}[]; - -export interface RunningGame { +export interface GameRunning { id: number; title: string; iconUrl: string;