Skip to content

Commit

Permalink
Merge pull request #902 from hydralauncher/feat/show-current-game-use…
Browse files Browse the repository at this point in the history
…r-profile

feat: show current game user profile
  • Loading branch information
zamitto authored Aug 20, 2024
2 parents 7e7c4da + 54516c1 commit cc9d254
Show file tree
Hide file tree
Showing 27 changed files with 288 additions and 235 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
MAIN_VITE_STEAMGRIDDB_API_KEY=YOUR_API_KEY
MAIN_VITE_API_URL=API_URL
MAIN_VITE_SENTRY_DSN=YOUR_SENTRY_DSN
SENTRY_AUTH_TOKEN=
4 changes: 0 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: yarn build:linux
env:
MAIN_VITE_ONLINEFIX_USERNAME: ${{ secrets.ONLINEFIX_USERNAME }}
MAIN_VITE_ONLINEFIX_PASSWORD: ${{ secrets.ONLINEFIX_PASSWORD }}
MAIN_VITE_API_URL: ${{ vars.MAIN_VITE_API_URL }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
MAIN_VITE_SENTRY_DSN: ${{ vars.MAIN_VITE_SENTRY_DSN }}
Expand All @@ -48,8 +46,6 @@ jobs:
if: matrix.os == 'windows-latest'
run: yarn build:win
env:
MAIN_VITE_ONLINEFIX_USERNAME: ${{ secrets.ONLINEFIX_USERNAME }}
MAIN_VITE_ONLINEFIX_PASSWORD: ${{ secrets.ONLINEFIX_PASSWORD }}
MAIN_VITE_API_URL: ${{ vars.MAIN_VITE_API_URL }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
MAIN_VITE_SENTRY_DSN: ${{ vars.MAIN_VITE_SENTRY_DSN }}
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: yarn build:linux
env:
MAIN_VITE_ONLINEFIX_USERNAME: ${{ secrets.ONLINEFIX_USERNAME }}
MAIN_VITE_ONLINEFIX_PASSWORD: ${{ secrets.ONLINEFIX_PASSWORD }}
MAIN_VITE_API_URL: ${{ vars.MAIN_VITE_API_URL }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
MAIN_VITE_SENTRY_DSN: ${{ vars.MAIN_VITE_SENTRY_DSN }}
Expand All @@ -50,8 +48,6 @@ jobs:
if: matrix.os == 'windows-latest'
run: yarn build:win
env:
MAIN_VITE_ONLINEFIX_USERNAME: ${{ secrets.ONLINEFIX_USERNAME }}
MAIN_VITE_ONLINEFIX_PASSWORD: ${{ secrets.ONLINEFIX_PASSWORD }}
MAIN_VITE_API_URL: ${{ vars.MAIN_VITE_API_URL }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
MAIN_VITE_SENTRY_DSN: ${{ vars.MAIN_VITE_SENTRY_DSN }}
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pnpm-lock.yaml
LICENSE.md
tsconfig.json
tsconfig.*.json
src/main/migrations
36 changes: 14 additions & 22 deletions src/main/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,22 @@ import {
UserPreferences,
UserAuth,
} from "@main/entity";
import type { BetterSqlite3ConnectionOptions } from "typeorm/driver/better-sqlite3/BetterSqlite3ConnectionOptions";

import { databasePath } from "./constants";
import migrations from "./migrations";
import * as migrations from "./migrations";

export const createDataSource = (
options: Partial<BetterSqlite3ConnectionOptions>
) =>
new DataSource({
type: "better-sqlite3",
entities: [
Game,
Repack,
UserPreferences,
GameShopCache,
DownloadSource,
DownloadQueue,
UserAuth,
],
synchronize: true,
database: databasePath,
...options,
});

export const dataSource = createDataSource({
export const dataSource = new DataSource({
type: "better-sqlite3",
entities: [
Game,
Repack,
UserPreferences,
GameShopCache,
DownloadSource,
DownloadQueue,
UserAuth,
],
synchronize: true,
database: databasePath,
migrations,
});
2 changes: 1 addition & 1 deletion src/main/events/library/remove-game-from-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const removeRemoveGameFromLibrary = async (gameId: number) => {
const game = await gameRepository.findOne({ where: { id: gameId } });

if (game?.remoteId) {
HydraApi.delete(`/games/${game.remoteId}`).catch(() => {});
HydraApi.delete(`/profile/games/${game.remoteId}`).catch(() => {});
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/main/events/user/block-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const blockUser = async (
_event: Electron.IpcMainInvokeEvent,
userId: string
) => {
await HydraApi.post(`/user/${userId}/block`);
await HydraApi.post(`/users/${userId}/block`);
};

registerEvent("blockUser", blockUser);
2 changes: 1 addition & 1 deletion src/main/events/user/get-user-friends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getUserFriends = async (
return HydraApi.get(`/profile/friends`, { take, skip });
}

return HydraApi.get(`/user/${userId}/friends`, { take, skip });
return HydraApi.get(`/users/${userId}/friends`, { take, skip });
};

const getUserFriendsEvent = async (
Expand Down
61 changes: 35 additions & 26 deletions src/main/events/user/get-user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { registerEvent } from "../register-event";
import { HydraApi } from "@main/services";
import { steamGamesWorker } from "@main/workers";
import { UserProfile } from "@types";
import { GameRunning, UserGame, UserProfile } from "@types";
import { convertSteamGameToCatalogueEntry } from "../helpers/search-games";
import { getSteamAppAsset } from "@main/helpers";
import { getUserFriends } from "./get-user-friends";
Expand All @@ -12,56 +12,65 @@ const getUser = async (
): Promise<UserProfile | null> => {
try {
const [profile, friends] = await Promise.all([
HydraApi.get(`/user/${userId}`),
HydraApi.get(`/users/${userId}`),
getUserFriends(userId, 12, 0).catch(() => {
return { totalFriends: 0, friends: [] };
}),
]);

const recentGames = await Promise.all(
profile.recentGames.map(async (game) => {
const steamGame = await steamGamesWorker.run(Number(game.objectId), {
name: "getById",
});
const iconUrl = steamGame?.clientIcon
? getSteamAppAsset("icon", game.objectId, steamGame.clientIcon)
: null;

return {
...game,
...convertSteamGameToCatalogueEntry(steamGame),
iconUrl,
};
return getSteamUserGame(game);
})
);

const libraryGames = await Promise.all(
profile.libraryGames.map(async (game) => {
const steamGame = await steamGamesWorker.run(Number(game.objectId), {
name: "getById",
});
const iconUrl = steamGame?.clientIcon
? getSteamAppAsset("icon", game.objectId, steamGame.clientIcon)
: null;

return {
...game,
...convertSteamGameToCatalogueEntry(steamGame),
iconUrl,
};
return getSteamUserGame(game);
})
);

const currentGame = await getGameRunning(profile.currentGame);

return {
...profile,
libraryGames,
recentGames,
friends: friends.friends,
totalFriends: friends.totalFriends,
currentGame,
};
} catch (err) {
return null;
}
};

const getGameRunning = async (currentGame): Promise<GameRunning | null> => {
if (!currentGame) {
return null;
}

const gameRunning = await getSteamUserGame(currentGame);

return {
...gameRunning,
sessionDurationInMillis: currentGame.sessionDurationInSeconds * 1000,
};
};

const getSteamUserGame = async (game): Promise<UserGame> => {
const steamGame = await steamGamesWorker.run(Number(game.objectId), {
name: "getById",
});
const iconUrl = steamGame?.clientIcon
? getSteamAppAsset("icon", game.objectId, steamGame.clientIcon)
: null;

return {
...game,
...convertSteamGameToCatalogueEntry(steamGame),
iconUrl,
};
};

registerEvent("getUser", getUser);
2 changes: 1 addition & 1 deletion src/main/events/user/unblock-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const unblockUser = async (
_event: Electron.IpcMainInvokeEvent,
userId: string
) => {
await HydraApi.post(`/user/${userId}/unblock`);
await HydraApi.post(`/users/${userId}/unblock`);
};

registerEvent("unblockUser", unblockUser);
11 changes: 0 additions & 11 deletions src/main/migrations/1715900413313-fix_repack_uploadDate.ts

This file was deleted.

This file was deleted.

Loading

0 comments on commit cc9d254

Please sign in to comment.