From 93298f0bc2613249e6e6f4ced7370b8ba49b251e Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Fri, 21 Jun 2024 01:06:59 +0100 Subject: [PATCH 1/4] chore: removing console.log --- src/main/events/profile/update-profile.ts | 2 -- src/renderer/src/pages/user/user.tsx | 2 -- 2 files changed, 4 deletions(-) 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/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 (
From 8afb3c27dc96a63b5fb66722e238d70cf277f3bb Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Fri, 21 Jun 2024 01:34:59 +0100 Subject: [PATCH 2/4] feat: improve sign out --- src/main/entity/index.ts | 1 + src/main/events/auth/sign-out.ts | 28 +++++++++++++++---- .../library/remove-game-from-library.ts | 3 +- src/main/events/misc/is-user-logged-in.ts | 2 +- src/main/events/profile/get-me.ts | 2 +- src/main/events/profile/update-profile.ts | 2 +- src/main/events/user/get-user.ts | 2 +- src/main/repository.ts | 2 +- src/main/services/download-manager.ts | 1 + src/main/services/index.ts | 1 + src/main/services/process-watcher.ts | 2 +- src/renderer/src/app.tsx | 4 +-- 12 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/main/entity/index.ts b/src/main/entity/index.ts index 4d358726..9cb4f044 100644 --- a/src/main/entity/index.ts +++ b/src/main/entity/index.ts @@ -4,3 +4,4 @@ export * from "./user-preferences.entity"; export * from "./game-shop-cache.entity"; export * from "./download-source.entity"; export * from "./download-queue.entity"; +export * from "./user-auth"; diff --git a/src/main/events/auth/sign-out.ts b/src/main/events/auth/sign-out.ts index dafce7ad..b8b6cecd 100644 --- a/src/main/events/auth/sign-out.ts +++ b/src/main/events/auth/sign-out.ts @@ -1,11 +1,29 @@ -import { gameRepository, userAuthRepository } from "@main/repository"; import { registerEvent } from "../register-event"; -import { HydraApi } from "@main/services/hydra-api"; +import { DownloadManager, HydraApi, gamesPlaytime } from "@main/services"; +import { dataSource } from "@main/data-source"; +import { DownloadQueue, Game, UserAuth } from "@main/entity"; + +const signOut = async (_event: Electron.IpcMainInvokeEvent) => { + const databaseOperations = dataSource.transaction( + async (transactionalEntityManager) => { + await transactionalEntityManager.getRepository(DownloadQueue).delete({}); + + await transactionalEntityManager.getRepository(Game).delete({}); + + await transactionalEntityManager + .getRepository(UserAuth) + .delete({ id: 1 }); + } + ); + + /* Removes all games being played */ + gamesPlaytime.clear(); + + /* Disconnects aria2 */ + DownloadManager.disconnect(); -const signOut = async (_event: Electron.IpcMainInvokeEvent): Promise => { await Promise.all([ - userAuthRepository.delete({ id: 1 }), - gameRepository.delete({}), + databaseOperations, HydraApi.post("/auth/logout").catch(), ]); }; diff --git a/src/main/events/library/remove-game-from-library.ts b/src/main/events/library/remove-game-from-library.ts index 5d154aae..d7874b8f 100644 --- a/src/main/events/library/remove-game-from-library.ts +++ b/src/main/events/library/remove-game-from-library.ts @@ -1,7 +1,6 @@ import { registerEvent } from "../register-event"; import { gameRepository } from "../../repository"; -import { HydraApi } from "@main/services/hydra-api"; -import { logger } from "@main/services"; +import { HydraApi, logger } from "@main/services"; const removeGameFromLibrary = async ( _event: Electron.IpcMainInvokeEvent, diff --git a/src/main/events/misc/is-user-logged-in.ts b/src/main/events/misc/is-user-logged-in.ts index d1874b01..f5f79e15 100644 --- a/src/main/events/misc/is-user-logged-in.ts +++ b/src/main/events/misc/is-user-logged-in.ts @@ -1,5 +1,5 @@ import { registerEvent } from "../register-event"; -import { HydraApi } from "@main/services/hydra-api"; +import { HydraApi } from "@main/services"; const isUserLoggedIn = async (_event: Electron.IpcMainInvokeEvent) => { return HydraApi.isLoggedIn(); diff --git a/src/main/events/profile/get-me.ts b/src/main/events/profile/get-me.ts index d68e5c81..1225551c 100644 --- a/src/main/events/profile/get-me.ts +++ b/src/main/events/profile/get-me.ts @@ -1,5 +1,5 @@ import { registerEvent } from "../register-event"; -import { HydraApi } from "@main/services/hydra-api"; +import { HydraApi } from "@main/services"; import { UserProfile } from "@types"; import { userAuthRepository } from "@main/repository"; import { logger } from "@main/services"; diff --git a/src/main/events/profile/update-profile.ts b/src/main/events/profile/update-profile.ts index 68d18c1b..fbed0606 100644 --- a/src/main/events/profile/update-profile.ts +++ b/src/main/events/profile/update-profile.ts @@ -1,5 +1,5 @@ import { registerEvent } from "../register-event"; -import { HydraApi } from "@main/services/hydra-api"; +import { HydraApi } from "@main/services"; import axios from "axios"; import fs from "node:fs"; import path from "node:path"; diff --git a/src/main/events/user/get-user.ts b/src/main/events/user/get-user.ts index 65d3e9e0..596df084 100644 --- a/src/main/events/user/get-user.ts +++ b/src/main/events/user/get-user.ts @@ -1,5 +1,5 @@ import { registerEvent } from "../register-event"; -import { HydraApi } from "@main/services/hydra-api"; +import { HydraApi } from "@main/services"; import { steamGamesWorker } from "@main/workers"; import { UserProfile } from "@types"; import { convertSteamGameToCatalogueEntry } from "../helpers/search-games"; diff --git a/src/main/repository.ts b/src/main/repository.ts index af6ebcbd..4464e775 100644 --- a/src/main/repository.ts +++ b/src/main/repository.ts @@ -6,8 +6,8 @@ import { GameShopCache, Repack, UserPreferences, + UserAuth, } from "@main/entity"; -import { UserAuth } from "./entity/user-auth"; export const gameRepository = dataSource.getRepository(Game); diff --git a/src/main/services/download-manager.ts b/src/main/services/download-manager.ts index 2a7532a4..379e25cd 100644 --- a/src/main/services/download-manager.ts +++ b/src/main/services/download-manager.ts @@ -50,6 +50,7 @@ export class DownloadManager { public static disconnect() { if (this.aria2c) { this.aria2c.kill(); + this.connected = false; } } diff --git a/src/main/services/index.ts b/src/main/services/index.ts index c30fbfe2..42017774 100644 --- a/src/main/services/index.ts +++ b/src/main/services/index.ts @@ -8,3 +8,4 @@ export * from "./how-long-to-beat"; export * from "./process-watcher"; export * from "./main-loop"; export * from "./repacks-manager"; +export * from "./hydra-api"; diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index fc97ff40..f20b4128 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -7,7 +7,7 @@ import { WindowManager } from "./window-manager"; import { createGame, updateGamePlaytime } from "./library-sync"; import { GameRunning } from "@types"; -const gamesPlaytime = new Map< +export const gamesPlaytime = new Map< number, { lastTick: number; firstTick: number } >(); diff --git a/src/renderer/src/app.tsx b/src/renderer/src/app.tsx index d98f1e1f..0f9d3972 100644 --- a/src/renderer/src/app.tsx +++ b/src/renderer/src/app.tsx @@ -96,11 +96,11 @@ export function App() { window.electron.isUserLoggedIn().then((isLoggedIn) => { if (isLoggedIn) { fetchUserDetails().then((response) => { - if (response) setUserDetails(response); + if (response) updateUserDetails(response); }); } }); - }, [dispatch, fetchUserDetails]); + }, [fetchUserDetails, updateUserDetails, dispatch]); const onSignIn = useCallback(() => { fetchUserDetails().then((response) => { From 2f4d1396a9d7378c95e4e7c569a60f8fb88f089d Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Fri, 21 Jun 2024 01:51:24 +0100 Subject: [PATCH 3/4] feat: adding link to game running --- src/main/events/auth/sign-out.ts | 14 ++++++------- src/renderer/src/pages/user/user-content.tsx | 21 +++++++++----------- src/renderer/src/pages/user/user.css.ts | 10 ++++++++++ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/main/events/auth/sign-out.ts b/src/main/events/auth/sign-out.ts index b8b6cecd..56a4ce29 100644 --- a/src/main/events/auth/sign-out.ts +++ b/src/main/events/auth/sign-out.ts @@ -4,8 +4,8 @@ import { dataSource } from "@main/data-source"; import { DownloadQueue, Game, UserAuth } from "@main/entity"; const signOut = async (_event: Electron.IpcMainInvokeEvent) => { - const databaseOperations = dataSource.transaction( - async (transactionalEntityManager) => { + const databaseOperations = dataSource + .transaction(async (transactionalEntityManager) => { await transactionalEntityManager.getRepository(DownloadQueue).delete({}); await transactionalEntityManager.getRepository(Game).delete({}); @@ -13,11 +13,11 @@ const signOut = async (_event: Electron.IpcMainInvokeEvent) => { await transactionalEntityManager .getRepository(UserAuth) .delete({ id: 1 }); - } - ); - - /* Removes all games being played */ - gamesPlaytime.clear(); + }) + .then(() => { + /* Removes all games being played */ + gamesPlaytime.clear(); + }); /* Disconnects aria2 */ DownloadManager.disconnect(); diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index ad620868..55dcc17f 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -15,7 +15,7 @@ import { import { useNavigate } from "react-router-dom"; import { buildGameDetailsPath, steamUrlBuilder } from "@renderer/helpers"; import { PersonIcon, TelescopeIcon } from "@primer/octicons-react"; -import { Button } from "@renderer/components"; +import { Button, Link } from "@renderer/components"; import { UserEditProfileModal } from "./user-edit-modal"; import { UserSignOutModal } from "./user-signout-modal"; @@ -114,16 +114,11 @@ export function UserContent({ }} > {gameRunning && isMe && ( -
+ {gameRunning.title} )}
-

{gameRunning.title}

+ + {gameRunning.title} +
{t("playing_for", { diff --git a/src/renderer/src/pages/user/user.css.ts b/src/renderer/src/pages/user/user.css.ts index 63871c26..299aa393 100644 --- a/src/renderer/src/pages/user/user.css.ts +++ b/src/renderer/src/pages/user/user.css.ts @@ -205,3 +205,13 @@ export const signOutModalButtonsContainer = style({ gap: `${SPACING_UNIT}px`, paddingTop: `${SPACING_UNIT}px`, }); + +export const profileBackground = style({ + width: "100%", + height: "100%", + position: "absolute", + objectFit: "cover", + left: "0", + top: "0", + borderRadius: "4px", +}); From cee6f373eb6194a45c64fe70646606a014ba8a6c Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 20 Jun 2024 22:07:23 -0300 Subject: [PATCH 4/4] fix: last time played --- src/main/services/library-sync/merge-with-remote-games.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/services/library-sync/merge-with-remote-games.ts b/src/main/services/library-sync/merge-with-remote-games.ts index 460cad0f..70a2ee59 100644 --- a/src/main/services/library-sync/merge-with-remote-games.ts +++ b/src/main/services/library-sync/merge-with-remote-games.ts @@ -21,7 +21,7 @@ export const mergeWithRemoteGames = async () => { localGame.lastTimePlayed == null || (game.lastTimePlayed && new Date(game.lastTimePlayed) > localGame.lastTimePlayed) - ? new Date(game.lastTimePlayed) + ? game.lastTimePlayed : localGame.lastTimePlayed; const updatedPlayTime =