mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-15 04:32:13 +00:00
feat: improve sign out
This commit is contained in:
parent
0ac17e95ff
commit
8afb3c27dc
12 changed files with 35 additions and 15 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 });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/* 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";
|
||||||
|
|
|
@ -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) => {
|
||||||
|
|
Loading…
Reference in a new issue