feat: updating play label on hero panel

This commit is contained in:
Hydra
2024-04-18 22:26:17 +01:00
parent 91b1341271
commit 96e11e6be9
40 changed files with 2049 additions and 745 deletions

View File

@@ -46,7 +46,9 @@ export const startProcessWatcher = async () => {
const zero = gamesPlaytime.get(game.id);
const delta = performance.now() - zero;
WindowManager.mainWindow.webContents.send("on-playtime", game.id);
if (WindowManager.mainWindow) {
WindowManager.mainWindow.webContents.send("on-playtime", game.id);
}
await gameRepository.update(game.id, {
playTimeInMilliseconds: game.playTimeInMilliseconds + delta,
@@ -68,7 +70,9 @@ export const startProcessWatcher = async () => {
if (gamesPlaytime.has(game.id)) {
gamesPlaytime.delete(game.id);
WindowManager.mainWindow.webContents.send("on-game-close", game.id);
if (WindowManager.mainWindow) {
WindowManager.mainWindow.webContents.send("on-game-close", game.id);
}
}
await sleep(sleepTime);

View File

@@ -1,26 +1,24 @@
import axios from "axios";
import { JSDOM } from "jsdom";
import shuffle from "lodash/shuffle";
import { logger } from "./logger";
const requestSteam250 = async (path: string) => {
return axios
.get(`https://steam250.com${path}`)
.then((response) => response.data);
};
export const requestSteam250 = async (path: string) => {
return axios.get(`https://steam250.com${path}`).then((response) => {
const { window } = new JSDOM(response.data);
const { document } = window;
export const getTrendingGames = async () => {
const response = await requestSteam250("/365day").catch((err) => {
logger.error(err.response, { method: "getTrendingGames" });
throw new Error(err);
return Array.from(document.querySelectorAll(".appline .title a")).map(
($title: HTMLAnchorElement) => {
const steamGameUrl = $title.href;
if (!steamGameUrl) return null;
return {
title: $title.textContent,
objectID: steamGameUrl.split("/").pop(),
};
}
);
});
const { window } = new JSDOM(response);
const { document } = window;
return Array.from(document.querySelectorAll(".appline .title a")).map(
($title) => $title.textContent!
);
};
const steam250Paths = [
@@ -32,15 +30,5 @@ const steam250Paths = [
export const getRandomSteam250List = async () => {
const [path] = shuffle(steam250Paths);
const response = await requestSteam250(path).catch((err) => {
logger.error(err.response, { method: "getRandomSteam250List" });
throw new Error(err);
});
const { window } = new JSDOM(response);
const { document } = window;
return Array.from(document.querySelectorAll(".appline .title a")).map(
($title) => $title.textContent!
);
return requestSteam250(path);
};

View File

@@ -1,5 +1,4 @@
import axios from "axios";
import { JSDOM } from "jsdom";
import type { SteamAppDetails } from "@types";
@@ -34,45 +33,3 @@ export const getSteamAppDetails = async (
throw new Error(err);
});
};
export const searchSteamGame = async (term: string) => {
const searchParams = new URLSearchParams({
start: "0",
count: "12",
sort_by: "_ASC",
/* Games only */
category1: "998",
term: term,
});
const response = await axios.get(
`https://store.steampowered.com/search/results/?${searchParams.toString()}`
);
const { window } = new JSDOM(response.data);
const { document } = window;
const $anchors = Array.from(
document.querySelectorAll("#search_resultsRows a")
);
return $anchors.reduce((prev, $a) => {
const $title = $a.querySelector(".title");
const objectIDs = $a.getAttribute("data-ds-appid");
if (!objectIDs) return prev;
const [objectID] = objectIDs.split(",");
if (!objectID || prev.some((game) => game.objectID === objectID))
return prev;
return [
...prev,
{
name: $title.textContent,
objectID,
},
];
}, []);
};

View File

@@ -4,11 +4,12 @@ import { app } from "electron";
import chunk from "lodash/chunk";
import { createDataSource, dataSource } from "@main/data-source";
import { Repack, RepackerFriendlyName } from "@main/entity";
import { Repack, RepackerFriendlyName, SteamGame } from "@main/entity";
import {
migrationScriptRepository,
repackRepository,
repackerFriendlyNameRepository,
steamGameRepository,
} from "@main/repository";
import { MigrationScript } from "@main/entity/migration-script.entity";
import { Like } from "typeorm";
@@ -115,11 +116,14 @@ export const resolveDatabaseUpdates = async () => {
const updateRepackRepository = updateDataSource.getRepository(Repack);
const updateRepackerFriendlyNameRepository =
updateDataSource.getRepository(RepackerFriendlyName);
const updateSteamGameRepository = updateDataSource.getRepository(SteamGame);
const [updateRepacks, updateRepackerFriendlyNames] = await Promise.all([
updateRepackRepository.find(),
updateRepackerFriendlyNameRepository.find(),
]);
const [updateRepacks, updateSteamGames, updateRepackerFriendlyNames] =
await Promise.all([
updateRepackRepository.find(),
updateSteamGameRepository.find(),
updateRepackerFriendlyNameRepository.find(),
]);
await runMigrationScripts(updateRepacks);
@@ -140,5 +144,16 @@ export const resolveDatabaseUpdates = async () => {
.orIgnore()
.execute();
}
const steamGamesChunks = chunk(updateSteamGames, 800);
for (const chunk of steamGamesChunks) {
await steamGameRepository
.createQueryBuilder()
.insert()
.values(chunk)
.orIgnore()
.execute();
}
});
};