mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
Merge branch 'main' into teste-locale2
This commit is contained in:
commit
6ae5f92ba9
14 changed files with 6706 additions and 94 deletions
1
.npmrc
Normal file
1
.npmrc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
engine-strict = true
|
BIN
hydra.db
BIN
hydra.db
Binary file not shown.
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "hydra",
|
"name": "hydra",
|
||||||
"version": "1.2.0",
|
"version": "1.2.2",
|
||||||
"description": "Hydra",
|
"description": "Hydra",
|
||||||
"main": "./out/main/index.js",
|
"main": "./out/main/index.js",
|
||||||
"author": "Los Broxas",
|
"author": "Los Broxas",
|
||||||
|
@ -10,6 +10,10 @@
|
||||||
"url": "https://github.com/hydralauncher/hydra.git"
|
"url": "https://github.com/hydralauncher/hydra.git"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
"engines": {
|
||||||
|
"npm": "please-use-yarn",
|
||||||
|
"yarn": ">= 1.19.1"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"format-check": "prettier --check .",
|
"format-check": "prettier --check .",
|
||||||
|
@ -25,7 +29,8 @@
|
||||||
"build:win": "electron-vite build && electron-builder --win",
|
"build:win": "electron-vite build && electron-builder --win",
|
||||||
"build:mac": "electron-vite build && electron-builder --mac",
|
"build:mac": "electron-vite build && electron-builder --mac",
|
||||||
"build:linux": "electron-vite build && electron-builder --linux",
|
"build:linux": "electron-vite build && electron-builder --linux",
|
||||||
"prepare": "husky"
|
"prepare": "husky",
|
||||||
|
"typeorm:migration-create": "yarn typeorm migration:create"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron-toolkit/preload": "^3.0.0",
|
"@electron-toolkit/preload": "^3.0.0",
|
||||||
|
|
|
@ -17,7 +17,11 @@
|
||||||
"downloading": "{{title}} ({{percentage}} - Pobieranie…)",
|
"downloading": "{{title}} ({{percentage}} - Pobieranie…)",
|
||||||
"filter": "Filtruj biblioteke",
|
"filter": "Filtruj biblioteke",
|
||||||
"follow_us": "Śledź nas",
|
"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": {
|
"header": {
|
||||||
"search": "Szukaj",
|
"search": "Szukaj",
|
||||||
|
@ -66,6 +70,8 @@
|
||||||
"copied_link_to_clipboard": "Skopiowano łącze",
|
"copied_link_to_clipboard": "Skopiowano łącze",
|
||||||
"hours": "godzin",
|
"hours": "godzin",
|
||||||
"minutes": "minut",
|
"minutes": "minut",
|
||||||
|
"amount_hours": "{{amount}} godzin",
|
||||||
|
"amount_minutes": "{{amount}} minut",
|
||||||
"accuracy": "{{accuracy}}% dokładność",
|
"accuracy": "{{accuracy}}% dokładność",
|
||||||
"add_to_library": "Dodaj do biblioteki",
|
"add_to_library": "Dodaj do biblioteki",
|
||||||
"remove_from_library": "Usuń z biblioteki",
|
"remove_from_library": "Usuń z biblioteki",
|
||||||
|
@ -80,9 +86,23 @@
|
||||||
"playing_now": "Granie teraz",
|
"playing_now": "Granie teraz",
|
||||||
"change": "Zmień",
|
"change": "Zmień",
|
||||||
"repacks_modal_description": "Wybierz repack, który chcesz pobrać",
|
"repacks_modal_description": "Wybierz repack, który chcesz pobrać",
|
||||||
"downloads_path": "Ścieżka pobierania",
|
|
||||||
"select_folder_hint": "Aby zmienić domyślny folder, przejdź do",
|
"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": {
|
"activation": {
|
||||||
"title": "Aktywuj Hydra",
|
"title": "Aktywuj Hydra",
|
||||||
|
@ -113,7 +133,9 @@
|
||||||
"remove_from_list": "Usuń",
|
"remove_from_list": "Usuń",
|
||||||
"delete_modal_title": "Czy na pewno?",
|
"delete_modal_title": "Czy na pewno?",
|
||||||
"delete_modal_description": "Spowoduje to usunięcie wszystkich plików instalacyjnych z komputera",
|
"delete_modal_description": "Spowoduje to usunięcie wszystkich plików instalacyjnych z komputera",
|
||||||
"install": "Instaluj"
|
"install": "Instaluj",
|
||||||
|
"real_debrid": "Real Debrid",
|
||||||
|
"torrent": "Torrent"
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"downloads_path": "Ścieżka pobierania",
|
"downloads_path": "Ścieżka pobierania",
|
||||||
|
@ -123,6 +145,15 @@
|
||||||
"enable_repack_list_notifications": "Gdy dodawany jest nowy repack",
|
"enable_repack_list_notifications": "Gdy dodawany jest nowy repack",
|
||||||
"telemetry": "Telemetria",
|
"telemetry": "Telemetria",
|
||||||
"telemetry_description": "Włącz anonimowe statystyki użycia",
|
"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"
|
"language": "Język"
|
||||||
},
|
},
|
||||||
"notifications": {
|
"notifications": {
|
||||||
|
@ -143,5 +174,8 @@
|
||||||
"title": "Programy nie są zainstalowane",
|
"title": "Programy nie są zainstalowane",
|
||||||
"description": "Pliki wykonywalne Wine lub Lutris nie zostały znalezione na twoim systemie",
|
"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"
|
"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 type { SqliteConnectionOptions } from "typeorm/driver/sqlite/SqliteConnectionOptions";
|
||||||
|
|
||||||
import { databasePath } from "./constants";
|
import { databasePath } from "./constants";
|
||||||
|
import migrations from "./migrations";
|
||||||
|
|
||||||
export const createDataSource = (options: Partial<SqliteConnectionOptions>) =>
|
export const createDataSource = (options: Partial<SqliteConnectionOptions>) =>
|
||||||
new DataSource({
|
new DataSource({
|
||||||
|
@ -19,4 +20,6 @@ export const createDataSource = (options: Partial<SqliteConnectionOptions>) =>
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const dataSource = createDataSource({});
|
export const dataSource = createDataSource({
|
||||||
|
migrations: migrations,
|
||||||
|
});
|
||||||
|
|
|
@ -53,6 +53,8 @@ app.whenReady().then(() => {
|
||||||
);
|
);
|
||||||
|
|
||||||
dataSource.initialize().then(async () => {
|
dataSource.initialize().then(async () => {
|
||||||
|
await dataSource.runMigrations();
|
||||||
|
|
||||||
await resolveDatabaseUpdates();
|
await resolveDatabaseUpdates();
|
||||||
|
|
||||||
await import("./main");
|
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 { logger } from "../logger";
|
||||||
import { JSDOM } from "jsdom";
|
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 createWorker from "@main/workers/torrent-parser.worker?nodeWorker";
|
||||||
import { toMagnetURI } from "parse-torrent";
|
import { toMagnetURI } from "parse-torrent";
|
||||||
|
|
||||||
const worker = createWorker({});
|
const worker = createWorker({});
|
||||||
|
|
||||||
import { onlinefixFormatter } from "@main/helpers";
|
|
||||||
import makeFetchCookie from "fetch-cookie";
|
import makeFetchCookie from "fetch-cookie";
|
||||||
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
|
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
|
||||||
import { formatBytes } from "@shared";
|
import { formatBytes } from "@shared";
|
||||||
|
|
||||||
const ONLINE_FIX_URL = "https://online-fix.me/";
|
const ONLINE_FIX_URL = "https://online-fix.me/";
|
||||||
|
|
||||||
|
let totalPages = 1;
|
||||||
|
|
||||||
export const getNewRepacksFromOnlineFix = async (
|
export const getNewRepacksFromOnlineFix = async (
|
||||||
existingRepacks: Repack[] = [],
|
existingRepacks: Repack[] = [],
|
||||||
page = 1,
|
page = 1,
|
||||||
|
@ -74,18 +72,16 @@ export const getNewRepacksFromOnlineFix = async (
|
||||||
|
|
||||||
const repacks: QueryDeepPartialEntity<Repack>[] = [];
|
const repacks: QueryDeepPartialEntity<Repack>[] = [];
|
||||||
const articles = Array.from(document.querySelectorAll(".news"));
|
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 {
|
try {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
articles.map(async (article) => {
|
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");
|
const gameLink = article.querySelector("a")?.getAttribute("href");
|
||||||
if (!gameLink) return;
|
if (!gameLink) return;
|
||||||
|
|
||||||
|
@ -94,32 +90,6 @@ export const getNewRepacksFromOnlineFix = async (
|
||||||
);
|
);
|
||||||
const gameDocument = new JSDOM(gamePage).window.document;
|
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(
|
const torrentButtons = Array.from(
|
||||||
gameDocument.querySelectorAll("a")
|
gameDocument.querySelectorAll("a")
|
||||||
).filter((a) => a.textContent?.includes("Torrent"));
|
).filter((a) => a.textContent?.includes("Torrent"));
|
||||||
|
@ -146,13 +116,17 @@ export const getNewRepacksFromOnlineFix = async (
|
||||||
);
|
);
|
||||||
|
|
||||||
worker.once("message", (torrent) => {
|
worker.once("message", (torrent) => {
|
||||||
|
if (!torrent) return;
|
||||||
|
|
||||||
|
const { name, created } = torrent;
|
||||||
|
|
||||||
repacks.push({
|
repacks.push({
|
||||||
fileSize: formatBytes(torrent.length ?? 0),
|
fileSize: formatBytes(torrent.length ?? 0),
|
||||||
magnet: toMagnetURI(torrent),
|
magnet: toMagnetURI(torrent),
|
||||||
page: 1,
|
page: 1,
|
||||||
repacker: "onlinefix",
|
repacker: "onlinefix",
|
||||||
title: gameName,
|
title: name,
|
||||||
uploadDate: uploadDate,
|
uploadDate: created,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,9 @@ import { formatBytes } from "@shared";
|
||||||
import { getFileBuffer } from "@main/helpers";
|
import { getFileBuffer } from "@main/helpers";
|
||||||
|
|
||||||
const worker = createWorker({});
|
const worker = createWorker({});
|
||||||
|
worker.setMaxListeners(11);
|
||||||
|
|
||||||
|
let totalPages = 1;
|
||||||
|
|
||||||
const formatXatabDate = (str: string) => {
|
const formatXatabDate = (str: string) => {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
|
@ -69,27 +72,37 @@ export const getNewRepacksFromXatab = async (
|
||||||
|
|
||||||
const repacks: QueryDeepPartialEntity<Repack>[] = [];
|
const repacks: QueryDeepPartialEntity<Repack>[] = [];
|
||||||
|
|
||||||
for (const $a of Array.from(
|
if (page === 1) {
|
||||||
window.document.querySelectorAll(".entry__title a")
|
totalPages = Number(
|
||||||
)) {
|
window.document.querySelector(
|
||||||
try {
|
"#bottom-nav > div.pagination > a:nth-child(12)"
|
||||||
const repack = await getXatabRepack(($a as HTMLAnchorElement).href);
|
)?.textContent
|
||||||
|
);
|
||||||
if (repack) {
|
|
||||||
repacks.push({
|
|
||||||
title: $a.textContent!,
|
|
||||||
repacker: "Xatab",
|
|
||||||
...repack,
|
|
||||||
page,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (err: unknown) {
|
|
||||||
logger.error((err as Error).message, {
|
|
||||||
method: "getNewRepacksFromXatab",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(
|
const newRepacks = repacks.filter(
|
||||||
(repack) =>
|
(repack) =>
|
||||||
!existingRepacks.some(
|
!existingRepacks.some(
|
||||||
|
@ -98,6 +111,7 @@ export const getNewRepacksFromXatab = async (
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!newRepacks.length) return;
|
if (!newRepacks.length) return;
|
||||||
|
if (page === totalPages) return;
|
||||||
|
|
||||||
await savePage(newRepacks);
|
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 { is } from "@electron-toolkit/utils";
|
||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import icon from "@resources/icon.png?asset";
|
import icon from "@resources/icon.png?asset";
|
||||||
import trayIcon from "@resources/tray-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 {
|
export class WindowManager {
|
||||||
public static mainWindow: Electron.BrowserWindow | null = null;
|
public static mainWindow: Electron.BrowserWindow | null = null;
|
||||||
|
@ -77,33 +86,66 @@ export class WindowManager {
|
||||||
public static createSystemTray(language: string) {
|
public static createSystemTray(language: string) {
|
||||||
const tray = new Tray(trayIcon);
|
const tray = new Tray(trayIcon);
|
||||||
|
|
||||||
const contextMenu = Menu.buildFromTemplate([
|
const updateSystemTray = async () => {
|
||||||
{
|
const games = await gameRepository.find({
|
||||||
label: t("open", {
|
where: {
|
||||||
ns: "system_tray",
|
isDeleted: false,
|
||||||
lng: language,
|
executablePath: Not(IsNull()),
|
||||||
}),
|
lastTimePlayed: Not(IsNull()),
|
||||||
type: "normal",
|
|
||||||
click: () => {
|
|
||||||
if (this.mainWindow) {
|
|
||||||
this.mainWindow.show();
|
|
||||||
} else {
|
|
||||||
this.createMainWindow();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
take: 5,
|
||||||
{
|
order: {
|
||||||
label: t("quit", {
|
updatedAt: "DESC",
|
||||||
ns: "system_tray",
|
},
|
||||||
lng: language,
|
});
|
||||||
}),
|
|
||||||
type: "normal",
|
const recentlyPlayedGames: Array<MenuItemConstructorOptions | MenuItem> =
|
||||||
click: () => app.quit(),
|
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.setToolTip("Hydra");
|
||||||
tray.setContextMenu(contextMenu);
|
|
||||||
|
|
||||||
if (process.platform === "win32" || process.platform === "linux") {
|
if (process.platform === "win32" || process.platform === "linux") {
|
||||||
tray.addListener("click", () => {
|
tray.addListener("click", () => {
|
||||||
|
@ -117,6 +159,11 @@ export class WindowManager {
|
||||||
|
|
||||||
this.createMainWindow();
|
this.createMainWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tray.addListener("right-click", async () => {
|
||||||
|
const contextMenu = await updateSystemTray();
|
||||||
|
tray.popUpContextMenu(contextMenu);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ export function Modal({
|
||||||
}, [onClose]);
|
}, [onClose]);
|
||||||
|
|
||||||
const isTopMostModal = () => {
|
const isTopMostModal = () => {
|
||||||
const openModals = document.querySelectorAll("[role=modal]");
|
const openModals = document.querySelectorAll("[role=dialog]");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
openModals.length &&
|
openModals.length &&
|
||||||
|
|
|
@ -33,7 +33,7 @@ export function HeroPanelPlaytime({
|
||||||
|
|
||||||
const numberFormatter = useMemo(() => {
|
const numberFormatter = useMemo(() => {
|
||||||
return new Intl.NumberFormat(i18n.language, {
|
return new Intl.NumberFormat(i18n.language, {
|
||||||
maximumFractionDigits: 1,
|
maximumFractionDigits: 0,
|
||||||
});
|
});
|
||||||
}, [i18n.language]);
|
}, [i18n.language]);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue