mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-18 08:43:57 +00:00
Merge branch 'main' into feat/add-wine-lutris-integration
This commit is contained in:
@@ -88,9 +88,6 @@
|
||||
"delete": "Remove all files"
|
||||
},
|
||||
"settings": {
|
||||
"error_title_modal": "Error",
|
||||
"error_modal_download": "Your selected folder does not have write permissions or does not exist, please check the folder in your \"Settings\" tab",
|
||||
"error_description_modal": "The selected directory does not have write permissions or does not exist, please choose another folder",
|
||||
"downloads_path": "Downloads path",
|
||||
"change": "Update",
|
||||
"notifications": "Notifications",
|
||||
|
||||
@@ -88,9 +88,6 @@
|
||||
"delete": "Apagar arquivos"
|
||||
},
|
||||
"settings": {
|
||||
"error_title_modal": "Erro",
|
||||
"error_modal_download": "Você selecionou uma pasta que não tem permissão de escrita ou não existe, por favor verifique na área \"Configurações\"",
|
||||
"error_description_modal": "O diretório selecionado não possui permissão de escrita ou não existe, favor selecione outra pasta",
|
||||
"downloads_path": "Diretório dos downloads",
|
||||
"change": "Mudar",
|
||||
"notifications": "Notificações",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { formatName, repackerFormatter } from "@main/helpers";
|
||||
import { formatName, getSteamAppAsset, repackerFormatter } from "@main/helpers";
|
||||
import { getTrendingGames } from "@main/services";
|
||||
import type { CatalogueCategory, CatalogueEntry } from "@types";
|
||||
import type { CatalogueCategory, CatalogueEntry, GameShop } from "@types";
|
||||
|
||||
import { stateManager } from "@main/state-manager";
|
||||
import { searchGames } from "../helpers/search-games";
|
||||
import { searchGames, searchRepacks } from "../helpers/search-games";
|
||||
import { registerEvent } from "../register-event";
|
||||
|
||||
const repacks = stateManager.getValue("repacks");
|
||||
@@ -12,14 +12,7 @@ const getCatalogue = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
category: CatalogueCategory
|
||||
) => {
|
||||
const trendingGames = await getTrendingGames();
|
||||
|
||||
let i = 0;
|
||||
const results: CatalogueEntry[] = [];
|
||||
|
||||
const getStringForLookup = (index: number) => {
|
||||
if (category === "trending") return trendingGames[index];
|
||||
|
||||
const repack = repacks[index];
|
||||
const formatter =
|
||||
repackerFormatter[repack.repacker as keyof typeof repackerFormatter];
|
||||
@@ -30,10 +23,56 @@ const getCatalogue = async (
|
||||
if (!repacks.length) return [];
|
||||
|
||||
const resultSize = 12;
|
||||
const requestSize = resultSize * 2;
|
||||
let lookupRequest = [];
|
||||
const requestSize = resultSize;
|
||||
|
||||
while (results.length < resultSize) {
|
||||
if (category === "trending") {
|
||||
return searchTrending(resultSize);
|
||||
} else {
|
||||
return searchRecentlyAdded(resultSize, requestSize, getStringForLookup);
|
||||
}
|
||||
};
|
||||
|
||||
const searchTrending = async (
|
||||
resultSize: number
|
||||
): Promise<CatalogueEntry[]> => {
|
||||
const results: CatalogueEntry[] = [];
|
||||
const trendingGames = await getTrendingGames();
|
||||
for (
|
||||
let i = 0;
|
||||
i < trendingGames.length && results.length < resultSize;
|
||||
i++
|
||||
) {
|
||||
if (!trendingGames[i]) continue;
|
||||
|
||||
const { title, objectID } = trendingGames[i];
|
||||
const repacks = searchRepacks(title);
|
||||
|
||||
if (title && repacks.length) {
|
||||
const catalogueEntry = {
|
||||
objectID,
|
||||
title,
|
||||
shop: "steam" as GameShop,
|
||||
cover: getSteamAppAsset("library", objectID),
|
||||
};
|
||||
repacks.sort(
|
||||
(a, b) =>
|
||||
new Date(a.updatedAt).getTime() - new Date(b.updatedAt).getTime()
|
||||
);
|
||||
results.push({ ...catalogueEntry, repacks });
|
||||
}
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
const searchRecentlyAdded = async (
|
||||
resultSize: number,
|
||||
requestSize: number,
|
||||
getStringForLookup: { (index: number): any; (arg0: any): any }
|
||||
): Promise<CatalogueEntry[]> => {
|
||||
let lookupRequest = [];
|
||||
const results: CatalogueEntry[] = [];
|
||||
|
||||
for (let i = 0; results.length < resultSize; i++) {
|
||||
const stringForLookup = getStringForLookup(i);
|
||||
|
||||
if (!stringForLookup) {
|
||||
@@ -43,8 +82,6 @@ const getCatalogue = async (
|
||||
|
||||
lookupRequest.push(searchGames(stringForLookup));
|
||||
|
||||
i++;
|
||||
|
||||
if (lookupRequest.length < requestSize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,6 @@ import type { GameShop } from "@types";
|
||||
import { getDownloadsPath } from "../helpers/get-downloads-path";
|
||||
import { getImageBase64 } from "@main/helpers";
|
||||
import { In } from "typeorm";
|
||||
import validatePath from "../helpers/validate-path";
|
||||
import { dialog } from "electron";
|
||||
import { t } from "i18next";
|
||||
|
||||
const startGameDownload = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
@@ -41,20 +38,6 @@ const startGameDownload = async (
|
||||
writePipe.write({ action: "pause" });
|
||||
|
||||
const downloadsPath = game?.downloadPath ?? (await getDownloadsPath());
|
||||
const error = validatePath(downloadsPath);
|
||||
if (error) {
|
||||
dialog.showErrorBox(
|
||||
t("error_title_modal", {
|
||||
ns: "settings",
|
||||
lng: "en",
|
||||
}),
|
||||
`${t("error_modal_download", {
|
||||
ns: "settings",
|
||||
lng: "en",
|
||||
})}${error instanceof Error ? "\n" + error.message : ""}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await gameRepository.update(
|
||||
{
|
||||
|
||||
@@ -1,44 +1,19 @@
|
||||
import { userPreferencesRepository } from "@main/repository";
|
||||
import { registerEvent } from "../register-event";
|
||||
import { dialog } from "electron";
|
||||
import { t } from "i18next";
|
||||
|
||||
import type { UserPreferences } from "@types";
|
||||
import validatePath from "../helpers/validate-path";
|
||||
|
||||
const updateUserPreferences = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
preferences: Partial<UserPreferences>
|
||||
) => {
|
||||
const payload = async () =>
|
||||
await userPreferencesRepository.upsert(
|
||||
{
|
||||
id: 1,
|
||||
...preferences,
|
||||
},
|
||||
["id"]
|
||||
);
|
||||
|
||||
if (preferences.downloadsPath) {
|
||||
const error = validatePath(preferences.downloadsPath);
|
||||
|
||||
if (!error) {
|
||||
payload();
|
||||
return true;
|
||||
}
|
||||
dialog.showErrorBox(
|
||||
t("error_title_modal", {
|
||||
ns: "settings",
|
||||
lng: "en",
|
||||
}),
|
||||
`${t("error_description_modal", {
|
||||
ns: "settings",
|
||||
lng: "en",
|
||||
})}${error instanceof Error ? "\n" + error.message : ""}`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
payload();
|
||||
return true;
|
||||
await userPreferencesRepository.upsert(
|
||||
{
|
||||
id: 1,
|
||||
...preferences,
|
||||
},
|
||||
["id"]
|
||||
);
|
||||
};
|
||||
|
||||
registerEvent(updateUserPreferences, {
|
||||
|
||||
@@ -19,7 +19,14 @@ export const getTrendingGames = async () => {
|
||||
const { document } = window;
|
||||
|
||||
return Array.from(document.querySelectorAll(".appline .title a")).map(
|
||||
($title) => $title.textContent!
|
||||
($title: HTMLAnchorElement) => {
|
||||
const steamGameUrld = $title.href;
|
||||
if (!steamGameUrld) return null;
|
||||
return {
|
||||
title: $title.textContent,
|
||||
objectID: steamGameUrld.split("/").pop(),
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
2
src/renderer/declaration.d.ts
vendored
2
src/renderer/declaration.d.ts
vendored
@@ -52,7 +52,7 @@ declare global {
|
||||
getUserPreferences: () => Promise<UserPreferences | null>;
|
||||
updateUserPreferences: (
|
||||
preferences: Partial<UserPreferences>
|
||||
) => Promise<boolean>;
|
||||
) => Promise<void>;
|
||||
|
||||
/* Hardware */
|
||||
getDiskFreeSpace: () => Promise<DiskSpace>;
|
||||
|
||||
@@ -29,14 +29,15 @@ export function Settings() {
|
||||
});
|
||||
}, []);
|
||||
|
||||
const updateUserPreferences = async <T extends keyof UserPreferences>(
|
||||
const updateUserPreferences = <T extends keyof UserPreferences>(
|
||||
field: T,
|
||||
value: UserPreferences[T]
|
||||
) => {
|
||||
const payload = await window.electron.updateUserPreferences({
|
||||
setForm((prev) => ({ ...prev, [field]: value }));
|
||||
|
||||
window.electron.updateUserPreferences({
|
||||
[field]: value,
|
||||
});
|
||||
setForm((prev) => (payload ? { ...prev, [field]: value } : prev));
|
||||
};
|
||||
|
||||
const handleChooseDownloadsPath = async () => {
|
||||
|
||||
Reference in New Issue
Block a user