fix: fixing download cancel

This commit is contained in:
Chubby Granny Chaser 2025-02-16 03:27:11 +00:00
commit 6158108452
No known key found for this signature in database
22 changed files with 122 additions and 81 deletions

View file

@ -159,6 +159,8 @@ def action():
downloader = downloads.get(game_id)
if downloader:
downloader.pause_download()
if downloading_game_id == game_id:
downloading_game_id = -1
elif action == 'cancel':
downloader = downloads.get(game_id)

View file

@ -107,7 +107,10 @@ const copyAria2Macos = async () => {
};
const copyAria2 = () => {
if (fs.existsSync("aria2")) {
const aria2Path =
process.platform === "win32" ? "aria2/aria2c.exe" : "aria2/aria2c";
if (fs.existsSync(aria2Path)) {
console.log("Aria2 already exists, skipping download...");
return;
}

View file

@ -310,9 +310,9 @@
"editor_tab_save": "Save",
"web_store": "Web store",
"clear_themes": "Clear",
"add_theme": "Add",
"add_theme_modal_title": "Create custom theme",
"add_theme_modal_description": "Create a new theme to customize Hydra's appearance",
"create_theme": "Create",
"create_theme_modal_title": "Create custom theme",
"create_theme_modal_description": "Create a new theme to customize Hydra's appearance",
"theme_name": "Name",
"insert_theme_name": "Insert theme name",
"set_theme": "Set theme",

View file

@ -300,9 +300,9 @@
"editor_tab_save": "Salvar",
"web_store": "Loja de temas",
"clear_themes": "Limpar",
"add_theme": "Adicionar",
"add_theme_modal_title": "Criar tema customizado",
"add_theme_modal_description": "Criar novo tema para customizar a aparência do Hydra",
"create_theme": "Criar",
"create_theme_modal_title": "Criar tema customizado",
"create_theme_modal_description": "Criar novo tema para customizar a aparência do Hydra",
"theme_name": "Nome",
"insert_theme_name": "Insira o nome do tema",
"set_theme": "Habilitar tema",

View file

@ -5,7 +5,7 @@ import type { Game, GameShop } from "@types";
import { steamGamesWorker } from "@main/workers";
import { createGame } from "@main/services/library-sync";
import { steamUrlBuilder } from "@shared";
import { updateLocalUnlockedAchivements } from "@main/services/achievements/update-local-unlocked-achivements";
import { updateLocalUnlockedAchievements } from "@main/services/achievements/update-local-unlocked-achivements";
import { downloadsSublevel, gamesSublevel, levelKeys } from "@main/level";
const addGameToLibrary = async (
@ -46,9 +46,9 @@ const addGameToLibrary = async (
await gamesSublevel.put(levelKeys.game(shop, objectId), game);
updateLocalUnlockedAchivements(game);
await createGame(game).catch(() => {});
createGame(game).catch(() => {});
updateLocalUnlockedAchievements(game);
}
};

View file

@ -2,7 +2,7 @@ import { registerEvent } from "../register-event";
import { DownloadManager } from "@main/services";
import { GameShop } from "@types";
import { levelKeys } from "@main/level";
import { downloadsSublevel, levelKeys } from "@main/level";
const cancelGameDownload = async (
_event: Electron.IpcMainInvokeEvent,
@ -12,6 +12,15 @@ const cancelGameDownload = async (
const downloadKey = levelKeys.game(shop, objectId);
await DownloadManager.cancelDownload(downloadKey);
const download = await downloadsSublevel.get(downloadKey);
if (!download) return;
await downloadsSublevel.put(downloadKey, {
...download,
status: "removed",
});
};
registerEvent("cancelGameDownload", cancelGameDownload);

View file

@ -15,6 +15,7 @@ const pauseGameSeed = async (
await downloadsSublevel.put(downloadKey, {
...download,
status: "complete",
shouldSeed: false,
});

View file

@ -8,12 +8,14 @@ const resumeGameSeed = async (
shop: GameShop,
objectId: string
) => {
const download = await downloadsSublevel.get(levelKeys.game(shop, objectId));
const downloadKey = levelKeys.game(shop, objectId);
const download = await downloadsSublevel.get(downloadKey);
if (!download) return;
await downloadsSublevel.put(levelKeys.game(shop, objectId), {
await downloadsSublevel.put(downloadKey, {
...download,
status: "seeding",
shouldSeed: true,
});

View file

@ -32,7 +32,7 @@ export const getUnlockedAchievements = async (
return achievementsData
.map((achievementData) => {
const unlockedAchiementData = unlockedAchievements.find(
const unlockedAchievementData = unlockedAchievements.find(
(localAchievement) => {
return (
localAchievement.name.toUpperCase() ==
@ -45,11 +45,11 @@ export const getUnlockedAchievements = async (
? achievementData.icon
: achievementData.icongray;
if (unlockedAchiementData) {
if (unlockedAchievementData) {
return {
...achievementData,
unlocked: true,
unlockTime: unlockedAchiementData.unlockTime,
unlockTime: unlockedAchievementData.unlockTime,
};
}

View file

@ -49,23 +49,21 @@ export const loadState = async () => {
.values()
.all()
.then((games) => {
return sortBy(
games.filter((game) => game.queued),
"timestamp",
"DESC"
);
return sortBy(games, "timestamp", "DESC");
});
const [nextItemOnQueue] = downloads;
const [nextItemOnQueue] = downloads.filter((game) => game.queued);
const downloadsToSeed = downloads.filter(
(download) =>
download.shouldSeed &&
download.downloader === Downloader.Torrent &&
download.progress === 1 &&
download.uri !== null
(game) =>
game.shouldSeed &&
game.downloader === Downloader.Torrent &&
game.progress === 1 &&
game.uri !== null
);
console.log("downloadsToSeed", downloadsToSeed);
await DownloadManager.startRPC(nextItemOnQueue, downloadsToSeed);
startMainLoop();

View file

@ -23,9 +23,8 @@ const saveAchievementsOnLocal = async (
return gameAchievementsSublevel
.get(levelKey)
.then(async (gameAchievement) => {
if (gameAchievement) {
await gameAchievementsSublevel.put(levelKey, {
...gameAchievement,
achievements: gameAchievement?.achievements ?? [],
unlockedAchievements: unlockedAchievements,
});
@ -39,7 +38,6 @@ const saveAchievementsOnLocal = async (
);
})
.catch(() => {});
}
});
};
@ -133,7 +131,7 @@ export const mergeAchievements = async (
);
})
.catch((err) => {
if (err! instanceof SubscriptionRequiredError) {
if (err instanceof SubscriptionRequiredError) {
achievementsLogger.log(
"Achievements not synchronized on API due to lack of subscription",
game.objectId,

View file

@ -6,7 +6,7 @@ import { parseAchievementFile } from "./parse-achievement-file";
import { mergeAchievements } from "./merge-achievements";
import type { Game, UnlockedAchievement } from "@types";
export const updateLocalUnlockedAchivements = async (game: Game) => {
export const updateLocalUnlockedAchievements = async (game: Game) => {
const gameAchievementFiles = findAchievementFiles(game);
const achievementFileInsideDirectory =

View file

@ -219,9 +219,11 @@ export class DownloadManager {
} as PauseDownloadPayload)
.catch(() => {});
if (downloadKey === this.downloadingGameId) {
WindowManager.mainWindow?.setProgressBar(-1);
this.downloadingGameId = null;
}
}
static async resumeDownload(download: Download) {
return this.startDownload(download);

View file

@ -24,7 +24,7 @@ export const mergeWithRemoteGames = async () => {
? game.playTimeInMilliseconds
: localGame.playTimeInMilliseconds;
gamesSublevel.put(levelKeys.game(game.shop, game.objectId), {
await gamesSublevel.put(levelKeys.game(game.shop, game.objectId), {
...localGame,
remoteId: game.id,
lastTimePlayed: updatedLastTimePlayed,
@ -39,7 +39,7 @@ export const mergeWithRemoteGames = async () => {
? steamUrlBuilder.icon(game.objectId, steamGame.clientIcon)
: null;
gamesSublevel.put(levelKeys.game(game.shop, game.objectId), {
await gamesSublevel.put(levelKeys.game(game.shop, game.objectId), {
objectId: game.objectId,
title: steamGame?.name,
remoteId: game.id,

View file

@ -245,13 +245,16 @@ export class WindowManager {
);
} else {
editorWindow.loadFile(path.join(__dirname, "../renderer/index.html"), {
hash: `editor?themeId=${themeId}`,
hash: `theme-editor?themeId=${themeId}`,
});
}
editorWindow.once("ready-to-show", () => {
editorWindow.show();
WindowManager.mainWindow?.webContents.openDevTools();
this.mainWindow?.webContents.openDevTools();
if (isStaging) {
editorWindow.webContents.openDevTools();
}
});
editorWindow.webContents.on("before-input-event", (event, input) => {
@ -262,7 +265,7 @@ export class WindowManager {
});
editorWindow.on("close", () => {
WindowManager.mainWindow?.webContents.closeDevTools();
this.mainWindow?.webContents.closeDevTools();
this.editorWindows.delete(themeId);
});
}

View file

@ -23,6 +23,7 @@
&__content {
display: flex;
flex-direction: column;
flex: 1;
padding: calc(globals.$spacing-unit * 2);
gap: calc(globals.$spacing-unit * 2);
width: 100%;
@ -54,6 +55,7 @@
display: flex;
color: globals.$muted-color;
border-radius: 4px;
&:hover {
background-color: rgba(255, 255, 255, 0.15);
}
@ -104,13 +106,14 @@
&__container {
display: flex;
flex-direction: column;
flex: 1;
overflow: hidden;
}
&__section {
gap: calc(globals.$spacing-unit * 2);
display: flex;
flex-direction: column;
gap: calc(globals.$spacing-unit * 2);
padding-bottom: globals.$spacing-unit;
}

View file

@ -39,7 +39,7 @@ export function useDownload() {
const pauseDownload = async (shop: GameShop, objectId: string) => {
await window.electron.pauseGameDownload(shop, objectId);
await updateLibrary();
dispatch(clearDownload());
if (lastPacket?.gameId === `${shop}:${objectId}`) dispatch(clearDownload());
};
const resumeDownload = async (shop: GameShop, objectId: string) => {

View file

@ -5,6 +5,14 @@
flex-direction: column;
gap: calc(globals.$spacing-unit * 2);
&__details-with-article {
display: flex;
align-items: center;
gap: calc(globals.$spacing-unit / 2);
align-self: flex-start;
cursor: pointer;
}
&__header {
display: flex;
align-items: center;

View file

@ -24,6 +24,7 @@ import {
DownloadIcon,
LinkIcon,
PlayIcon,
QuestionIcon,
ThreeBarsIcon,
TrashIcon,
UnlinkIcon,
@ -123,8 +124,12 @@ export function DownloadGroup({
</p>
{download.downloader === Downloader.Torrent && (
<small>
<small
className="download-group__details-with-article"
data-open-article="peers-and-seeds"
>
{lastPacket?.numPeers} peers / {lastPacket?.numSeeds} seeds
<QuestionIcon size={12} />
</small>
)}
</>
@ -137,7 +142,14 @@ export function DownloadGroup({
return download.status === "seeding" &&
download.downloader === Downloader.Torrent ? (
<>
<p>{t("seeding")}</p>
<p
data-open-article="seeding"
className="download-group__details-with-article"
>
{t("seeding")}
<QuestionIcon />
</p>
{uploadSpeed && <p>{uploadSpeed}/s</p>}
</>
) : (
@ -175,7 +187,7 @@ export function DownloadGroup({
const deleting = isGameDeleting(game.id);
if (download?.progress === 1) {
if (game.download?.progress === 1) {
return [
{
label: t("install"),
@ -190,8 +202,8 @@ export function DownloadGroup({
disabled: deleting,
icon: <UnlinkIcon />,
show:
download.status === "seeding" &&
download.downloader === Downloader.Torrent,
game.download?.status === "seeding" &&
game.download?.downloader === Downloader.Torrent,
onClick: () => {
pauseSeeding(game.shop, game.objectId);
},
@ -201,8 +213,8 @@ export function DownloadGroup({
disabled: deleting,
icon: <LinkIcon />,
show:
download.status !== "seeding" &&
download.downloader === Downloader.Torrent,
game.download?.status !== "seeding" &&
game.download?.downloader === Downloader.Torrent,
onClick: () => {
resumeSeeding(game.shop, game.objectId);
},
@ -218,7 +230,7 @@ export function DownloadGroup({
];
}
if (isGameDownloading || download?.status === "active") {
if (isGameDownloading) {
return [
{
label: t("pause"),

View file

@ -8,7 +8,7 @@ import "./downloads.scss";
import { DeleteGameModal } from "./delete-game-modal";
import { DownloadGroup } from "./download-group";
import type { GameShop, LibraryGame, SeedingStatus } from "@types";
import { orderBy, sortBy } from "lodash-es";
import { orderBy } from "lodash-es";
import { ArrowDownIcon } from "@primer/octicons-react";
export default function Downloads() {
@ -58,11 +58,13 @@ export default function Downloads() {
complete: [],
};
const result = sortBy(library, (game) => game.download?.timestamp).reduce(
(prev, next) => {
/* Game has been manually added to the library or has been canceled */
if (!next.download?.status || next.download?.status === "removed")
return prev;
const result = orderBy(
library,
(game) => game.download?.timestamp,
"desc"
).reduce((prev, next) => {
/* Game has been manually added to the library */
if (!next.download) return prev;
/* Is downloading */
if (lastPacket?.gameId === next.id)
@ -73,9 +75,7 @@ export default function Downloads() {
return { ...prev, queued: [...prev.queued, next] };
return { ...prev, complete: [...prev.complete, next] };
},
initialValue
);
}, initialValue);
const queued = orderBy(result.queued, (game) => game.download?.timestamp, [
"desc",

View file

@ -67,7 +67,7 @@ export const ThemeActions = ({
onClick={() => setAddThemeModalVisible(true)}
>
<PlusIcon />
{t("add_theme")}
{t("create_theme")}
</Button>
</div>
</div>

View file

@ -56,8 +56,8 @@ export const AddThemeModal = ({
return (
<Modal
visible={visible}
title={t("add_theme_modal_title")}
description={t("add_theme_modal_description")}
title={t("create_theme_modal_title")}
description={t("create_theme_modal_description")}
onClose={onClose}
>
<div className="add-theme-modal__container">
@ -72,7 +72,7 @@ export const AddThemeModal = ({
/>
<Button theme="primary" onClick={handleSubmit}>
{t("add_theme")}
{t("create_theme")}
</Button>
</div>
</Modal>