mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
fix possibility of 404 on home if getRandomGame has no validy elements to return
this can happen when user has no internet connection when opening hydra
This commit is contained in:
parent
2904302c81
commit
a8b236e02c
2 changed files with 21 additions and 20 deletions
|
@ -7,22 +7,25 @@ export interface Steam250Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const requestSteam250 = async (path: string) => {
|
export const requestSteam250 = async (path: string) => {
|
||||||
return axios.get(`https://steam250.com${path}`).then((response) => {
|
return axios
|
||||||
const { window } = new JSDOM(response.data);
|
.get(`https://steam250.com${path}`)
|
||||||
const { document } = window;
|
.then((response) => {
|
||||||
|
const { window } = new JSDOM(response.data);
|
||||||
|
const { document } = window;
|
||||||
|
|
||||||
return Array.from(document.querySelectorAll(".appline .title a"))
|
return Array.from(document.querySelectorAll(".appline .title a"))
|
||||||
.map(($title: HTMLAnchorElement) => {
|
.map(($title: HTMLAnchorElement) => {
|
||||||
const steamGameUrl = $title.href;
|
const steamGameUrl = $title.href;
|
||||||
if (!steamGameUrl) return null;
|
if (!steamGameUrl) return null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: $title.textContent,
|
title: $title.textContent,
|
||||||
objectID: steamGameUrl.split("/").pop(),
|
objectID: steamGameUrl.split("/").pop(),
|
||||||
} as Steam250Game;
|
} as Steam250Game;
|
||||||
})
|
})
|
||||||
.filter((game) => game != null);
|
.filter((game) => game != null);
|
||||||
});
|
})
|
||||||
|
.catch((_) => []);
|
||||||
};
|
};
|
||||||
|
|
||||||
const steam250Paths = [
|
const steam250Paths = [
|
||||||
|
|
|
@ -58,14 +58,12 @@ export function Home() {
|
||||||
const getRandomGame = useCallback(() => {
|
const getRandomGame = useCallback(() => {
|
||||||
setIsLoadingRandomGame(true);
|
setIsLoadingRandomGame(true);
|
||||||
|
|
||||||
window.electron
|
window.electron.getRandomGame().then((objectID) => {
|
||||||
.getRandomGame()
|
if (objectID) {
|
||||||
.then((objectID) => {
|
|
||||||
randomGameObjectID.current = objectID;
|
randomGameObjectID.current = objectID;
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
setIsLoadingRandomGame(false);
|
setIsLoadingRandomGame(false);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleRandomizerClick = () => {
|
const handleRandomizerClick = () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue