Skip to content

Commit

Permalink
Merge branch 'main' of github.com:hydralauncher/hydra
Browse files Browse the repository at this point in the history
  • Loading branch information
thegrannychaseroperation committed Dec 2, 2024
2 parents 8b4791f + 870e459 commit e9fddd2
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 174 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
MAIN_VITE_CHECKOUT_URL: ${{ vars.MAIN_VITE_STAGING_CHECKOUT_URL }}
MAIN_VITE_ANALYTICS_API_URL: ${{ vars.MAIN_VITE_ANALYTICS_API_URL }}
RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }}
RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build Windows
Expand All @@ -59,6 +60,7 @@ jobs:
MAIN_VITE_CHECKOUT_URL: ${{ vars.MAIN_VITE_STAGING_CHECKOUT_URL }}
MAIN_VITE_ANALYTICS_API_URL: ${{ vars.MAIN_VITE_ANALYTICS_API_URL }}
RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }}
RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create artifact
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
MAIN_VITE_CHECKOUT_URL: ${{ vars.MAIN_VITE_CHECKOUT_URL }}
MAIN_VITE_ANALYTICS_API_URL: ${{ vars.MAIN_VITE_ANALYTICS_API_URL }}
RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }}
RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build Windows
if: matrix.os == 'windows-latest'
Expand All @@ -57,6 +58,7 @@ jobs:
MAIN_VITE_CHECKOUT_URL: ${{ vars.MAIN_VITE_CHECKOUT_URL }}
MAIN_VITE_ANALYTICS_API_URL: ${{ vars.MAIN_VITE_ANALYTICS_API_URL }}
RENDERER_VITE_INTERCOM_APP_ID: ${{ vars.RENDERER_VITE_INTERCOM_APP_ID }}
RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.RENDERER_VITE_EXTERNAL_RESOURCES_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create artifact
uses: actions/upload-artifact@v4
Expand Down
22 changes: 10 additions & 12 deletions src/main/events/catalogue/get-how-long-to-beat.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import type { HowLongToBeatCategory } from "@types";
import { getHowLongToBeatGame, searchHowLongToBeat } from "@main/services";
import type { GameShop, HowLongToBeatCategory } from "@types";

import { registerEvent } from "../register-event";
import { formatName } from "@shared";
import { HydraApi } from "@main/services";

const getHowLongToBeat = async (
_event: Electron.IpcMainInvokeEvent,
title: string
objectId: string,
shop: GameShop
): Promise<HowLongToBeatCategory[] | null> => {
const response = await searchHowLongToBeat(title);

const game = response.data.find((game) => {
return formatName(game.game_name) === formatName(title);
const params = new URLSearchParams({
objectId,
shop,
});

if (!game) return null;
const howLongToBeat = await getHowLongToBeatGame(String(game.game_id));

return howLongToBeat;
return HydraApi.get(`/games/how-long-to-beat?${params.toString()}`, null, {
needsAuth: false,
});
};

registerEvent("getHowLongToBeat", getHowLongToBeat);
3 changes: 2 additions & 1 deletion src/main/events/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { appVersion, defaultDownloadsPath } from "@main/constants";
import { appVersion, defaultDownloadsPath, isStaging } from "@main/constants";
import { ipcMain } from "electron";

import "./catalogue/get-catalogue";
Expand Down Expand Up @@ -72,5 +72,6 @@ import "./misc/show-item-in-folder";

ipcMain.handle("ping", () => "pong");
ipcMain.handle("getVersion", () => appVersion);
ipcMain.handle("isStaging", () => isStaging);
ipcMain.handle("isPortableVersion", () => isPortableVersion());
ipcMain.handle("getDefaultDownloadsPath", () => defaultDownloadsPath);
108 changes: 0 additions & 108 deletions src/main/services/how-long-to-beat.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/main/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export * from "./steam-250";
export * from "./steam-grid";
export * from "./window-manager";
export * from "./download";
export * from "./how-long-to-beat";
export * from "./process-watcher";
export * from "./main-loop";
export * from "./hydra-api";
Expand Down
7 changes: 3 additions & 4 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type {
import type { CatalogueCategory } from "@shared";
import type { AxiosProgressEvent } from "axios";
import { GameAchievement } from "@main/entity";
import { isStaging } from "@main/constants";

contextBridge.exposeInMainWorld("electron", {
/* Torrenting */
Expand Down Expand Up @@ -43,8 +42,8 @@ contextBridge.exposeInMainWorld("electron", {
getGameShopDetails: (objectId: string, shop: GameShop, language: string) =>
ipcRenderer.invoke("getGameShopDetails", objectId, shop, language),
getRandomGame: () => ipcRenderer.invoke("getRandomGame"),
getHowLongToBeat: (title: string) =>
ipcRenderer.invoke("getHowLongToBeat", title),
getHowLongToBeat: (objectId: string, shop: GameShop) =>
ipcRenderer.invoke("getHowLongToBeat", objectId, shop),
getGames: (take?: number, skip?: number) =>
ipcRenderer.invoke("getGames", take, skip),
searchGameRepacks: (query: string) =>
Expand Down Expand Up @@ -199,7 +198,7 @@ contextBridge.exposeInMainWorld("electron", {
ping: () => ipcRenderer.invoke("ping"),
getVersion: () => ipcRenderer.invoke("getVersion"),
getDefaultDownloadsPath: () => ipcRenderer.invoke("getDefaultDownloadsPath"),
isStaging,
isStaging: () => ipcRenderer.invoke("isStaging"),
isPortableVersion: () => ipcRenderer.invoke("isPortableVersion"),
openExternal: (src: string) => ipcRenderer.invoke("openExternal", src),
openCheckout: () => ipcRenderer.invoke("openCheckout"),
Expand Down
4 changes: 0 additions & 4 deletions src/renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
http-equiv="Content-Security-Policy"
content="default-src 'self' 'unsafe-inline' *;"
/>
<script
type="text/javascript"
src="%RENDERER_VITE_EXTERNAL_RESOURCES_URL%"
></script>
</head>
<body>
<div id="root"></div>
Expand Down
52 changes: 27 additions & 25 deletions src/renderer/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,6 @@ export function App() {
clearUserDetails,
} = useUserDetails();

useEffect(() => {
if (userDetails) {
const $existingScript = document.getElementById("user-details");

const content = `window.userDetails = ${JSON.stringify(userDetails)};`;

if ($existingScript) {
$existingScript.textContent = content;
} else {
const $script = document.createElement("script");
$script.id = "user-details";
$script.type = "text/javascript";
$script.textContent = content;

document.head.appendChild($script);
}
}
}, [userDetails]);

const dispatch = useAppDispatch();

const navigate = useNavigate();
Expand Down Expand Up @@ -133,12 +114,33 @@ export function App() {
dispatch(setProfileBackground(profileBackground));
}

fetchUserDetails().then((response) => {
if (response) {
updateUserDetails(response);
syncFriendRequests();
}
});
fetchUserDetails()
.then((response) => {
if (response) {
updateUserDetails(response);
syncFriendRequests();

const $existingScript = document.getElementById("user-details");

const content = `window.userDetails = ${JSON.stringify(response)};`;

if ($existingScript) {
$existingScript.textContent = content;
} else {
const $script = document.createElement("script");
$script.id = "user-details";
$script.type = "text/javascript";
$script.textContent = content;

document.head.appendChild($script);
}
}
})
.finally(() => {
const $script = document.createElement("script");
$script.src = `${import.meta.env.RENDERER_VITE_EXTERNAL_RESOURCES_URL}?t=${Date.now()}`;
document.head.appendChild($script);
});
}, [fetchUserDetails, syncFriendRequests, updateUserDetails, dispatch]);

const onSignIn = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export function GameDetailsContextProvider({
shop,
i18n.language,
userDetails,
userPreferences,
]);

useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/src/declaration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ declare global {
) => Promise<ShopDetails | null>;
getRandomGame: () => Promise<Steam250Game>;
getHowLongToBeat: (
title: string
objectId: string,
shop: GameShop
) => Promise<HowLongToBeatCategory[] | null>;
getGames: (take?: number, skip?: number) => Promise<CatalogueEntry[]>;
searchGameRepacks: (query: string) => Promise<GameRepack[]>;
Expand Down Expand Up @@ -162,6 +163,7 @@ declare global {
openExternal: (src: string) => Promise<void>;
openCheckout: () => Promise<void>;
getVersion: () => Promise<string>;
isStaging: () => Promise<boolean>;
ping: () => string;
getDefaultDownloadsPath: () => Promise<string>;
isPortableVersion: () => Promise<boolean>;
Expand Down Expand Up @@ -231,8 +233,6 @@ declare global {

/* Notifications */
publishNewRepacksNotification: (newRepacksCount: number) => Promise<void>;

isStaging: boolean;
}

interface Window {
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/src/pages/game-details/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ export function Sidebar() {
});
} else {
try {
const howLongToBeat =
await window.electron.getHowLongToBeat(gameTitle);
const howLongToBeat = await window.electron.getHowLongToBeat(
objectId,
shop
);

if (howLongToBeat) {
howLongToBeatEntriesTable.add({
Expand Down
32 changes: 18 additions & 14 deletions src/renderer/src/pages/profile/profile-content/profile-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,25 @@ export function ProfileContent() {
return userProfile?.relation?.status === "ACCEPTED";
}, [userProfile]);

const buildUserGameDetailsPath = (game: UserGame) => {
if (!userProfile?.hasActiveSubscription || game.achievementCount === 0) {
return buildGameDetailsPath({
...game,
objectId: game.objectId,
});
}
const buildUserGameDetailsPath = useCallback(
(game: UserGame) => {
if (!userProfile?.hasActiveSubscription || game.achievementCount === 0) {
return buildGameDetailsPath({
...game,
objectId: game.objectId,
});
}

const userParams = userProfile
? {
userId: userProfile.id,
}
: undefined;
const userParams = userProfile
? {
userId: userProfile.id,
}
: undefined;

return buildGameAchievementPath({ ...game }, userParams);
};
return buildGameAchievementPath({ ...game }, userParams);
},
[userProfile]
);

const formatPlayTime = useCallback(
(playTimeInSeconds = 0) => {
Expand Down Expand Up @@ -259,6 +262,7 @@ export function ProfileContent() {
userStats,
numberFormatter,
t,
buildUserGameDetailsPath,
formatPlayTime,
navigate,
]);
Expand Down
Loading

0 comments on commit e9fddd2

Please sign in to comment.