Skip to content

Commit

Permalink
feat: adding aria2c
Browse files Browse the repository at this point in the history
  • Loading branch information
thegrannychaseroperation committed Nov 28, 2024
1 parent 2d8b63c commit 4060f7a
Show file tree
Hide file tree
Showing 30 changed files with 372 additions and 1,352 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
MAIN_VITE_API_URL=API_URL
MAIN_VITE_AUTH_URL=AUTH_URL
MAIN_VITE_STEAMGRIDDB_API_KEY=YOUR_API_KEY
RENDERER_VITE_INTERCOM_APP_ID=YOUR_APP_ID
73 changes: 73 additions & 0 deletions postinstall.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { default: axios } = require("axios");
const util = require("node:util");
const fs = require("node:fs");
const path = require("node:path");
const { spawnSync } = require("node:child_process");

const exec = util.promisify(require("node:child_process").exec);

Expand Down Expand Up @@ -46,4 +47,76 @@ const downloadLudusavi = async () => {
});
};

const downloadAria2WindowsAndLinux = async () => {
if (fs.existsSync("aria2")) {
console.log("Aria2 already exists, skipping download...");
return;
}

const file =
process.platform === "win32"
? "aria2-1.37.0-win-64bit-build1.zip"
: "aria2-1.37.0-1-x86_64.pkg.tar.zst";

const downloadUrl =
process.platform === "win32"
? `https://github.com/aria2/aria2/releases/download/release-1.37.0/${file}`
: "https://archlinux.org/packages/extra/x86_64/aria2/download/";

console.log(`Downloading ${file}...`);

const response = await axios.get(downloadUrl, { responseType: "stream" });

const stream = response.data.pipe(fs.createWriteStream(file));

stream.on("finish", async () => {
console.log(`Downloaded ${file}, extracting...`);

if (process.platform === "win32") {
await exec(`npx extract-zip ${file}`);
console.log("Extracted. Renaming folder...");

fs.renameSync(file.replace(".zip", ""), "aria2");
} else {
await exec(`tar --zstd -xvf ${file} usr/bin/aria2c`);
console.log("Extracted. Copying binary file...");
fs.mkdirSync("aria2");
fs.copyFileSync("usr/bin/aria2c", "aria2/aria2c");
fs.rmSync("usr", { recursive: true });
}

console.log(`Extracted ${file}, removing compressed downloaded file...`);
fs.rmSync(file);
});
};

const copyAria2Macos = async () => {
console.log("Checking if aria2 is installed...");

const isAria2Installed = spawnSync("which", ["aria2c"]).status;

if (isAria2Installed != 0) {
console.log("Please install aria2");
console.log("brew install aria2");
return;
}

console.log("Copying aria2 binary...");
fs.mkdirSync("aria2");
await exec(`cp $(which aria2c) aria2/aria2c`);
};

if (process.platform === "win32") {
fs.copyFileSync(
"node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe",
"fastlist.exe"
);
}

if (process.platform == "darwin") {
copyAria2Macos();
} else {
downloadAria2WindowsAndLinux();
}

downloadLudusavi();
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ cx_Logging; sys_platform == 'win32'
pywin32; sys_platform == 'win32'
psutil
Pillow
flask
aria2p
10 changes: 3 additions & 7 deletions src/main/events/auth/sign-out.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { registerEvent } from "../register-event";
import {
DownloadManager,
HydraApi,
PythonInstance,
gamesPlaytime,
} from "@main/services";
import { DownloadManager, HydraApi, gamesPlaytime } from "@main/services";
import { dataSource } from "@main/data-source";
import { DownloadQueue, Game, UserAuth, UserSubscription } from "@main/entity";

Expand Down Expand Up @@ -32,7 +27,8 @@ const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
DownloadManager.cancelDownload();

/* Disconnects libtorrent */
PythonInstance.killTorrent();
// TODO
// TorrentDownloader.killTorrent();

HydraApi.handleSignOut();

Expand Down
5 changes: 3 additions & 2 deletions src/main/events/library/close-game.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gameRepository } from "@main/repository";
import { registerEvent } from "../register-event";
import { PythonInstance, logger } from "@main/services";
import { logger } from "@main/services";
import sudo from "sudo-prompt";
import { app } from "electron";

Expand All @@ -16,7 +16,8 @@ const closeGame = async (
_event: Electron.IpcMainInvokeEvent,
gameId: number
) => {
const processes = await PythonInstance.getProcessList();
// const processes = await PythonInstance.getProcessList();
const processes = [];
const game = await gameRepository.findOne({
where: { id: gameId, isDeleted: false },
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/events/profile/process-profile-image.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { registerEvent } from "../register-event";
import { PythonInstance } from "@main/services";

const processProfileImage = async (
_event: Electron.IpcMainInvokeEvent,
path: string
) => {
return PythonInstance.processProfileImage(path);
return path;
// return PythonInstance.processProfileImage(path);
};

registerEvent("processProfileImage", processProfileImage);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RealDebridClient } from "@main/services/real-debrid";
import { RealDebridClient } from "@main/services/download/real-debrid";
import { registerEvent } from "../register-event";

const authenticateRealDebrid = async (
Expand Down
7 changes: 5 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import path from "node:path";
import url from "node:url";
import fs from "node:fs";
import { electronApp, optimizer } from "@electron-toolkit/utils";
import { logger, PythonInstance, WindowManager } from "@main/services";
import { logger, WindowManager } from "@main/services";
import { dataSource } from "@main/data-source";
import resources from "@locales";
import { userPreferencesRepository } from "@main/repository";
import { knexClient, migrationConfig } from "./knex-client";
import { databaseDirectory } from "./constants";
import { PythonRPC } from "./services/python-rpc";
import { Aria2 } from "./services/aria2";

const { autoUpdater } = updater;

Expand Down Expand Up @@ -146,7 +148,8 @@ app.on("window-all-closed", () => {

app.on("before-quit", () => {
/* Disconnects libtorrent */
PythonInstance.kill();
PythonRPC.kill();
Aria2.kill();
});

app.on("activate", () => {
Expand Down
26 changes: 14 additions & 12 deletions src/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import {
DownloadManager,
Ludusavi,
PythonInstance,
startMainLoop,
} from "./services";
import { DownloadManager, Ludusavi, startMainLoop } from "./services";
import {
downloadQueueRepository,
userPreferencesRepository,
} from "./repository";
import { UserPreferences } from "./entity";
import { RealDebridClient } from "./services/real-debrid";
import { RealDebridClient } from "./services/download/real-debrid";
import { HydraApi } from "./services/hydra-api";
import { uploadGamesBatch } from "./services/library-sync";
import { PythonRPC } from "./services/python-rpc";
import { Aria2 } from "./services/aria2";

const loadState = async (userPreferences: UserPreferences | null) => {
import("./events");

Aria2.spawn();

if (userPreferences?.realDebridApiToken) {
RealDebridClient.authorize(userPreferences?.realDebridApiToken);
}
Expand All @@ -35,11 +34,14 @@ const loadState = async (userPreferences: UserPreferences | null) => {
},
});

if (nextQueueItem?.game.status === "active") {
DownloadManager.startDownload(nextQueueItem.game);
} else {
PythonInstance.spawn();
}
PythonRPC.spawn();
// start download

// if (nextQueueItem?.game.status === "active") {
// DownloadManager.startDownload(nextQueueItem.game);
// } else {
// PythonInstance.spawn();
// }

startMainLoop();
};
Expand Down
Loading

0 comments on commit 4060f7a

Please sign in to comment.