mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
feat: use main-loop to watch seeding list
This commit is contained in:
parent
cd4715e00d
commit
e0f7f34d14
@ -98,6 +98,17 @@ export class DownloadManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async watchSeedingList() {
|
||||||
|
const seedingList = await PythonInstance.getSeedingList();
|
||||||
|
|
||||||
|
if (seedingList) {
|
||||||
|
WindowManager.mainWindow?.webContents.send(
|
||||||
|
"on-seeding-list",
|
||||||
|
JSON.parse(JSON.stringify(seedingList))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static async pauseDownload() {
|
static async pauseDownload() {
|
||||||
if (this.currentDownloader === Downloader.Torrent) {
|
if (this.currentDownloader === Downloader.Torrent) {
|
||||||
await PythonInstance.pauseDownload();
|
await PythonInstance.pauseDownload();
|
||||||
|
@ -60,14 +60,15 @@ export class PythonInstance {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getStatus() {
|
public static async getSeedingList() {
|
||||||
if (this.downloadingGameId === -1) return null;
|
|
||||||
|
|
||||||
const response = await this.rpc.get<LibtorrentPayload | null>("/status");
|
const response = await this.rpc.get<LibtorrentPayload | null>("/status");
|
||||||
|
|
||||||
if (response.data === null) return null;
|
return response.data?.seeding || [];
|
||||||
|
}
|
||||||
|
|
||||||
console.log(response.data);
|
public static async getStatus() {
|
||||||
|
const response = await this.rpc.get<LibtorrentPayload | null>("/status");
|
||||||
|
if (response.data?.downloading === null) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
@ -80,7 +81,7 @@ export class PythonInstance {
|
|||||||
folderName,
|
folderName,
|
||||||
status,
|
status,
|
||||||
gameId,
|
gameId,
|
||||||
} = response.data;
|
} = response.data?.downloading!;
|
||||||
|
|
||||||
this.downloadingGameId = gameId;
|
this.downloadingGameId = gameId;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ export enum LibtorrentStatus {
|
|||||||
Seeding = 5,
|
Seeding = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LibtorrentPayload {
|
export interface LibtorrentGamePayload {
|
||||||
progress: number;
|
progress: number;
|
||||||
numPeers: number;
|
numPeers: number;
|
||||||
numSeeds: number;
|
numSeeds: number;
|
||||||
@ -32,6 +32,23 @@ export interface LibtorrentPayload {
|
|||||||
gameId: number;
|
gameId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LibtorrentPayload {
|
||||||
|
downloading?: LibtorrentGamePayload;
|
||||||
|
seeding: LibtorrentGamePayload[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LibtorrentSeedingPayload {
|
||||||
|
progress: number;
|
||||||
|
numPeers: number;
|
||||||
|
numSeeds: number;
|
||||||
|
uploadSpeed: number;
|
||||||
|
// isCheckingFiles: boolean;
|
||||||
|
fileSize: number;
|
||||||
|
folderName: string;
|
||||||
|
status: LibtorrentStatus;
|
||||||
|
gameId: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ProcessPayload {
|
export interface ProcessPayload {
|
||||||
exe: string;
|
exe: string;
|
||||||
pid: number;
|
pid: number;
|
||||||
|
@ -10,6 +10,7 @@ export const startMainLoop = async () => {
|
|||||||
watchProcesses(),
|
watchProcesses(),
|
||||||
DownloadManager.watchDownloads(),
|
DownloadManager.watchDownloads(),
|
||||||
AchievementWatcherManager.watchAchievements(),
|
AchievementWatcherManager.watchAchievements(),
|
||||||
|
DownloadManager.watchSeedingList(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await sleep(1500);
|
await sleep(1500);
|
||||||
|
@ -15,6 +15,7 @@ import type {
|
|||||||
import type { CatalogueCategory } from "@shared";
|
import type { CatalogueCategory } from "@shared";
|
||||||
import type { AxiosProgressEvent } from "axios";
|
import type { AxiosProgressEvent } from "axios";
|
||||||
import { GameAchievement } from "@main/entity";
|
import { GameAchievement } from "@main/entity";
|
||||||
|
import { LibtorrentSeedingPayload } from "@main/services/download/types";
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld("electron", {
|
contextBridge.exposeInMainWorld("electron", {
|
||||||
/* Torrenting */
|
/* Torrenting */
|
||||||
@ -36,6 +37,12 @@ contextBridge.exposeInMainWorld("electron", {
|
|||||||
ipcRenderer.on("on-download-progress", listener);
|
ipcRenderer.on("on-download-progress", listener);
|
||||||
return () => ipcRenderer.removeListener("on-download-progress", listener);
|
return () => ipcRenderer.removeListener("on-download-progress", listener);
|
||||||
},
|
},
|
||||||
|
onSeedingList: (cb: (value: LibtorrentSeedingPayload[]) => void) => {
|
||||||
|
const listener = (_event: Electron.IpcRendererEvent, value: LibtorrentSeedingPayload[]) => cb(value);
|
||||||
|
ipcRenderer.on("on-seeding-list", listener);
|
||||||
|
return () => ipcRenderer.removeListener("on-seeding-list", listener);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/* Catalogue */
|
/* Catalogue */
|
||||||
searchGames: (query: string) => ipcRenderer.invoke("searchGames", query),
|
searchGames: (query: string) => ipcRenderer.invoke("searchGames", query),
|
||||||
|
3
src/renderer/src/declaration.d.ts
vendored
3
src/renderer/src/declaration.d.ts
vendored
@ -49,6 +49,9 @@ declare global {
|
|||||||
onDownloadProgress: (
|
onDownloadProgress: (
|
||||||
cb: (value: DownloadProgress) => void
|
cb: (value: DownloadProgress) => void
|
||||||
) => () => Electron.IpcRenderer;
|
) => () => Electron.IpcRenderer;
|
||||||
|
onSeedingList: (
|
||||||
|
cb: (value: LibtorrentSeedingPayload[]) => void
|
||||||
|
) => () => Electron.IpcRenderer;
|
||||||
|
|
||||||
/* Catalogue */
|
/* Catalogue */
|
||||||
searchGames: (query: string) => Promise<CatalogueEntry[]>;
|
searchGames: (query: string) => Promise<CatalogueEntry[]>;
|
||||||
|
@ -2,12 +2,12 @@ import { useTranslation } from "react-i18next";
|
|||||||
|
|
||||||
import { useDownload, useLibrary } from "@renderer/hooks";
|
import { useDownload, useLibrary } from "@renderer/hooks";
|
||||||
|
|
||||||
import { useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { BinaryNotFoundModal } from "../shared-modals/binary-not-found-modal";
|
import { BinaryNotFoundModal } from "../shared-modals/binary-not-found-modal";
|
||||||
import * as styles from "./downloads.css";
|
import * as styles from "./downloads.css";
|
||||||
import { DeleteGameModal } from "./delete-game-modal";
|
import { DeleteGameModal } from "./delete-game-modal";
|
||||||
import { DownloadGroup } from "./download-group";
|
import { DownloadGroup } from "./download-group";
|
||||||
import type { LibraryGame } from "@types";
|
import type { LibraryGame, SeedingList } from "@types";
|
||||||
import { orderBy } from "lodash-es";
|
import { orderBy } from "lodash-es";
|
||||||
import { ArrowDownIcon } from "@primer/octicons-react";
|
import { ArrowDownIcon } from "@primer/octicons-react";
|
||||||
|
|
||||||
@ -30,6 +30,14 @@ export default function Downloads() {
|
|||||||
|
|
||||||
const { lastPacket } = useDownload();
|
const { lastPacket } = useDownload();
|
||||||
|
|
||||||
|
const [seedingList, setSeedingList] = useState<SeedingList[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.electron.onSeedingList((value) => setSeedingList(value));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
console.log("sexo", seedingList);
|
||||||
|
|
||||||
const handleOpenGameInstaller = (gameId: number) =>
|
const handleOpenGameInstaller = (gameId: number) =>
|
||||||
window.electron.openGameInstaller(gameId).then((isBinaryInPath) => {
|
window.electron.openGameInstaller(gameId).then((isBinaryInPath) => {
|
||||||
if (!isBinaryInPath) setShowBinaryNotFoundModal(true);
|
if (!isBinaryInPath) setShowBinaryNotFoundModal(true);
|
||||||
|
@ -151,6 +151,13 @@ export interface DownloadProgress {
|
|||||||
game: LibraryGame;
|
game: LibraryGame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SeedingList {
|
||||||
|
progress: number;
|
||||||
|
numPeers: number;
|
||||||
|
numSeeds: number;
|
||||||
|
uploadSpeed: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface UserPreferences {
|
export interface UserPreferences {
|
||||||
downloadsPath: string | null;
|
downloadsPath: string | null;
|
||||||
language: string;
|
language: string;
|
||||||
|
@ -169,6 +169,6 @@ class TorrentDownloader:
|
|||||||
elif status.state == 5:
|
elif status.state == 5:
|
||||||
response['seeding'].append(torrent_info)
|
response['seeding'].append(torrent_info)
|
||||||
|
|
||||||
print(response)
|
# print(response)
|
||||||
# return response
|
return response
|
||||||
return None
|
# return None
|
Loading…
Reference in New Issue
Block a user