Skip to content

Commit

Permalink
Merge pull request #1311 from hydralauncher/feat/achievements-points
Browse files Browse the repository at this point in the history
feat: achievements points
  • Loading branch information
zamitto authored Dec 23, 2024
2 parents c0f35c5 + 017954b commit dfb50e9
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 138 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hydralauncher",
"version": "3.0.8",
"version": "3.1.0",
"description": "Hydra",
"main": "./out/main/index.js",
"author": "Los Broxas",
Expand Down
2 changes: 1 addition & 1 deletion python_rpc/http_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_download_status(self):
download = self.aria2.get_download(self.download.gid)

response = {
'folderName': str(download.dir) + "/" + download.name,
'folderName': download.name,
'fileSize': download.total_length,
'progress': download.completed_length / download.total_length if download.total_length else 0,
'downloadSpeed': download.download_speed,
Expand Down
2 changes: 0 additions & 2 deletions python_rpc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ def action():
action = data.get('action')
game_id = data.get('game_id')

print(data)

if action == 'start':
url = data.get('url')

Expand Down
Binary file modified resources/tray-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions src/main/events/cloud-save/get-game-artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HydraApi } from "@main/services";
import { registerEvent } from "../register-event";
import type { GameArtifact, GameShop } from "@types";
import { SubscriptionRequiredError } from "@shared";

const getGameArtifacts = async (
_event: Electron.IpcMainInvokeEvent,
Expand All @@ -13,8 +14,16 @@ const getGameArtifacts = async (
});

return HydraApi.get<GameArtifact[]>(
`/profile/games/artifacts?${params.toString()}`
);
`/profile/games/artifacts?${params.toString()}`,
{},
{ needsSubscription: true }
).catch((err) => {
if (err instanceof SubscriptionRequiredError) {
return [];
}

throw err;
});
};

registerEvent("getGameArtifacts", getGameArtifacts);
7 changes: 1 addition & 6 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { RealDebridClient } from "./services/download/real-debrid";
import { HydraApi } from "./services/hydra-api";
import { uploadGamesBatch } from "./services/library-sync";
import { Aria2 } from "./services/aria2";
import { PythonRPC } from "./services/python-rpc";

const loadState = async (userPreferences: UserPreferences | null) => {
import("./events");
Expand Down Expand Up @@ -43,11 +42,7 @@ const loadState = async (userPreferences: UserPreferences | null) => {
},
});

if (nextQueueItem?.game.status === "active") {
DownloadManager.startRPC(nextQueueItem.game, seedList);
} else {
PythonRPC.spawn();
}
await DownloadManager.startRPC(nextQueueItem?.game, seedList);

startMainLoop();
};
Expand Down
78 changes: 39 additions & 39 deletions src/main/services/download/download-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,19 @@ import { logger } from "../logger";
export class DownloadManager {
private static downloadingGameId: number | null = null;

public static startRPC(game: Game, initialSeeding?: Game[]) {
if (game && game.status === "active") {
PythonRPC.spawn(
{
game_id: game.id,
url: game.uri!,
save_path: game.downloadPath!,
},
initialSeeding?.map((game) => ({
game_id: game.id,
url: game.uri!,
save_path: game.downloadPath!,
}))
);
public static async startRPC(game?: Game, initialSeeding?: Game[]) {
PythonRPC.spawn(
game?.status === "active"
? await this.getDownloadPayload(game).catch(() => undefined)
: undefined,
initialSeeding?.map((game) => ({
game_id: game.id,
url: game.uri!,
save_path: game.downloadPath!,
}))
);

this.downloadingGameId = game.id;
}
this.downloadingGameId = game?.id ?? null;
}

private static async getDownloadStatus() {
Expand Down Expand Up @@ -226,7 +222,9 @@ export class DownloadManager {

WindowManager.mainWindow?.setProgressBar(-1);

this.downloadingGameId = null;
if (gameId === this.downloadingGameId) {
this.downloadingGameId = null;
}
}

static async resumeSeeding(game: Game) {
Expand All @@ -245,64 +243,66 @@ export class DownloadManager {
});
}

static async startDownload(game: Game) {
private static async getDownloadPayload(game: Game) {
switch (game.downloader) {
case Downloader.Gofile: {
const id = game!.uri!.split("/").pop();

const token = await GofileApi.authorize();
const downloadLink = await GofileApi.getDownloadLink(id!);

await PythonRPC.rpc.post("/action", {
return {
action: "start",
game_id: game.id,
url: downloadLink,
save_path: game.downloadPath,
save_path: game.downloadPath!,
header: `Cookie: accountToken=${token}`,
});
break;
};
}
case Downloader.PixelDrain: {
const id = game!.uri!.split("/").pop();

await PythonRPC.rpc.post("/action", {
return {
action: "start",
game_id: game.id,
url: `https://pixeldrain.com/api/file/${id}?download`,
save_path: game.downloadPath,
});
break;
save_path: game.downloadPath!,
};
}
case Downloader.Qiwi: {
const downloadUrl = await QiwiApi.getDownloadUrl(game.uri!);

await PythonRPC.rpc.post("/action", {
return {
action: "start",
game_id: game.id,
url: downloadUrl,
save_path: game.downloadPath,
});
break;
save_path: game.downloadPath!,
};
}
case Downloader.Torrent:
await PythonRPC.rpc.post("/action", {
return {
action: "start",
game_id: game.id,
url: game.uri,
save_path: game.downloadPath,
});
break;
url: game.uri!,
save_path: game.downloadPath!,
};
case Downloader.RealDebrid: {
const downloadUrl = await RealDebridClient.getDownloadUrl(game.uri!);

await PythonRPC.rpc.post("/action", {
return {
action: "start",
game_id: game.id,
url: downloadUrl,
save_path: game.downloadPath,
});
url: downloadUrl!,
save_path: game.downloadPath!,
};
}
}
}

static async startDownload(game: Game) {
const payload = await this.getDownloadPayload(game);

await PythonRPC.rpc.post("/action", payload);

this.downloadingGameId = game.id;
}
Expand Down
10 changes: 7 additions & 3 deletions src/renderer/src/pages/achievements/achievement-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ export function AchievementList({ achievements }: AchievementListProps) {

return (
<ul className={styles.list}>
{achievements.map((achievement, index) => (
<li key={index} className={styles.listItem} style={{ display: "flex" }}>
{achievements.map((achievement) => (
<li
key={achievement.name}
className={styles.listItem}
style={{ display: "flex" }}
>
<img
className={styles.listItemImage({
unlocked: achievement.unlocked,
Expand Down Expand Up @@ -72,7 +76,7 @@ export function AchievementList({ achievements }: AchievementListProps) {
<p style={{ fontSize: "1.1em" }}>???</p>
</button>
)}
{achievement.unlockTime && (
{achievement.unlockTime != null && (
<div
title={t("unlocked_at", {
date: formatDateTime(achievement.unlockTime),
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/pages/game-details/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function Sidebar() {
<div>
<p>{achievement.displayName}</p>
<small>
{achievement.unlockTime &&
{achievement.unlockTime != null &&
formatDateTime(achievement.unlockTime)}
</small>
</div>
Expand Down Expand Up @@ -203,7 +203,7 @@ export function Sidebar() {
<div>
<p>{achievement.displayName}</p>
<small>
{achievement.unlockTime &&
{achievement.unlockTime != null &&
formatDateTime(achievement.unlockTime)}
</small>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { settingsContext } from "@renderer/context";
import { downloadSourcesTable } from "@renderer/dexie";
import { downloadSourcesWorker } from "@renderer/workers";
import { useNavigate } from "react-router-dom";
import { clearFilters } from "@renderer/features";
import { setFilters } from "@renderer/features";
import { setFilters, clearFilters } from "@renderer/features";

export function SettingsDownloadSources() {
const [showAddDownloadSourceModal, setShowAddDownloadSourceModal] =
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class UserNotLoggedInError extends Error {
export class SubscriptionRequiredError extends Error {
constructor() {
super("user does not have hydra cloud subscription");
this.name = "UserWithoutCloudSubscriptionError";
this.name = "SubscriptionRequiredError";
}
}

Expand Down

0 comments on commit dfb50e9

Please sign in to comment.