mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-26 12:21:03 +00:00
feat: refactor
This commit is contained in:
@@ -16,7 +16,7 @@ import { IsNull, Not } from "typeorm";
|
||||
const fileStats: Map<string, number> = new Map();
|
||||
const fltFiles: Map<string, Set<string>> = new Map();
|
||||
|
||||
const watchAchiievementsWindows = async () => {
|
||||
const watchAchievementsWindows = async () => {
|
||||
const games = await gameRepository.find({
|
||||
where: {
|
||||
isDeleted: false,
|
||||
@@ -53,12 +53,17 @@ const watchAchievementsWithWine = async () => {
|
||||
|
||||
if (games.length === 0) return;
|
||||
|
||||
// const user = app.getPath("home").split("/").pop()
|
||||
|
||||
// for (const game of games) {
|
||||
// }
|
||||
|
||||
// TODO: watch achievements with wine
|
||||
};
|
||||
|
||||
export const watchAchievements = async () => {
|
||||
if (process.platform === "win32") {
|
||||
return watchAchiievementsWindows();
|
||||
return watchAchievementsWindows();
|
||||
}
|
||||
|
||||
watchAchievementsWithWine();
|
||||
@@ -101,10 +106,9 @@ const compareFltFolder = async (game: Game, file: AchievementFile) => {
|
||||
}
|
||||
};
|
||||
|
||||
const compareFile = async (game: Game, file: AchievementFile) => {
|
||||
const compareFile = (game: Game, file: AchievementFile) => {
|
||||
if (file.type === Cracker.flt) {
|
||||
await compareFltFolder(game, file);
|
||||
return;
|
||||
return compareFltFolder(game, file);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -121,8 +125,7 @@ const compareFile = async (game: Game, file: AchievementFile) => {
|
||||
currentStat.mtimeMs
|
||||
);
|
||||
|
||||
await processAchievementFileDiff(game, file);
|
||||
return;
|
||||
return processAchievementFileDiff(game, file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,8 +139,9 @@ const compareFile = async (game: Game, file: AchievementFile) => {
|
||||
previousStat,
|
||||
currentStat.mtimeMs
|
||||
);
|
||||
await processAchievementFileDiff(game, file);
|
||||
return processAchievementFileDiff(game, file);
|
||||
} catch (err) {
|
||||
fileStats.set(file.filePath, -1);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,13 +3,13 @@ import {
|
||||
userPreferencesRepository,
|
||||
} from "@main/repository";
|
||||
import { HydraApi } from "../hydra-api";
|
||||
import { AchievementData } from "@types";
|
||||
import type { AchievementData, GameShop } from "@types";
|
||||
import { UserNotLoggedInError } from "@shared";
|
||||
import { logger } from "../logger";
|
||||
|
||||
export const getGameAchievementData = async (
|
||||
objectId: string,
|
||||
shop: string
|
||||
shop: GameShop
|
||||
) => {
|
||||
const userPreferences = await userPreferencesRepository.findOne({
|
||||
where: { id: 1 },
|
||||
|
||||
@@ -6,11 +6,11 @@ import {
|
||||
import type { AchievementData, GameShop, UnlockedAchievement } from "@types";
|
||||
import { WindowManager } from "../window-manager";
|
||||
import { HydraApi } from "../hydra-api";
|
||||
import { getGameAchievements } from "@main/events/catalogue/get-game-achievements";
|
||||
import { getUnlockedAchievements } from "@main/events/user/get-unlocked-achievements";
|
||||
|
||||
const saveAchievementsOnLocal = async (
|
||||
objectId: string,
|
||||
shop: string,
|
||||
shop: GameShop,
|
||||
achievements: any[]
|
||||
) => {
|
||||
return gameAchievementRepository
|
||||
@@ -23,7 +23,7 @@ const saveAchievementsOnLocal = async (
|
||||
["objectId", "shop"]
|
||||
)
|
||||
.then(() => {
|
||||
return getGameAchievements(objectId, shop as GameShop)
|
||||
return getUnlockedAchievements(objectId, shop)
|
||||
.then((achievements) => {
|
||||
WindowManager.mainWindow?.webContents.send(
|
||||
`on-update-achievements-${objectId}-${shop}`,
|
||||
@@ -36,12 +36,12 @@ const saveAchievementsOnLocal = async (
|
||||
|
||||
export const mergeAchievements = async (
|
||||
objectId: string,
|
||||
shop: string,
|
||||
shop: GameShop,
|
||||
achievements: UnlockedAchievement[],
|
||||
publishNotification: boolean
|
||||
) => {
|
||||
const game = await gameRepository.findOne({
|
||||
where: { objectID: objectId, shop: shop as GameShop },
|
||||
where: { objectID: objectId, shop: shop },
|
||||
});
|
||||
|
||||
if (!game) return;
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
startTorrentClient as startRPCClient,
|
||||
} from "./torrent-client";
|
||||
import { gameRepository } from "@main/repository";
|
||||
import { DownloadProgress } from "@types";
|
||||
import type { DownloadProgress } from "@types";
|
||||
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
|
||||
import { calculateETA } from "./helpers";
|
||||
import axios from "axios";
|
||||
|
||||
Reference in New Issue
Block a user