feat: improve sign out

This commit is contained in:
Chubby Granny Chaser 2024-06-21 01:34:59 +01:00
parent 0ac17e95ff
commit 8afb3c27dc
No known key found for this signature in database
12 changed files with 35 additions and 15 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 });
}
);
/* 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

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