mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-12 19:22:28 +00:00
Merge pull request #620 from hydralauncher/feature/improve-sign-out
Feature/improve sign out
This commit is contained in:
commit
458acb0b70
15 changed files with 55 additions and 28 deletions
|
@ -4,3 +4,4 @@ export * from "./user-preferences.entity";
|
||||||
export * from "./game-shop-cache.entity";
|
export * from "./game-shop-cache.entity";
|
||||||
export * from "./download-source.entity";
|
export * from "./download-source.entity";
|
||||||
export * from "./download-queue.entity";
|
export * from "./download-queue.entity";
|
||||||
|
export * from "./user-auth";
|
||||||
|
|
|
@ -1,11 +1,29 @@
|
||||||
import { gameRepository, userAuthRepository } from "@main/repository";
|
|
||||||
import { registerEvent } from "../register-event";
|
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([
|
await Promise.all([
|
||||||
userAuthRepository.delete({ id: 1 }),
|
databaseOperations,
|
||||||
gameRepository.delete({}),
|
|
||||||
HydraApi.post("/auth/logout").catch(),
|
HydraApi.post("/auth/logout").catch(),
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import { gameRepository } from "../../repository";
|
import { gameRepository } from "../../repository";
|
||||||
import { HydraApi } from "@main/services/hydra-api";
|
import { HydraApi, logger } from "@main/services";
|
||||||
import { logger } from "@main/services";
|
|
||||||
|
|
||||||
const removeGameFromLibrary = async (
|
const removeGameFromLibrary = async (
|
||||||
_event: Electron.IpcMainInvokeEvent,
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import { HydraApi } from "@main/services/hydra-api";
|
import { HydraApi } from "@main/services";
|
||||||
|
|
||||||
const isUserLoggedIn = async (_event: Electron.IpcMainInvokeEvent) => {
|
const isUserLoggedIn = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||||
return HydraApi.isLoggedIn();
|
return HydraApi.isLoggedIn();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import { HydraApi } from "@main/services/hydra-api";
|
import { HydraApi } from "@main/services";
|
||||||
import { UserProfile } from "@types";
|
import { UserProfile } from "@types";
|
||||||
import { userAuthRepository } from "@main/repository";
|
import { userAuthRepository } from "@main/repository";
|
||||||
import { logger } from "@main/services";
|
import { logger } from "@main/services";
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import { HydraApi } from "@main/services/hydra-api";
|
import { HydraApi } from "@main/services";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import { HydraApi } from "@main/services/hydra-api";
|
import { HydraApi } from "@main/services";
|
||||||
import { steamGamesWorker } from "@main/workers";
|
import { steamGamesWorker } from "@main/workers";
|
||||||
import { UserProfile } from "@types";
|
import { UserProfile } from "@types";
|
||||||
import { convertSteamGameToCatalogueEntry } from "../helpers/search-games";
|
import { convertSteamGameToCatalogueEntry } from "../helpers/search-games";
|
||||||
|
|
|
@ -6,8 +6,8 @@ import {
|
||||||
GameShopCache,
|
GameShopCache,
|
||||||
Repack,
|
Repack,
|
||||||
UserPreferences,
|
UserPreferences,
|
||||||
|
UserAuth,
|
||||||
} from "@main/entity";
|
} from "@main/entity";
|
||||||
import { UserAuth } from "./entity/user-auth";
|
|
||||||
|
|
||||||
export const gameRepository = dataSource.getRepository(Game);
|
export const gameRepository = dataSource.getRepository(Game);
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ export class DownloadManager {
|
||||||
public static disconnect() {
|
public static disconnect() {
|
||||||
if (this.aria2c) {
|
if (this.aria2c) {
|
||||||
this.aria2c.kill();
|
this.aria2c.kill();
|
||||||
|
this.connected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,3 +8,4 @@ export * from "./how-long-to-beat";
|
||||||
export * from "./process-watcher";
|
export * from "./process-watcher";
|
||||||
export * from "./main-loop";
|
export * from "./main-loop";
|
||||||
export * from "./repacks-manager";
|
export * from "./repacks-manager";
|
||||||
|
export * from "./hydra-api";
|
||||||
|
|
|
@ -21,7 +21,7 @@ export const mergeWithRemoteGames = async () => {
|
||||||
localGame.lastTimePlayed == null ||
|
localGame.lastTimePlayed == null ||
|
||||||
(game.lastTimePlayed &&
|
(game.lastTimePlayed &&
|
||||||
new Date(game.lastTimePlayed) > localGame.lastTimePlayed)
|
new Date(game.lastTimePlayed) > localGame.lastTimePlayed)
|
||||||
? new Date(game.lastTimePlayed)
|
? game.lastTimePlayed
|
||||||
: localGame.lastTimePlayed;
|
: localGame.lastTimePlayed;
|
||||||
|
|
||||||
const updatedPlayTime =
|
const updatedPlayTime =
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { WindowManager } from "./window-manager";
|
||||||
import { createGame, updateGamePlaytime } from "./library-sync";
|
import { createGame, updateGamePlaytime } from "./library-sync";
|
||||||
import { GameRunning } from "@types";
|
import { GameRunning } from "@types";
|
||||||
|
|
||||||
const gamesPlaytime = new Map<
|
export const gamesPlaytime = new Map<
|
||||||
number,
|
number,
|
||||||
{ lastTick: number; firstTick: number }
|
{ lastTick: number; firstTick: number }
|
||||||
>();
|
>();
|
||||||
|
|
|
@ -96,11 +96,11 @@ export function App() {
|
||||||
window.electron.isUserLoggedIn().then((isLoggedIn) => {
|
window.electron.isUserLoggedIn().then((isLoggedIn) => {
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
fetchUserDetails().then((response) => {
|
fetchUserDetails().then((response) => {
|
||||||
if (response) setUserDetails(response);
|
if (response) updateUserDetails(response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [dispatch, fetchUserDetails]);
|
}, [fetchUserDetails, updateUserDetails, dispatch]);
|
||||||
|
|
||||||
const onSignIn = useCallback(() => {
|
const onSignIn = useCallback(() => {
|
||||||
fetchUserDetails().then((response) => {
|
fetchUserDetails().then((response) => {
|
||||||
|
|
|
@ -15,7 +15,7 @@ import {
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { buildGameDetailsPath, steamUrlBuilder } from "@renderer/helpers";
|
import { buildGameDetailsPath, steamUrlBuilder } from "@renderer/helpers";
|
||||||
import { PersonIcon, TelescopeIcon } from "@primer/octicons-react";
|
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 { UserEditProfileModal } from "./user-edit-modal";
|
||||||
import { UserSignOutModal } from "./user-signout-modal";
|
import { UserSignOutModal } from "./user-signout-modal";
|
||||||
|
|
||||||
|
@ -114,16 +114,11 @@ export function UserContent({
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{gameRunning && isMe && (
|
{gameRunning && isMe && (
|
||||||
<div
|
<img
|
||||||
style={{
|
src={steamUrlBuilder.libraryHero(gameRunning.objectID)}
|
||||||
backgroundImage: `url(${steamUrlBuilder.libraryHero(gameRunning.objectID)})`,
|
alt={gameRunning.title}
|
||||||
backgroundPosition: "top",
|
className={styles.profileBackground}
|
||||||
position: "absolute",
|
/>
|
||||||
inset: 0,
|
|
||||||
backgroundSize: "cover",
|
|
||||||
borderRadius: "4px",
|
|
||||||
}}
|
|
||||||
></div>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
@ -165,7 +160,9 @@ export function UserContent({
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<p>{gameRunning.title}</p>
|
<Link to={buildGameDetailsPath(gameRunning)}>
|
||||||
|
{gameRunning.title}
|
||||||
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<small>
|
<small>
|
||||||
{t("playing_for", {
|
{t("playing_for", {
|
||||||
|
|
|
@ -205,3 +205,13 @@ export const signOutModalButtonsContainer = style({
|
||||||
gap: `${SPACING_UNIT}px`,
|
gap: `${SPACING_UNIT}px`,
|
||||||
paddingTop: `${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",
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue