Merge branch 'main' of https://github.com/hydralauncher/hydra into feat/custom-games-support

This commit is contained in:
Moyasee
2025-09-28 17:39:07 +03:00
48 changed files with 1577 additions and 311 deletions

View File

@@ -19,6 +19,7 @@ import "./library/update-custom-game";
import "./library/update-game-custom-assets";
import "./library/add-game-to-favorites";
import "./library/remove-game-from-favorites";
import "./library/toggle-game-pin";
import "./library/create-game-shortcut";
import "./library/close-game";
import "./library/delete-game-folder";
@@ -71,6 +72,7 @@ import "./auth/sign-out";
import "./auth/open-auth-window";
import "./auth/get-session-hash";
import "./user/get-user";
import "./user/get-user-library";
import "./user/get-blocked-users";
import "./user/block-user";
import "./user/unblock-user";

View File

@@ -0,0 +1,43 @@
import { registerEvent } from "../register-event";
import { gamesSublevel, levelKeys } from "@main/level";
import { HydraApi, logger } from "@main/services";
import type { GameShop, UserGame } from "@types";
const toggleGamePin = async (
_event: Electron.IpcMainInvokeEvent,
shop: GameShop,
objectId: string,
pin: boolean
) => {
try {
const gameKey = levelKeys.game(shop, objectId);
const game = await gamesSublevel.get(gameKey);
if (!game) return;
if (pin) {
const response = await HydraApi.put<UserGame>(
`/profile/games/${shop}/${objectId}/pin`
);
await gamesSublevel.put(gameKey, {
...game,
isPinned: pin,
pinnedDate: new Date(response.pinnedDate!),
});
} else {
await HydraApi.put(`/profile/games/${shop}/${objectId}/unpin`);
await gamesSublevel.put(gameKey, {
...game,
isPinned: pin,
pinnedDate: null,
});
}
} catch (error) {
logger.error("Failed to update game pinned status", error);
throw new Error(`Failed to update game pinned status: ${error}`);
}
};
registerEvent("toggleGamePin", toggleGamePin);

View File

@@ -0,0 +1,28 @@
import { registerEvent } from "../register-event";
import { HydraApi } from "@main/services";
import type { UserLibraryResponse } from "@types";
const getUserLibrary = async (
_event: Electron.IpcMainInvokeEvent,
userId: string,
take: number = 12,
skip: number = 0,
sortBy?: string
): Promise<UserLibraryResponse | null> => {
const params = new URLSearchParams();
params.append("take", take.toString());
params.append("skip", skip.toString());
if (sortBy) {
params.append("sortBy", sortBy);
}
const queryString = params.toString();
const baseUrl = `/users/${userId}/library`;
const url = queryString ? `${baseUrl}?${queryString}` : baseUrl;
return HydraApi.get<UserLibraryResponse>(url).catch(() => null);
};
registerEvent("getUserLibrary", getUserLibrary);

View File

@@ -8,6 +8,7 @@ type ProfileGame = {
playTimeInMilliseconds: number;
hasManuallyUpdatedPlaytime: boolean;
isFavorite?: boolean;
isPinned?: boolean;
} & ShopAssets;
export const mergeWithRemoteGames = async () => {
@@ -36,6 +37,7 @@ export const mergeWithRemoteGames = async () => {
lastTimePlayed: updatedLastTimePlayed,
playTimeInMilliseconds: updatedPlayTime,
favorite: game.isFavorite ?? localGame.favorite,
isPinned: game.isPinned ?? localGame.isPinned,
});
} else {
await gamesSublevel.put(gameKey, {
@@ -51,6 +53,7 @@ export const mergeWithRemoteGames = async () => {
hasManuallyUpdatedPlaytime: game.hasManuallyUpdatedPlaytime,
isDeleted: false,
favorite: game.isFavorite ?? false,
isPinned: game.isPinned ?? false,
});
}

View File

@@ -28,6 +28,7 @@ export const uploadGamesBatch = async () => {
shop: game.shop,
lastTimePlayed: game.lastTimePlayed,
isFavorite: game.favorite,
isPinned: game.isPinned ?? false,
};
})
).catch(() => {});