From adcb505ab7f140a337c2d6eb0dd1625be2022c60 Mon Sep 17 00:00:00 2001
From: Zamitto <167933696+zamitto@users.noreply.github.com>
Date: Thu, 20 Jun 2024 18:09:49 -0300
Subject: [PATCH] feat: signout modal text
---
src/main/services/process-watcher.ts | 6 +++---
src/preload/index.ts | 14 ++++++++------
src/renderer/src/app.tsx | 12 ++++++------
.../src/components/sidebar/sidebar-profile.tsx | 12 ++++++------
.../game-details/game-details.context.tsx | 4 ++--
src/renderer/src/declaration.d.ts | 7 ++++---
.../src/features/running-game-slice.ts | 18 +++++++++---------
src/renderer/src/pages/user/user-content.tsx | 12 ++++++------
src/renderer/src/store.ts | 4 ++--
src/types/index.ts | 7 +------
10 files changed, 47 insertions(+), 49 deletions(-)
diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts
index 5bc81d26..fc97ff40 100644
--- a/src/main/services/process-watcher.ts
+++ b/src/main/services/process-watcher.ts
@@ -5,7 +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";
+import { GameRunning } from "@types";
const gamesPlaytime = new Map<
number,
@@ -93,7 +93,7 @@ export const watchProcesses = async () => {
}
if (WindowManager.mainWindow) {
- const runningGames = Array.from(gamesPlaytime.entries()).map((entry) => {
+ const gamesRunning = Array.from(gamesPlaytime.entries()).map((entry) => {
return {
id: entry[0],
sessionDurationInMillis: performance.now() - entry[1].firstTick,
@@ -102,7 +102,7 @@ export const watchProcesses = async () => {
WindowManager.mainWindow.webContents.send(
"on-games-running",
- runningGames as RunningGameEvent
+ gamesRunning as Pick[]
);
}
};
diff --git a/src/preload/index.ts b/src/preload/index.ts
index b5c46470..c92343c5 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -8,7 +8,7 @@ import type {
UserPreferences,
AppUpdaterEvent,
StartGameDownloadPayload,
- RunningGameEvent,
+ GameRunning,
} from "@types";
contextBridge.exposeInMainWorld("electron", {
@@ -85,11 +85,13 @@ contextBridge.exposeInMainWorld("electron", {
ipcRenderer.invoke("deleteGameFolder", gameId),
getGameByObjectID: (objectID: string) =>
ipcRenderer.invoke("getGameByObjectID", objectID),
- onRunningGames: (cb: (runningGames: RunningGameEvent) => void) => {
- const listener = (
- _event: Electron.IpcRendererEvent,
- runningGames: RunningGameEvent
- ) => cb(runningGames);
+ onGamesRunning: (
+ cb: (
+ gamesRunning: Pick[]
+ ) => void
+ ) => {
+ const listener = (_event: Electron.IpcRendererEvent, gamesRunning) =>
+ cb(gamesRunning);
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 33e02bf5..0c92eccf 100644
--- a/src/renderer/src/app.tsx
+++ b/src/renderer/src/app.tsx
@@ -21,7 +21,7 @@ import {
closeToast,
setUserDetails,
setProfileBackground,
- setRunningGame,
+ setGameRunning,
} from "@renderer/features";
export interface AppProps {
@@ -97,16 +97,16 @@ export function App() {
}, [dispatch, fetchUserDetails]);
useEffect(() => {
- const unsubscribe = window.electron.onRunningGames((runningGames) => {
- if (runningGames.length) {
- const lastGame = runningGames[runningGames.length - 1];
+ const unsubscribe = window.electron.onGamesRunning((gamesRunning) => {
+ if (gamesRunning.length) {
+ const lastGame = gamesRunning[gamesRunning.length - 1];
const libraryGame = library.find(
(library) => library.id === lastGame.id
);
if (libraryGame) {
dispatch(
- setRunningGame({
+ setGameRunning({
...libraryGame,
sessionDurationInMillis: lastGame.sessionDurationInMillis,
})
@@ -114,7 +114,7 @@ export function App() {
return;
}
}
- dispatch(setRunningGame(null));
+ dispatch(setGameRunning(null));
});
return () => {
diff --git a/src/renderer/src/components/sidebar/sidebar-profile.tsx b/src/renderer/src/components/sidebar/sidebar-profile.tsx
index 859c904b..ac1c9c96 100644
--- a/src/renderer/src/components/sidebar/sidebar-profile.tsx
+++ b/src/renderer/src/components/sidebar/sidebar-profile.tsx
@@ -13,7 +13,7 @@ export function SidebarProfile() {
const { userDetails, profileBackground } = useUserDetails();
- const { runningGame } = useAppSelector((state) => state.runningGame);
+ const { gameRunning } = useAppSelector((state) => state.gameRunning);
const handleButtonClick = () => {
if (userDetails === null) {
@@ -54,19 +54,19 @@ export function SidebarProfile() {
{userDetails ? userDetails.displayName : t("sign_in")}
- {userDetails && runningGame && (
+ {userDetails && gameRunning && (
- {runningGame.title}
+ {gameRunning.title}
)}
- {userDetails && runningGame && (
+ {userDetails && gameRunning && (
)}
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;