mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-02 16:23:48 +03:00
Merge branch 'main' into teste-locale2
This commit is contained in:
commit
6ae5f92ba9
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydra",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.2",
|
||||
"description": "Hydra",
|
||||
"main": "./out/main/index.js",
|
||||
"author": "Los Broxas",
|
||||
@ -10,6 +10,10 @@
|
||||
"url": "https://github.com/hydralauncher/hydra.git"
|
||||
},
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"npm": "please-use-yarn",
|
||||
"yarn": ">= 1.19.1"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "prettier --write .",
|
||||
"format-check": "prettier --check .",
|
||||
@ -25,7 +29,8 @@
|
||||
"build:win": "electron-vite build && electron-builder --win",
|
||||
"build:mac": "electron-vite build && electron-builder --mac",
|
||||
"build:linux": "electron-vite build && electron-builder --linux",
|
||||
"prepare": "husky"
|
||||
"prepare": "husky",
|
||||
"typeorm:migration-create": "yarn typeorm migration:create"
|
||||
},
|
||||
"dependencies": {
|
||||
"@electron-toolkit/preload": "^3.0.0",
|
||||
|
@ -17,7 +17,11 @@
|
||||
"downloading": "{{title}} ({{percentage}} - Pobieranie…)",
|
||||
"filter": "Filtruj biblioteke",
|
||||
"follow_us": "Śledź nas",
|
||||
"home": "Główna"
|
||||
"home": "Główna",
|
||||
"discord": "Dołącz nasz Discord",
|
||||
"telegram": "Dołącz nasz Telegram",
|
||||
"x": "Śledź na X",
|
||||
"github": "Przyczyń się na GitHub"
|
||||
},
|
||||
"header": {
|
||||
"search": "Szukaj",
|
||||
@ -66,6 +70,8 @@
|
||||
"copied_link_to_clipboard": "Skopiowano łącze",
|
||||
"hours": "godzin",
|
||||
"minutes": "minut",
|
||||
"amount_hours": "{{amount}} godzin",
|
||||
"amount_minutes": "{{amount}} minut",
|
||||
"accuracy": "{{accuracy}}% dokładność",
|
||||
"add_to_library": "Dodaj do biblioteki",
|
||||
"remove_from_library": "Usuń z biblioteki",
|
||||
@ -80,9 +86,23 @@
|
||||
"playing_now": "Granie teraz",
|
||||
"change": "Zmień",
|
||||
"repacks_modal_description": "Wybierz repack, który chcesz pobrać",
|
||||
"downloads_path": "Ścieżka pobierania",
|
||||
"select_folder_hint": "Aby zmienić domyślny folder, przejdź do",
|
||||
"download_now": "Pobierz teraz"
|
||||
"download_now": "Pobierz teraz",
|
||||
"installation_instructions": "Instrukcja instalacji",
|
||||
"installation_instructions_description": "Do zainstalowania tej gry wymagane są dodatkowe kroki",
|
||||
"online_fix_instruction": "Gry OnlineFix wymagają hasła do wyodrębnienia. W razie potrzeby użyj następującego hasła:",
|
||||
"dodi_installation_instruction": "Po otwarciu instalatora DODI naciśnij klawisz <0 /> w górę, aby rozpocząć proces instalacji:",
|
||||
"dont_show_it_again": "Nie pokazuj tego ponownie",
|
||||
"copy_to_clipboard": "Skopiuj",
|
||||
"copied_to_clipboard": "Skopiowano",
|
||||
"got_it": "Rozumiem",
|
||||
"no_shop_details": "Nie udało się pobrać danych sklepu.",
|
||||
"download_options": "Opcje pobierania",
|
||||
"download_path": "Ścieżka pobierania",
|
||||
"previous_screenshot": "Poprzedni zrzut ekranu",
|
||||
"next_screenshot": "Następny zrzut ekranu",
|
||||
"screenshot": "Zrzut ekranu {{number}}",
|
||||
"open_screenshot": "Otwórz zrzut ekranu {{number}}"
|
||||
},
|
||||
"activation": {
|
||||
"title": "Aktywuj Hydra",
|
||||
@ -113,7 +133,9 @@
|
||||
"remove_from_list": "Usuń",
|
||||
"delete_modal_title": "Czy na pewno?",
|
||||
"delete_modal_description": "Spowoduje to usunięcie wszystkich plików instalacyjnych z komputera",
|
||||
"install": "Instaluj"
|
||||
"install": "Instaluj",
|
||||
"real_debrid": "Real Debrid",
|
||||
"torrent": "Torrent"
|
||||
},
|
||||
"settings": {
|
||||
"downloads_path": "Ścieżka pobierania",
|
||||
@ -123,6 +145,15 @@
|
||||
"enable_repack_list_notifications": "Gdy dodawany jest nowy repack",
|
||||
"telemetry": "Telemetria",
|
||||
"telemetry_description": "Włącz anonimowe statystyki użycia",
|
||||
"real_debrid_api_token_label": "Real Debrid API token",
|
||||
"quit_app_instead_hiding": "Zamknij Hydr zamiast minimalizować do zasobnika",
|
||||
"launch_with_system": "Uruchom Hydra przy starcie systemu",
|
||||
"general": "Ogólne",
|
||||
"behavior": "Zachowania",
|
||||
"enable_real_debrid": "Włącz Real Debrid",
|
||||
"real_debrid": "Real Debrid",
|
||||
"real_debrid_api_token_hint": "Możesz uzyskać swój klucz API <0>tutaj</0>.",
|
||||
"save_changes": "Zapisz zmiany",
|
||||
"language": "Język"
|
||||
},
|
||||
"notifications": {
|
||||
@ -143,5 +174,8 @@
|
||||
"title": "Programy nie są zainstalowane",
|
||||
"description": "Pliki wykonywalne Wine lub Lutris nie zostały znalezione na twoim systemie",
|
||||
"instructions": "Sprawdź prawidłowy sposób instalacji dowolnego z nich w swojej dystrybucji Linuksa, aby gra działała normalnie"
|
||||
},
|
||||
"modal": {
|
||||
"close": "Zamknij"
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import {
|
||||
import type { SqliteConnectionOptions } from "typeorm/driver/sqlite/SqliteConnectionOptions";
|
||||
|
||||
import { databasePath } from "./constants";
|
||||
import migrations from "./migrations";
|
||||
|
||||
export const createDataSource = (options: Partial<SqliteConnectionOptions>) =>
|
||||
new DataSource({
|
||||
@ -19,4 +20,6 @@ export const createDataSource = (options: Partial<SqliteConnectionOptions>) =>
|
||||
...options,
|
||||
});
|
||||
|
||||
export const dataSource = createDataSource({});
|
||||
export const dataSource = createDataSource({
|
||||
migrations: migrations,
|
||||
});
|
||||
|
@ -53,6 +53,8 @@ app.whenReady().then(() => {
|
||||
);
|
||||
|
||||
dataSource.initialize().then(async () => {
|
||||
await dataSource.runMigrations();
|
||||
|
||||
await resolveDatabaseUpdates();
|
||||
|
||||
await import("./main");
|
||||
|
78
src/main/migrations/1715900413313-fix_repack_uploadDate.ts
Normal file
78
src/main/migrations/1715900413313-fix_repack_uploadDate.ts
Normal file
@ -0,0 +1,78 @@
|
||||
import { createDataSource } from "@main/data-source";
|
||||
import { Repack } from "@main/entity";
|
||||
import { app } from "electron";
|
||||
import { chunk } from "lodash-es";
|
||||
import path from "path";
|
||||
import { In, MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class FixRepackUploadDate1715900413313 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "repack_temp",
|
||||
columns: [
|
||||
{ name: "title", type: "varchar" },
|
||||
{ name: "old_id", type: "int" },
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
await queryRunner.query(
|
||||
`INSERT INTO repack_temp (title, old_id) SELECT title, id FROM repack WHERE repacker IN ('onlinefix', 'Xatab');`
|
||||
);
|
||||
|
||||
await queryRunner.query(
|
||||
`DELETE FROM repack WHERE repacker IN ('onlinefix', 'Xatab');`
|
||||
);
|
||||
|
||||
const updateDataSource = createDataSource({
|
||||
database: app.isPackaged
|
||||
? path.join(process.resourcesPath, "hydra.db")
|
||||
: path.join(__dirname, "..", "..", "hydra.db"),
|
||||
});
|
||||
|
||||
await updateDataSource.initialize();
|
||||
|
||||
const updateRepackRepository = updateDataSource.getRepository(Repack);
|
||||
|
||||
const updatedRepacks = await updateRepackRepository.find({
|
||||
where: {
|
||||
repacker: In(["onlinefix", "Xatab"]),
|
||||
},
|
||||
});
|
||||
|
||||
const chunks = chunk(
|
||||
updatedRepacks.map((repack) => {
|
||||
const { id: _, ...rest } = repack;
|
||||
return rest;
|
||||
}),
|
||||
500
|
||||
);
|
||||
|
||||
for (const chunk of chunks) {
|
||||
await queryRunner.manager
|
||||
.createQueryBuilder(Repack, "repack")
|
||||
.insert()
|
||||
.values(chunk)
|
||||
.orIgnore()
|
||||
.execute();
|
||||
}
|
||||
|
||||
await queryRunner.query(
|
||||
`UPDATE game
|
||||
SET repackId = (
|
||||
SELECT id
|
||||
from repack LEFT JOIN repack_temp ON repack_temp.title = repack.title
|
||||
WHERE repack_temp.old_id = game.repackId
|
||||
)
|
||||
WHERE EXISTS (select old_id from repack_temp WHERE old_id = game.repackId)`
|
||||
);
|
||||
|
||||
await queryRunner.dropTable("repack_temp");
|
||||
}
|
||||
|
||||
public async down(_: QueryRunner): Promise<void> {
|
||||
return;
|
||||
}
|
||||
}
|
3
src/main/migrations/index.ts
Normal file
3
src/main/migrations/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { FixRepackUploadDate1715900413313 } from "./1715900413313-fix_repack_uploadDate";
|
||||
|
||||
export default [FixRepackUploadDate1715900413313];
|
@ -3,21 +3,19 @@ import { decodeNonUtf8Response, savePage } from "./helpers";
|
||||
import { logger } from "../logger";
|
||||
import { JSDOM } from "jsdom";
|
||||
|
||||
import { format, parse, sub } from "date-fns";
|
||||
import { ru } from "date-fns/locale";
|
||||
|
||||
import createWorker from "@main/workers/torrent-parser.worker?nodeWorker";
|
||||
import { toMagnetURI } from "parse-torrent";
|
||||
|
||||
const worker = createWorker({});
|
||||
|
||||
import { onlinefixFormatter } from "@main/helpers";
|
||||
import makeFetchCookie from "fetch-cookie";
|
||||
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
|
||||
import { formatBytes } from "@shared";
|
||||
|
||||
const ONLINE_FIX_URL = "https://online-fix.me/";
|
||||
|
||||
let totalPages = 1;
|
||||
|
||||
export const getNewRepacksFromOnlineFix = async (
|
||||
existingRepacks: Repack[] = [],
|
||||
page = 1,
|
||||
@ -74,18 +72,16 @@ export const getNewRepacksFromOnlineFix = async (
|
||||
|
||||
const repacks: QueryDeepPartialEntity<Repack>[] = [];
|
||||
const articles = Array.from(document.querySelectorAll(".news"));
|
||||
const totalPages = Number(
|
||||
document.querySelector("nav > a:nth-child(13)")?.textContent
|
||||
);
|
||||
|
||||
if (page == 1) {
|
||||
totalPages = Number(
|
||||
document.querySelector("nav > a:nth-child(13)")?.textContent
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
await Promise.all(
|
||||
articles.map(async (article) => {
|
||||
const gameText = article.querySelector("h2.title")?.textContent?.trim();
|
||||
if (!gameText) return;
|
||||
|
||||
const gameName = onlinefixFormatter(gameText);
|
||||
|
||||
const gameLink = article.querySelector("a")?.getAttribute("href");
|
||||
if (!gameLink) return;
|
||||
|
||||
@ -94,32 +90,6 @@ export const getNewRepacksFromOnlineFix = async (
|
||||
);
|
||||
const gameDocument = new JSDOM(gamePage).window.document;
|
||||
|
||||
const uploadDateText = gameDocument.querySelector("time")?.textContent;
|
||||
if (!uploadDateText) return;
|
||||
|
||||
let decodedDateText = uploadDateText;
|
||||
|
||||
// "Вчера" means yesterday.
|
||||
if (decodedDateText.includes("Вчера")) {
|
||||
const yesterday = sub(new Date(), { days: 1 });
|
||||
const formattedYesterday = format(yesterday, "d LLLL yyyy", {
|
||||
locale: ru,
|
||||
});
|
||||
decodedDateText = decodedDateText.replace(
|
||||
"Вчера", // "Change yesterday to the default expected date format"
|
||||
formattedYesterday
|
||||
);
|
||||
}
|
||||
|
||||
const uploadDate = parse(
|
||||
decodedDateText,
|
||||
"d LLLL yyyy, HH:mm",
|
||||
new Date(),
|
||||
{
|
||||
locale: ru,
|
||||
}
|
||||
);
|
||||
|
||||
const torrentButtons = Array.from(
|
||||
gameDocument.querySelectorAll("a")
|
||||
).filter((a) => a.textContent?.includes("Torrent"));
|
||||
@ -146,13 +116,17 @@ export const getNewRepacksFromOnlineFix = async (
|
||||
);
|
||||
|
||||
worker.once("message", (torrent) => {
|
||||
if (!torrent) return;
|
||||
|
||||
const { name, created } = torrent;
|
||||
|
||||
repacks.push({
|
||||
fileSize: formatBytes(torrent.length ?? 0),
|
||||
magnet: toMagnetURI(torrent),
|
||||
page: 1,
|
||||
repacker: "onlinefix",
|
||||
title: gameName,
|
||||
uploadDate: uploadDate,
|
||||
title: name,
|
||||
uploadDate: created,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -12,6 +12,9 @@ import { formatBytes } from "@shared";
|
||||
import { getFileBuffer } from "@main/helpers";
|
||||
|
||||
const worker = createWorker({});
|
||||
worker.setMaxListeners(11);
|
||||
|
||||
let totalPages = 1;
|
||||
|
||||
const formatXatabDate = (str: string) => {
|
||||
const date = new Date();
|
||||
@ -69,27 +72,37 @@ export const getNewRepacksFromXatab = async (
|
||||
|
||||
const repacks: QueryDeepPartialEntity<Repack>[] = [];
|
||||
|
||||
for (const $a of Array.from(
|
||||
window.document.querySelectorAll(".entry__title a")
|
||||
)) {
|
||||
try {
|
||||
const repack = await getXatabRepack(($a as HTMLAnchorElement).href);
|
||||
|
||||
if (repack) {
|
||||
repacks.push({
|
||||
title: $a.textContent!,
|
||||
repacker: "Xatab",
|
||||
...repack,
|
||||
page,
|
||||
});
|
||||
}
|
||||
} catch (err: unknown) {
|
||||
logger.error((err as Error).message, {
|
||||
method: "getNewRepacksFromXatab",
|
||||
});
|
||||
}
|
||||
if (page === 1) {
|
||||
totalPages = Number(
|
||||
window.document.querySelector(
|
||||
"#bottom-nav > div.pagination > a:nth-child(12)"
|
||||
)?.textContent
|
||||
);
|
||||
}
|
||||
|
||||
const repacksFromPage = Array.from(
|
||||
window.document.querySelectorAll(".entry__title a")
|
||||
).map(($a) => {
|
||||
return getXatabRepack(($a as HTMLAnchorElement).href)
|
||||
.then((repack) => {
|
||||
if (repack) {
|
||||
repacks.push({
|
||||
title: $a.textContent!,
|
||||
repacker: "Xatab",
|
||||
...repack,
|
||||
page,
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
logger.error((err as Error).message, {
|
||||
method: "getNewRepacksFromXatab",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
await Promise.all(repacksFromPage);
|
||||
|
||||
const newRepacks = repacks.filter(
|
||||
(repack) =>
|
||||
!existingRepacks.some(
|
||||
@ -98,6 +111,7 @@ export const getNewRepacksFromXatab = async (
|
||||
);
|
||||
|
||||
if (!newRepacks.length) return;
|
||||
if (page === totalPages) return;
|
||||
|
||||
await savePage(newRepacks);
|
||||
|
||||
|
@ -1,10 +1,19 @@
|
||||
import { BrowserWindow, Menu, Tray, app } from "electron";
|
||||
import {
|
||||
BrowserWindow,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemConstructorOptions,
|
||||
Tray,
|
||||
app,
|
||||
shell,
|
||||
} from "electron";
|
||||
import { is } from "@electron-toolkit/utils";
|
||||
import { t } from "i18next";
|
||||
import path from "node:path";
|
||||
import icon from "@resources/icon.png?asset";
|
||||
import trayIcon from "@resources/tray-icon.png?asset";
|
||||
import { userPreferencesRepository } from "@main/repository";
|
||||
import { gameRepository, userPreferencesRepository } from "@main/repository";
|
||||
import { IsNull, Not } from "typeorm";
|
||||
|
||||
export class WindowManager {
|
||||
public static mainWindow: Electron.BrowserWindow | null = null;
|
||||
@ -77,33 +86,66 @@ export class WindowManager {
|
||||
public static createSystemTray(language: string) {
|
||||
const tray = new Tray(trayIcon);
|
||||
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: t("open", {
|
||||
ns: "system_tray",
|
||||
lng: language,
|
||||
}),
|
||||
type: "normal",
|
||||
click: () => {
|
||||
if (this.mainWindow) {
|
||||
this.mainWindow.show();
|
||||
} else {
|
||||
this.createMainWindow();
|
||||
}
|
||||
const updateSystemTray = async () => {
|
||||
const games = await gameRepository.find({
|
||||
where: {
|
||||
isDeleted: false,
|
||||
executablePath: Not(IsNull()),
|
||||
lastTimePlayed: Not(IsNull()),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("quit", {
|
||||
ns: "system_tray",
|
||||
lng: language,
|
||||
}),
|
||||
type: "normal",
|
||||
click: () => app.quit(),
|
||||
},
|
||||
]);
|
||||
take: 5,
|
||||
order: {
|
||||
updatedAt: "DESC",
|
||||
},
|
||||
});
|
||||
|
||||
const recentlyPlayedGames: Array<MenuItemConstructorOptions | MenuItem> =
|
||||
games.map(({ title, executablePath }) => ({
|
||||
label: title,
|
||||
type: "normal",
|
||||
click: async () => {
|
||||
if (!executablePath) return;
|
||||
|
||||
shell.openPath(executablePath);
|
||||
},
|
||||
}));
|
||||
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: t("open", {
|
||||
ns: "system_tray",
|
||||
lng: language,
|
||||
}),
|
||||
type: "normal",
|
||||
click: () => {
|
||||
if (this.mainWindow) {
|
||||
this.mainWindow.show();
|
||||
} else {
|
||||
this.createMainWindow();
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
...recentlyPlayedGames,
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
{
|
||||
label: t("quit", {
|
||||
ns: "system_tray",
|
||||
lng: language,
|
||||
}),
|
||||
type: "normal",
|
||||
click: () => app.quit(),
|
||||
},
|
||||
]);
|
||||
|
||||
return contextMenu;
|
||||
};
|
||||
|
||||
tray.setToolTip("Hydra");
|
||||
tray.setContextMenu(contextMenu);
|
||||
|
||||
if (process.platform === "win32" || process.platform === "linux") {
|
||||
tray.addListener("click", () => {
|
||||
@ -117,6 +159,11 @@ export class WindowManager {
|
||||
|
||||
this.createMainWindow();
|
||||
});
|
||||
|
||||
tray.addListener("right-click", async () => {
|
||||
const contextMenu = await updateSystemTray();
|
||||
tray.popUpContextMenu(contextMenu);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ export function Modal({
|
||||
}, [onClose]);
|
||||
|
||||
const isTopMostModal = () => {
|
||||
const openModals = document.querySelectorAll("[role=modal]");
|
||||
const openModals = document.querySelectorAll("[role=dialog]");
|
||||
|
||||
return (
|
||||
openModals.length &&
|
||||
|
@ -33,7 +33,7 @@ export function HeroPanelPlaytime({
|
||||
|
||||
const numberFormatter = useMemo(() => {
|
||||
return new Intl.NumberFormat(i18n.language, {
|
||||
maximumFractionDigits: 1,
|
||||
maximumFractionDigits: 0,
|
||||
});
|
||||
}, [i18n.language]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user