mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-20 01:33:56 +00:00
feat: updating play label on hero panel
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
];
|
||||
}, []);
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user