Merge pull request #620 from hydralauncher/feature/improve-sign-out

Feature/improve sign out
This commit is contained in:
Zamitto 2024-06-20 22:13:08 -03:00 committed by GitHub
commit 458acb0b70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 55 additions and 28 deletions

View File

@ -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";

View File

@ -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 });
})
.then(() => {
/* Removes all games being played */
gamesPlaytime.clear();
});
/* Disconnects aria2 */
DownloadManager.disconnect();
const signOut = async (_event: Electron.IpcMainInvokeEvent): Promise<void> => {
await Promise.all([
userAuthRepository.delete({ id: 1 }),
gameRepository.delete({}),
databaseOperations,
HydraApi.post("/auth/logout").catch(),
]);
};

View File

@ -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,

View File

@ -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();

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -6,8 +6,8 @@ import {
GameShopCache,
Repack,
UserPreferences,
UserAuth,
} from "@main/entity";
import { UserAuth } from "./entity/user-auth";
export const gameRepository = dataSource.getRepository(Game);

View File

@ -50,6 +50,7 @@ export class DownloadManager {
public static disconnect() {
if (this.aria2c) {
this.aria2c.kill();
this.connected = false;
}
}

View File

@ -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";

View File

@ -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 =

View File

@ -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 }
>();

View File

@ -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) => {

View File

@ -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 && (
<div
style={{
backgroundImage: `url(${steamUrlBuilder.libraryHero(gameRunning.objectID)})`,
backgroundPosition: "top",
position: "absolute",
inset: 0,
backgroundSize: "cover",
borderRadius: "4px",
}}
></div>
<img
src={steamUrlBuilder.libraryHero(gameRunning.objectID)}
alt={gameRunning.title}
className={styles.profileBackground}
/>
)}
<div
@ -165,7 +160,9 @@ export function UserContent({
alignItems: "center",
}}
>
<p>{gameRunning.title}</p>
<Link to={buildGameDetailsPath(gameRunning)}>
{gameRunning.title}
</Link>
</div>
<small>
{t("playing_for", {

View File

@ -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",
});