mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 21:44:55 +03:00
Merge branch 'main' into feature/adding-flame-animation
This commit is contained in:
commit
39be8fdf53
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydralauncher",
|
"name": "hydralauncher",
|
||||||
"version": "2.1.1",
|
"version": "2.1.3",
|
||||||
"description": "Hydra",
|
"description": "Hydra",
|
||||||
"main": "./out/main/index.js",
|
"main": "./out/main/index.js",
|
||||||
"author": "Los Broxas",
|
"author": "Los Broxas",
|
||||||
|
@ -59,6 +59,7 @@ import "./profile/update-friend-request";
|
|||||||
import "./profile/update-profile";
|
import "./profile/update-profile";
|
||||||
import "./profile/process-profile-image";
|
import "./profile/process-profile-image";
|
||||||
import "./profile/send-friend-request";
|
import "./profile/send-friend-request";
|
||||||
|
import "./profile/sync-friend-requests";
|
||||||
import { isPortableVersion } from "@main/helpers";
|
import { isPortableVersion } from "@main/helpers";
|
||||||
|
|
||||||
ipcMain.handle("ping", () => "pong");
|
ipcMain.handle("ping", () => "pong");
|
||||||
|
@ -1,32 +1,14 @@
|
|||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import * as Sentry from "@sentry/electron/main";
|
import * as Sentry from "@sentry/electron/main";
|
||||||
import { HydraApi, logger } from "@main/services";
|
import { HydraApi } from "@main/services";
|
||||||
import { UserProfile } from "@types";
|
import { ProfileVisibility, UserDetails } from "@types";
|
||||||
import { userAuthRepository } from "@main/repository";
|
import { userAuthRepository } from "@main/repository";
|
||||||
import { steamUrlBuilder, UserNotLoggedInError } from "@shared";
|
import { UserNotLoggedInError } from "@shared";
|
||||||
import { steamGamesWorker } from "@main/workers";
|
|
||||||
|
|
||||||
const getSteamGame = async (objectId: string) => {
|
|
||||||
try {
|
|
||||||
const steamGame = await steamGamesWorker.run(Number(objectId), {
|
|
||||||
name: "getById",
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
title: steamGame.name,
|
|
||||||
iconUrl: steamUrlBuilder.icon(objectId, steamGame.clientIcon),
|
|
||||||
};
|
|
||||||
} catch (err) {
|
|
||||||
logger.error("Failed to get Steam game", err);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getMe = async (
|
const getMe = async (
|
||||||
_event: Electron.IpcMainInvokeEvent
|
_event: Electron.IpcMainInvokeEvent
|
||||||
): Promise<UserProfile | null> => {
|
): Promise<UserDetails | null> => {
|
||||||
return HydraApi.get(`/profile/me`)
|
return HydraApi.get<UserDetails>(`/profile/me`)
|
||||||
.then(async (me) => {
|
.then(async (me) => {
|
||||||
userAuthRepository.upsert(
|
userAuthRepository.upsert(
|
||||||
{
|
{
|
||||||
@ -38,17 +20,6 @@ const getMe = async (
|
|||||||
["id"]
|
["id"]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (me.currentGame) {
|
|
||||||
const steamGame = await getSteamGame(me.currentGame.objectId);
|
|
||||||
|
|
||||||
if (steamGame) {
|
|
||||||
me.currentGame = {
|
|
||||||
...me.currentGame,
|
|
||||||
...steamGame,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Sentry.setUser({ id: me.id, username: me.username });
|
Sentry.setUser({ id: me.id, username: me.username });
|
||||||
|
|
||||||
return me;
|
return me;
|
||||||
@ -61,7 +32,13 @@ const getMe = async (
|
|||||||
const loggedUser = await userAuthRepository.findOne({ where: { id: 1 } });
|
const loggedUser = await userAuthRepository.findOne({ where: { id: 1 } });
|
||||||
|
|
||||||
if (loggedUser) {
|
if (loggedUser) {
|
||||||
return { ...loggedUser, id: loggedUser.userId };
|
return {
|
||||||
|
...loggedUser,
|
||||||
|
id: loggedUser.userId,
|
||||||
|
username: "",
|
||||||
|
bio: "",
|
||||||
|
profileVisibility: "PUBLIC" as ProfileVisibility,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
9
src/main/events/profile/sync-friend-requests.ts
Normal file
9
src/main/events/profile/sync-friend-requests.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { registerEvent } from "../register-event";
|
||||||
|
import { HydraApi } from "@main/services";
|
||||||
|
import { FriendRequestSync } from "@types";
|
||||||
|
|
||||||
|
const syncFriendRequests = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||||
|
return HydraApi.get<FriendRequestSync>(`/profile/friend-requests/sync`);
|
||||||
|
};
|
||||||
|
|
||||||
|
registerEvent("syncFriendRequests", syncFriendRequests);
|
@ -2,7 +2,7 @@ import { registerEvent } from "../register-event";
|
|||||||
|
|
||||||
import type { StartGameDownloadPayload } from "@types";
|
import type { StartGameDownloadPayload } from "@types";
|
||||||
import { getFileBase64 } from "@main/helpers";
|
import { getFileBase64 } from "@main/helpers";
|
||||||
import { DownloadManager } from "@main/services";
|
import { DownloadManager, HydraApi, logger } from "@main/services";
|
||||||
|
|
||||||
import { Not } from "typeorm";
|
import { Not } from "typeorm";
|
||||||
import { steamGamesWorker } from "@main/workers";
|
import { steamGamesWorker } from "@main/workers";
|
||||||
@ -101,6 +101,17 @@ const startGameDownload = async (
|
|||||||
|
|
||||||
createGame(updatedGame!).catch(() => {});
|
createGame(updatedGame!).catch(() => {});
|
||||||
|
|
||||||
|
HydraApi.post(
|
||||||
|
"/games/download",
|
||||||
|
{
|
||||||
|
objectId: updatedGame!.objectID,
|
||||||
|
shop: updatedGame!.shop,
|
||||||
|
},
|
||||||
|
{ needsAuth: false }
|
||||||
|
).catch((err) => {
|
||||||
|
logger.error("Failed to create game download", err);
|
||||||
|
});
|
||||||
|
|
||||||
await DownloadManager.cancelDownload(updatedGame!.id);
|
await DownloadManager.cancelDownload(updatedGame!.id);
|
||||||
await DownloadManager.startDownload(updatedGame!);
|
await DownloadManager.startDownload(updatedGame!);
|
||||||
|
|
||||||
|
@ -3,12 +3,19 @@ import { databasePath } from "./constants";
|
|||||||
import { Hydra2_0_3 } from "./migrations/20240830143811_Hydra_2_0_3";
|
import { Hydra2_0_3 } from "./migrations/20240830143811_Hydra_2_0_3";
|
||||||
import { RepackUris } from "./migrations/20240830143906_RepackUris";
|
import { RepackUris } from "./migrations/20240830143906_RepackUris";
|
||||||
import { UpdateUserLanguage } from "./migrations/20240913213944_update_user_language";
|
import { UpdateUserLanguage } from "./migrations/20240913213944_update_user_language";
|
||||||
|
import { EnsureRepackUris } from "./migrations/20240915035339_ensure_repack_uris";
|
||||||
|
import { app } from "electron";
|
||||||
|
|
||||||
export type HydraMigration = Knex.Migration & { name: string };
|
export type HydraMigration = Knex.Migration & { name: string };
|
||||||
|
|
||||||
class MigrationSource implements Knex.MigrationSource<HydraMigration> {
|
class MigrationSource implements Knex.MigrationSource<HydraMigration> {
|
||||||
getMigrations(): Promise<HydraMigration[]> {
|
getMigrations(): Promise<HydraMigration[]> {
|
||||||
return Promise.resolve([Hydra2_0_3, RepackUris, UpdateUserLanguage]);
|
return Promise.resolve([
|
||||||
|
Hydra2_0_3,
|
||||||
|
RepackUris,
|
||||||
|
UpdateUserLanguage,
|
||||||
|
EnsureRepackUris,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
getMigrationName(migration: HydraMigration): string {
|
getMigrationName(migration: HydraMigration): string {
|
||||||
return migration.name;
|
return migration.name;
|
||||||
@ -19,6 +26,7 @@ class MigrationSource implements Knex.MigrationSource<HydraMigration> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const knexClient = knex({
|
export const knexClient = knex({
|
||||||
|
debug: !app.isPackaged,
|
||||||
client: "better-sqlite3",
|
client: "better-sqlite3",
|
||||||
connection: {
|
connection: {
|
||||||
filename: databasePath,
|
filename: databasePath,
|
||||||
|
@ -4,55 +4,15 @@ import type { Knex } from "knex";
|
|||||||
export const RepackUris: HydraMigration = {
|
export const RepackUris: HydraMigration = {
|
||||||
name: "RepackUris",
|
name: "RepackUris",
|
||||||
up: async (knex: Knex) => {
|
up: async (knex: Knex) => {
|
||||||
await knex.schema.createTable("temporary_repack", (table) => {
|
await knex.schema.alterTable("repack", (table) => {
|
||||||
const timestamp = new Date().getTime();
|
|
||||||
table.increments("id").primary();
|
|
||||||
table
|
|
||||||
.text("title")
|
|
||||||
.notNullable()
|
|
||||||
.unique({ indexName: "repack_title_unique_" + timestamp });
|
|
||||||
table
|
|
||||||
.text("magnet")
|
|
||||||
.notNullable()
|
|
||||||
.unique({ indexName: "repack_magnet_unique_" + timestamp });
|
|
||||||
table.text("repacker").notNullable();
|
|
||||||
table.text("fileSize").notNullable();
|
|
||||||
table.datetime("uploadDate").notNullable();
|
|
||||||
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table
|
|
||||||
.integer("downloadSourceId")
|
|
||||||
.references("download_source.id")
|
|
||||||
.onDelete("CASCADE");
|
|
||||||
table.text("uris").notNullable().defaultTo("[]");
|
table.text("uris").notNullable().defaultTo("[]");
|
||||||
});
|
});
|
||||||
await knex.raw(
|
|
||||||
`INSERT INTO "temporary_repack"("id", "title", "magnet", "repacker", "fileSize", "uploadDate", "createdAt", "updatedAt", "downloadSourceId") SELECT "id", "title", "magnet", "repacker", "fileSize", "uploadDate", "createdAt", "updatedAt", "downloadSourceId" FROM "repack"`
|
|
||||||
);
|
|
||||||
await knex.schema.dropTable("repack");
|
|
||||||
await knex.schema.renameTable("temporary_repack", "repack");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
down: async (knex: Knex) => {
|
down: async (knex: Knex) => {
|
||||||
await knex.schema.renameTable("repack", "temporary_repack");
|
await knex.schema.alterTable("repack", (table) => {
|
||||||
await knex.schema.createTable("repack", (table) => {
|
|
||||||
table.increments("id").primary();
|
|
||||||
table.text("title").notNullable().unique();
|
|
||||||
table.text("magnet").notNullable().unique();
|
|
||||||
table.integer("page");
|
table.integer("page");
|
||||||
table.text("repacker").notNullable();
|
table.dropColumn("uris");
|
||||||
table.text("fileSize").notNullable();
|
|
||||||
table.datetime("uploadDate").notNullable();
|
|
||||||
table.datetime("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table.datetime("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
||||||
table
|
|
||||||
.integer("downloadSourceId")
|
|
||||||
.references("download_source.id")
|
|
||||||
.onDelete("CASCADE");
|
|
||||||
});
|
});
|
||||||
await knex.raw(
|
|
||||||
`INSERT INTO "repack"("id", "title", "magnet", "repacker", "fileSize", "uploadDate", "createdAt", "updatedAt", "downloadSourceId") SELECT "id", "title", "magnet", "repacker", "fileSize", "uploadDate", "createdAt", "updatedAt", "downloadSourceId" FROM "temporary_repack"`
|
|
||||||
);
|
|
||||||
await knex.schema.dropTable("temporary_repack");
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
17
src/main/migrations/20240915035339_ensure_repack_uris.ts
Normal file
17
src/main/migrations/20240915035339_ensure_repack_uris.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import type { HydraMigration } from "@main/knex-client";
|
||||||
|
import type { Knex } from "knex";
|
||||||
|
|
||||||
|
export const EnsureRepackUris: HydraMigration = {
|
||||||
|
name: "EnsureRepackUris",
|
||||||
|
up: async (knex: Knex) => {
|
||||||
|
await knex.schema.hasColumn("repack", "uris").then(async (exists) => {
|
||||||
|
if (!exists) {
|
||||||
|
await knex.schema.table("repack", (table) => {
|
||||||
|
table.text("uris").notNullable().defaultTo("[]");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
down: async (_knex: Knex) => {},
|
||||||
|
};
|
@ -6,6 +6,7 @@ import { uploadGamesBatch } from "./library-sync";
|
|||||||
import { clearGamesRemoteIds } from "./library-sync/clear-games-remote-id";
|
import { clearGamesRemoteIds } from "./library-sync/clear-games-remote-id";
|
||||||
import { logger } from "./logger";
|
import { logger } from "./logger";
|
||||||
import { UserNotLoggedInError } from "@shared";
|
import { UserNotLoggedInError } from "@shared";
|
||||||
|
import { omit } from "lodash-es";
|
||||||
|
|
||||||
interface HydraApiOptions {
|
interface HydraApiOptions {
|
||||||
needsAuth: boolean;
|
needsAuth: boolean;
|
||||||
@ -96,11 +97,14 @@ export class HydraApi {
|
|||||||
this.instance.interceptors.response.use(
|
this.instance.interceptors.response.use(
|
||||||
(response) => {
|
(response) => {
|
||||||
logger.log(" ---- RESPONSE -----");
|
logger.log(" ---- RESPONSE -----");
|
||||||
|
const data = Array.isArray(response.data)
|
||||||
|
? response.data
|
||||||
|
: omit(response.data, ["username", "accessToken", "refreshToken"]);
|
||||||
logger.log(
|
logger.log(
|
||||||
response.status,
|
response.status,
|
||||||
response.config.method,
|
response.config.method,
|
||||||
response.config.url,
|
response.config.url,
|
||||||
response.data
|
data
|
||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
@ -166,7 +170,10 @@ export class HydraApi {
|
|||||||
this.userAuth.authToken = accessToken;
|
this.userAuth.authToken = accessToken;
|
||||||
this.userAuth.expirationTimestamp = tokenExpirationTimestamp;
|
this.userAuth.expirationTimestamp = tokenExpirationTimestamp;
|
||||||
|
|
||||||
logger.log("Token refreshed", this.userAuth);
|
logger.log(
|
||||||
|
"Token refreshed. New expiration:",
|
||||||
|
this.userAuth.expirationTimestamp
|
||||||
|
);
|
||||||
|
|
||||||
userAuthRepository.upsert(
|
userAuthRepository.upsert(
|
||||||
{
|
{
|
||||||
|
@ -1,20 +1,8 @@
|
|||||||
import { Game } from "@main/entity";
|
import { Game } from "@main/entity";
|
||||||
import { HydraApi } from "../hydra-api";
|
import { HydraApi } from "../hydra-api";
|
||||||
import { gameRepository } from "@main/repository";
|
import { gameRepository } from "@main/repository";
|
||||||
import { logger } from "../logger";
|
|
||||||
|
|
||||||
export const createGame = async (game: Game) => {
|
export const createGame = async (game: Game) => {
|
||||||
HydraApi.post(
|
|
||||||
"/games/download",
|
|
||||||
{
|
|
||||||
objectId: game.objectID,
|
|
||||||
shop: game.shop,
|
|
||||||
},
|
|
||||||
{ needsAuth: false }
|
|
||||||
).catch((err) => {
|
|
||||||
logger.error("Failed to create game download", err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return HydraApi.post(`/profile/games`, {
|
return HydraApi.post(`/profile/games`, {
|
||||||
objectId: game.objectID,
|
objectId: game.objectID,
|
||||||
playTimeInMilliseconds: Math.trunc(game.playTimeInMilliseconds),
|
playTimeInMilliseconds: Math.trunc(game.playTimeInMilliseconds),
|
||||||
|
@ -119,7 +119,7 @@ const onCloseGame = (game: Game) => {
|
|||||||
if (game.remoteId) {
|
if (game.remoteId) {
|
||||||
updateGamePlaytime(
|
updateGamePlaytime(
|
||||||
game,
|
game,
|
||||||
performance.now() - gamePlaytime.firstTick,
|
performance.now() - gamePlaytime.lastSyncTick,
|
||||||
game.lastTimePlayed!
|
game.lastTimePlayed!
|
||||||
).catch(() => {});
|
).catch(() => {});
|
||||||
} else {
|
} else {
|
||||||
|
@ -150,6 +150,7 @@ contextBridge.exposeInMainWorld("electron", {
|
|||||||
processProfileImage: (imagePath: string) =>
|
processProfileImage: (imagePath: string) =>
|
||||||
ipcRenderer.invoke("processProfileImage", imagePath),
|
ipcRenderer.invoke("processProfileImage", imagePath),
|
||||||
getFriendRequests: () => ipcRenderer.invoke("getFriendRequests"),
|
getFriendRequests: () => ipcRenderer.invoke("getFriendRequests"),
|
||||||
|
syncFriendRequests: () => ipcRenderer.invoke("syncFriendRequests"),
|
||||||
updateFriendRequest: (userId: string, action: FriendRequestAction) =>
|
updateFriendRequest: (userId: string, action: FriendRequestAction) =>
|
||||||
ipcRenderer.invoke("updateFriendRequest", userId, action),
|
ipcRenderer.invoke("updateFriendRequest", userId, action),
|
||||||
sendFriendRequest: (userId: string) =>
|
sendFriendRequest: (userId: string) =>
|
||||||
|
@ -43,7 +43,7 @@ export function App() {
|
|||||||
isFriendsModalVisible,
|
isFriendsModalVisible,
|
||||||
friendRequetsModalTab,
|
friendRequetsModalTab,
|
||||||
friendModalUserId,
|
friendModalUserId,
|
||||||
fetchFriendRequests,
|
syncFriendRequests,
|
||||||
hideFriendsModal,
|
hideFriendsModal,
|
||||||
} = useUserDetails();
|
} = useUserDetails();
|
||||||
|
|
||||||
@ -105,22 +105,22 @@ export function App() {
|
|||||||
fetchUserDetails().then((response) => {
|
fetchUserDetails().then((response) => {
|
||||||
if (response) {
|
if (response) {
|
||||||
updateUserDetails(response);
|
updateUserDetails(response);
|
||||||
fetchFriendRequests();
|
syncFriendRequests();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [fetchUserDetails, fetchFriendRequests, updateUserDetails, dispatch]);
|
}, [fetchUserDetails, syncFriendRequests, updateUserDetails, dispatch]);
|
||||||
|
|
||||||
const onSignIn = useCallback(() => {
|
const onSignIn = useCallback(() => {
|
||||||
fetchUserDetails().then((response) => {
|
fetchUserDetails().then((response) => {
|
||||||
if (response) {
|
if (response) {
|
||||||
updateUserDetails(response);
|
updateUserDetails(response);
|
||||||
fetchFriendRequests();
|
syncFriendRequests();
|
||||||
showSuccessToast(t("successfully_signed_in"));
|
showSuccessToast(t("successfully_signed_in"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [
|
}, [
|
||||||
fetchUserDetails,
|
fetchUserDetails,
|
||||||
fetchFriendRequests,
|
syncFriendRequests,
|
||||||
t,
|
t,
|
||||||
showSuccessToast,
|
showSuccessToast,
|
||||||
updateUserDetails,
|
updateUserDetails,
|
||||||
|
@ -15,15 +15,15 @@ export function SidebarProfile() {
|
|||||||
|
|
||||||
const { t } = useTranslation("sidebar");
|
const { t } = useTranslation("sidebar");
|
||||||
|
|
||||||
const { userDetails, friendRequests, showFriendsModal, fetchFriendRequests } =
|
const {
|
||||||
useUserDetails();
|
userDetails,
|
||||||
|
friendRequestCount,
|
||||||
|
showFriendsModal,
|
||||||
|
syncFriendRequests,
|
||||||
|
} = useUserDetails();
|
||||||
|
|
||||||
const { gameRunning } = useAppSelector((state) => state.gameRunning);
|
const { gameRunning } = useAppSelector((state) => state.gameRunning);
|
||||||
|
|
||||||
const receivedRequests = useMemo(() => {
|
|
||||||
return friendRequests.filter((request) => request.type === "RECEIVED");
|
|
||||||
}, [friendRequests]);
|
|
||||||
|
|
||||||
const handleProfileClick = () => {
|
const handleProfileClick = () => {
|
||||||
if (userDetails === null) {
|
if (userDetails === null) {
|
||||||
window.electron.openAuthWindow();
|
window.electron.openAuthWindow();
|
||||||
@ -35,7 +35,7 @@ export function SidebarProfile() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
pollingInterval.current = setInterval(() => {
|
pollingInterval.current = setInterval(() => {
|
||||||
fetchFriendRequests();
|
syncFriendRequests();
|
||||||
}, LONG_POLLING_INTERVAL);
|
}, LONG_POLLING_INTERVAL);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
@ -43,7 +43,7 @@ export function SidebarProfile() {
|
|||||||
clearInterval(pollingInterval.current);
|
clearInterval(pollingInterval.current);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [fetchFriendRequests]);
|
}, [syncFriendRequests]);
|
||||||
|
|
||||||
const friendsButton = useMemo(() => {
|
const friendsButton = useMemo(() => {
|
||||||
if (!userDetails) return null;
|
if (!userDetails) return null;
|
||||||
@ -57,16 +57,16 @@ export function SidebarProfile() {
|
|||||||
}
|
}
|
||||||
title={t("friends")}
|
title={t("friends")}
|
||||||
>
|
>
|
||||||
{receivedRequests.length > 0 && (
|
{friendRequestCount > 0 && (
|
||||||
<small className={styles.friendsButtonBadge}>
|
<small className={styles.friendsButtonBadge}>
|
||||||
{receivedRequests.length > 99 ? "99+" : receivedRequests.length}
|
{friendRequestCount > 99 ? "99+" : friendRequestCount}
|
||||||
</small>
|
</small>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<PeopleIcon size={16} />
|
<PeopleIcon size={16} />
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
}, [userDetails, t, receivedRequests, showFriendsModal]);
|
}, [userDetails, t, friendRequestCount, showFriendsModal]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.profileContainer}>
|
<div className={styles.profileContainer}>
|
||||||
@ -100,6 +100,7 @@ export function SidebarProfile() {
|
|||||||
textOverflow: "ellipsis",
|
textOverflow: "ellipsis",
|
||||||
whiteSpace: "nowrap",
|
whiteSpace: "nowrap",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
|
textAlign: "left",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<small>{gameRunning.title}</small>
|
<small>{gameRunning.title}</small>
|
||||||
|
@ -26,7 +26,7 @@ export const sidebar = recipe({
|
|||||||
paddingTop: `${SPACING_UNIT * 6}px`,
|
paddingTop: `${SPACING_UNIT * 6}px`,
|
||||||
},
|
},
|
||||||
false: {
|
false: {
|
||||||
paddingTop: `${SPACING_UNIT * 2}px`,
|
paddingTop: `${SPACING_UNIT}px`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
5
src/renderer/src/declaration.d.ts
vendored
5
src/renderer/src/declaration.d.ts
vendored
@ -23,6 +23,8 @@ import type {
|
|||||||
GameStats,
|
GameStats,
|
||||||
TrendingGame,
|
TrendingGame,
|
||||||
UserStats,
|
UserStats,
|
||||||
|
UserDetails,
|
||||||
|
FriendRequestSync,
|
||||||
} from "@types";
|
} from "@types";
|
||||||
import type { DiskSpace } from "check-disk-space";
|
import type { DiskSpace } from "check-disk-space";
|
||||||
|
|
||||||
@ -153,7 +155,7 @@ declare global {
|
|||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
|
|
||||||
/* Profile */
|
/* Profile */
|
||||||
getMe: () => Promise<UserProfile | null>;
|
getMe: () => Promise<UserDetails | null>;
|
||||||
undoFriendship: (userId: string) => Promise<void>;
|
undoFriendship: (userId: string) => Promise<void>;
|
||||||
updateProfile: (
|
updateProfile: (
|
||||||
updateProfile: UpdateProfileRequest
|
updateProfile: UpdateProfileRequest
|
||||||
@ -163,6 +165,7 @@ declare global {
|
|||||||
path: string
|
path: string
|
||||||
) => Promise<{ imagePath: string; mimeType: string }>;
|
) => Promise<{ imagePath: string; mimeType: string }>;
|
||||||
getFriendRequests: () => Promise<FriendRequest[]>;
|
getFriendRequests: () => Promise<FriendRequest[]>;
|
||||||
|
syncFriendRequests: () => Promise<FriendRequestSync>;
|
||||||
updateFriendRequest: (
|
updateFriendRequest: (
|
||||||
userId: string,
|
userId: string,
|
||||||
action: FriendRequestAction
|
action: FriendRequestAction
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
|
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
|
||||||
import { UserFriendModalTab } from "@renderer/pages/shared-modals/user-friend-modal";
|
import { UserFriendModalTab } from "@renderer/pages/shared-modals/user-friend-modal";
|
||||||
import type { FriendRequest, UserProfile } from "@types";
|
import type { FriendRequest, UserDetails } from "@types";
|
||||||
|
|
||||||
export interface UserDetailsState {
|
export interface UserDetailsState {
|
||||||
userDetails: UserProfile | null;
|
userDetails: UserDetails | null;
|
||||||
profileBackground: null | string;
|
profileBackground: null | string;
|
||||||
friendRequests: FriendRequest[];
|
friendRequests: FriendRequest[];
|
||||||
|
friendRequestCount: number;
|
||||||
isFriendsModalVisible: boolean;
|
isFriendsModalVisible: boolean;
|
||||||
friendRequetsModalTab: UserFriendModalTab | null;
|
friendRequetsModalTab: UserFriendModalTab | null;
|
||||||
friendModalUserId: string;
|
friendModalUserId: string;
|
||||||
@ -15,6 +16,7 @@ const initialState: UserDetailsState = {
|
|||||||
userDetails: null,
|
userDetails: null,
|
||||||
profileBackground: null,
|
profileBackground: null,
|
||||||
friendRequests: [],
|
friendRequests: [],
|
||||||
|
friendRequestCount: 0,
|
||||||
isFriendsModalVisible: false,
|
isFriendsModalVisible: false,
|
||||||
friendRequetsModalTab: null,
|
friendRequetsModalTab: null,
|
||||||
friendModalUserId: "",
|
friendModalUserId: "",
|
||||||
@ -24,7 +26,7 @@ export const userDetailsSlice = createSlice({
|
|||||||
name: "user-details",
|
name: "user-details",
|
||||||
initialState,
|
initialState,
|
||||||
reducers: {
|
reducers: {
|
||||||
setUserDetails: (state, action: PayloadAction<UserProfile | null>) => {
|
setUserDetails: (state, action: PayloadAction<UserDetails | null>) => {
|
||||||
state.userDetails = action.payload;
|
state.userDetails = action.payload;
|
||||||
},
|
},
|
||||||
setProfileBackground: (state, action: PayloadAction<string | null>) => {
|
setProfileBackground: (state, action: PayloadAction<string | null>) => {
|
||||||
@ -33,6 +35,9 @@ export const userDetailsSlice = createSlice({
|
|||||||
setFriendRequests: (state, action: PayloadAction<FriendRequest[]>) => {
|
setFriendRequests: (state, action: PayloadAction<FriendRequest[]>) => {
|
||||||
state.friendRequests = action.payload;
|
state.friendRequests = action.payload;
|
||||||
},
|
},
|
||||||
|
setFriendRequestCount: (state, action: PayloadAction<number>) => {
|
||||||
|
state.friendRequestCount = action.payload;
|
||||||
|
},
|
||||||
setFriendsModalVisible: (
|
setFriendsModalVisible: (
|
||||||
state,
|
state,
|
||||||
action: PayloadAction<{ initialTab: UserFriendModalTab; userId: string }>
|
action: PayloadAction<{ initialTab: UserFriendModalTab; userId: string }>
|
||||||
@ -52,6 +57,7 @@ export const {
|
|||||||
setUserDetails,
|
setUserDetails,
|
||||||
setProfileBackground,
|
setProfileBackground,
|
||||||
setFriendRequests,
|
setFriendRequests,
|
||||||
|
setFriendRequestCount,
|
||||||
setFriendsModalVisible,
|
setFriendsModalVisible,
|
||||||
setFriendsModalHidden,
|
setFriendsModalHidden,
|
||||||
} = userDetailsSlice.actions;
|
} = userDetailsSlice.actions;
|
||||||
|
@ -6,11 +6,12 @@ import {
|
|||||||
setFriendRequests,
|
setFriendRequests,
|
||||||
setFriendsModalVisible,
|
setFriendsModalVisible,
|
||||||
setFriendsModalHidden,
|
setFriendsModalHidden,
|
||||||
|
setFriendRequestCount,
|
||||||
} from "@renderer/features";
|
} from "@renderer/features";
|
||||||
import type {
|
import type {
|
||||||
FriendRequestAction,
|
FriendRequestAction,
|
||||||
UpdateProfileRequest,
|
UpdateProfileRequest,
|
||||||
UserProfile,
|
UserDetails,
|
||||||
} from "@types";
|
} from "@types";
|
||||||
import { UserFriendModalTab } from "@renderer/pages/shared-modals/user-friend-modal";
|
import { UserFriendModalTab } from "@renderer/pages/shared-modals/user-friend-modal";
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ export function useUserDetails() {
|
|||||||
userDetails,
|
userDetails,
|
||||||
profileBackground,
|
profileBackground,
|
||||||
friendRequests,
|
friendRequests,
|
||||||
|
friendRequestCount,
|
||||||
isFriendsModalVisible,
|
isFriendsModalVisible,
|
||||||
friendModalUserId,
|
friendModalUserId,
|
||||||
friendRequetsModalTab,
|
friendRequetsModalTab,
|
||||||
@ -40,7 +42,7 @@ export function useUserDetails() {
|
|||||||
}, [clearUserDetails]);
|
}, [clearUserDetails]);
|
||||||
|
|
||||||
const updateUserDetails = useCallback(
|
const updateUserDetails = useCallback(
|
||||||
async (userDetails: UserProfile) => {
|
async (userDetails: UserDetails) => {
|
||||||
dispatch(setUserDetails(userDetails));
|
dispatch(setUserDetails(userDetails));
|
||||||
|
|
||||||
if (userDetails.profileImageUrl) {
|
if (userDetails.profileImageUrl) {
|
||||||
@ -83,7 +85,10 @@ export function useUserDetails() {
|
|||||||
const patchUser = useCallback(
|
const patchUser = useCallback(
|
||||||
async (values: UpdateProfileRequest) => {
|
async (values: UpdateProfileRequest) => {
|
||||||
const response = await window.electron.updateProfile(values);
|
const response = await window.electron.updateProfile(values);
|
||||||
return updateUserDetails(response);
|
return updateUserDetails({
|
||||||
|
...response,
|
||||||
|
username: userDetails?.username || "",
|
||||||
|
});
|
||||||
},
|
},
|
||||||
[updateUserDetails]
|
[updateUserDetails]
|
||||||
);
|
);
|
||||||
@ -92,11 +97,21 @@ export function useUserDetails() {
|
|||||||
return window.electron
|
return window.electron
|
||||||
.getFriendRequests()
|
.getFriendRequests()
|
||||||
.then((friendRequests) => {
|
.then((friendRequests) => {
|
||||||
|
syncFriendRequests();
|
||||||
dispatch(setFriendRequests(friendRequests));
|
dispatch(setFriendRequests(friendRequests));
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
||||||
|
const syncFriendRequests = useCallback(async () => {
|
||||||
|
return window.electron
|
||||||
|
.syncFriendRequests()
|
||||||
|
.then((sync) => {
|
||||||
|
dispatch(setFriendRequestCount(sync.friendRequestCount));
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
}, [dispatch]);
|
||||||
|
|
||||||
const showFriendsModal = useCallback(
|
const showFriendsModal = useCallback(
|
||||||
(initialTab: UserFriendModalTab, userId: string) => {
|
(initialTab: UserFriendModalTab, userId: string) => {
|
||||||
dispatch(setFriendsModalVisible({ initialTab, userId }));
|
dispatch(setFriendsModalVisible({ initialTab, userId }));
|
||||||
@ -140,6 +155,7 @@ export function useUserDetails() {
|
|||||||
userDetails,
|
userDetails,
|
||||||
profileBackground,
|
profileBackground,
|
||||||
friendRequests,
|
friendRequests,
|
||||||
|
friendRequestCount,
|
||||||
friendRequetsModalTab,
|
friendRequetsModalTab,
|
||||||
isFriendsModalVisible,
|
isFriendsModalVisible,
|
||||||
friendModalUserId,
|
friendModalUserId,
|
||||||
@ -152,6 +168,7 @@ export function useUserDetails() {
|
|||||||
patchUser,
|
patchUser,
|
||||||
sendFriendRequest,
|
sendFriendRequest,
|
||||||
fetchFriendRequests,
|
fetchFriendRequests,
|
||||||
|
syncFriendRequests,
|
||||||
updateFriendRequestState,
|
updateFriendRequestState,
|
||||||
blockUser,
|
blockUser,
|
||||||
unblockUser,
|
unblockUser,
|
||||||
|
@ -160,12 +160,15 @@ export function DownloadSettingsModal({
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{selectedDownloader && selectedDownloader !== Downloader.Torrent && (
|
{selectedDownloader != null &&
|
||||||
<p style={{ marginTop: `${SPACING_UNIT}px` }}>
|
selectedDownloader !== Downloader.Torrent && (
|
||||||
<span style={{ color: vars.color.warning }}>{t("warning")}</span>{" "}
|
<p style={{ marginTop: `${SPACING_UNIT}px` }}>
|
||||||
{t("hydra_needs_to_remain_open")}
|
<span style={{ color: vars.color.warning }}>
|
||||||
</p>
|
{t("warning")}
|
||||||
)}
|
</span>{" "}
|
||||||
|
{t("hydra_needs_to_remain_open")}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useContext, useEffect, useState } from "react";
|
import { useContext, useState } from "react";
|
||||||
import type { HowLongToBeatCategory, SteamAppDetails } from "@types";
|
import type { HowLongToBeatCategory, SteamAppDetails } from "@types";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Button } from "@renderer/components";
|
import { Button } from "@renderer/components";
|
||||||
@ -9,7 +9,7 @@ import { useFormat } from "@renderer/hooks";
|
|||||||
import { DownloadIcon, PeopleIcon } from "@primer/octicons-react";
|
import { DownloadIcon, PeopleIcon } from "@primer/octicons-react";
|
||||||
|
|
||||||
export function Sidebar() {
|
export function Sidebar() {
|
||||||
const [_howLongToBeat, setHowLongToBeat] = useState<{
|
const [_howLongToBeat, _setHowLongToBeat] = useState<{
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
data: HowLongToBeatCategory[] | null;
|
data: HowLongToBeatCategory[] | null;
|
||||||
}>({ isLoading: true, data: null });
|
}>({ isLoading: true, data: null });
|
||||||
@ -17,27 +17,26 @@ export function Sidebar() {
|
|||||||
const [activeRequirement, setActiveRequirement] =
|
const [activeRequirement, setActiveRequirement] =
|
||||||
useState<keyof SteamAppDetails["pc_requirements"]>("minimum");
|
useState<keyof SteamAppDetails["pc_requirements"]>("minimum");
|
||||||
|
|
||||||
const { gameTitle, shopDetails, objectID, stats } =
|
const { gameTitle, shopDetails, stats } = useContext(gameDetailsContext);
|
||||||
useContext(gameDetailsContext);
|
|
||||||
|
|
||||||
const { t } = useTranslation("game_details");
|
const { t } = useTranslation("game_details");
|
||||||
|
|
||||||
const { numberFormatter } = useFormat();
|
const { numberFormatter } = useFormat();
|
||||||
|
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
if (objectID) {
|
// if (objectID) {
|
||||||
setHowLongToBeat({ isLoading: true, data: null });
|
// setHowLongToBeat({ isLoading: true, data: null });
|
||||||
|
|
||||||
window.electron
|
// window.electron
|
||||||
.getHowLongToBeat(objectID, "steam", gameTitle)
|
// .getHowLongToBeat(objectID, "steam", gameTitle)
|
||||||
.then((howLongToBeat) => {
|
// .then((howLongToBeat) => {
|
||||||
setHowLongToBeat({ isLoading: false, data: howLongToBeat });
|
// setHowLongToBeat({ isLoading: false, data: howLongToBeat });
|
||||||
})
|
// })
|
||||||
.catch(() => {
|
// .catch(() => {
|
||||||
setHowLongToBeat({ isLoading: false, data: null });
|
// setHowLongToBeat({ isLoading: false, data: null });
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}, [objectID, gameTitle]);
|
// }, [objectID, gameTitle]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside className={styles.contentSidebar}>
|
<aside className={styles.contentSidebar}>
|
||||||
|
@ -170,6 +170,10 @@ export interface UserBlocks {
|
|||||||
blocks: UserFriend[];
|
blocks: UserFriend[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FriendRequestSync {
|
||||||
|
friendRequestCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface FriendRequest {
|
export interface FriendRequest {
|
||||||
id: string;
|
id: string;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
@ -190,23 +194,34 @@ export interface UserProfileCurrentGame extends Omit<GameRunning, "objectID"> {
|
|||||||
sessionDurationInSeconds: number;
|
sessionDurationInSeconds: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ProfileVisibility = "PUBLIC" | "PRIVATE" | "FRIENDS";
|
||||||
|
|
||||||
|
export interface UserDetails {
|
||||||
|
id: string;
|
||||||
|
username: string;
|
||||||
|
displayName: string;
|
||||||
|
profileImageUrl: string | null;
|
||||||
|
profileVisibility: ProfileVisibility;
|
||||||
|
bio: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface UserProfile {
|
export interface UserProfile {
|
||||||
id: string;
|
id: string;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
profileImageUrl: string | null;
|
profileImageUrl: string | null;
|
||||||
profileVisibility: "PUBLIC" | "PRIVATE" | "FRIENDS";
|
profileVisibility: ProfileVisibility;
|
||||||
totalPlayTimeInSeconds: number;
|
|
||||||
libraryGames: UserGame[];
|
libraryGames: UserGame[];
|
||||||
recentGames: UserGame[];
|
recentGames: UserGame[];
|
||||||
friends: UserFriend[];
|
friends: UserFriend[];
|
||||||
totalFriends: number;
|
totalFriends: number;
|
||||||
relation: UserRelation | null;
|
relation: UserRelation | null;
|
||||||
currentGame: UserProfileCurrentGame | null;
|
currentGame: UserProfileCurrentGame | null;
|
||||||
|
bio: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateProfileRequest {
|
export interface UpdateProfileRequest {
|
||||||
displayName?: string;
|
displayName?: string;
|
||||||
profileVisibility?: "PUBLIC" | "PRIVATE" | "FRIENDS";
|
profileVisibility?: ProfileVisibility;
|
||||||
profileImageUrl?: string | null;
|
profileImageUrl?: string | null;
|
||||||
bio?: string;
|
bio?: string;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user