This commit is contained in:
lilezek
2024-05-04 12:07:44 +02:00
29 changed files with 1212 additions and 1208 deletions

View File

@@ -11,6 +11,9 @@ import { HTTPDownloader } from "./http-downloader";
import { Unrar } from "../unrar";
import { GameStatus } from "@globals";
import path from "node:path";
import crypto from "node:crypto";
import fs from "node:fs";
interface DownloadStatus {
numPeers: number;
@@ -112,7 +115,7 @@ export class Downloader {
});
if (
gameUpdate.progress === 1 &&
game?.progress === 1 &&
gameUpdate.status !== GameStatus.Decompressing
) {
const userPreferences = await userPreferencesRepository.findOne({
@@ -120,7 +123,10 @@ export class Downloader {
});
if (userPreferences?.downloadNotificationsEnabled) {
const iconPath = await this.createTempIcon(game.iconUrl);
new Notification({
icon: iconPath,
title: t("download_complete", {
ns: "notifications",
lng: userPreferences.language,
@@ -186,4 +192,23 @@ export class Downloader {
return game.decompressionProgress;
return game.progress;
}
private static createTempIcon(encodedIcon: string): Promise<string> {
return new Promise((resolve, reject) => {
const hash = crypto.randomBytes(16).toString("hex");
const iconPath = path.join(app.getPath("temp"), `${hash}.png`);
fs.writeFile(
iconPath,
Buffer.from(
encodedIcon.replace("data:image/jpeg;base64,", ""),
"base64"
),
(err) => {
if (err) reject(err);
resolve(iconPath);
}
);
});
}
}

View File

@@ -20,6 +20,7 @@ export const startProcessWatcher = async () => {
});
if (games.length === 0) {
await sleep(sleepTime);
continue;
}

View File

@@ -52,8 +52,7 @@ const getXatabRepack = (url: string) => {
worker.removeListener("message", onMessage);
};
worker.on("message", onMessage);
worker.postMessage($downloadButton.href);
worker.once("message", onMessage);
})();
});
};