Skip to content

Commit

Permalink
Merge pull request #1367 from hydralauncher/fix/issues
Browse files Browse the repository at this point in the history
fix: issues
  • Loading branch information
zamitto authored Jan 1, 2025
2 parents 297ca5a + 16b50fc commit 59bc23b
Show file tree
Hide file tree
Showing 30 changed files with 199 additions and 106 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hydralauncher",
"version": "3.1.4",
"version": "3.1.5",
"description": "Hydra",
"main": "./out/main/index.js",
"author": "Los Broxas",
Expand Down Expand Up @@ -47,13 +47,13 @@
"auto-launch": "^5.0.6",
"axios": "^1.7.9",
"better-sqlite3": "^11.7.0",
"check-disk-space": "^3.4.0",
"classnames": "^2.5.1",
"color": "^4.2.3",
"color.js": "^1.2.0",
"create-desktop-shortcuts": "^1.11.0",
"date-fns": "^3.6.0",
"dexie": "^4.0.10",
"diskusage": "^1.2.0",
"electron-log": "^5.2.4",
"electron-updater": "^6.3.9",
"file-type": "^19.6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/bg/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"game_details": {
"launch_options": "Опции за стартиране",
"launch_options_description": "Напредналите потребители могат да въведат модификации на своите опции за стартиране",
"launch_options_description": "Напредналите потребители могат да въведат модификации на своите опции за стартиране (экспериментальный)",
"launch_options_placeholder": "Няма зададен параметър",
"open_download_options": "Варианти за изтегляне",
"download_options_zero": "Няма варианти за изтегляне",
Expand Down
5 changes: 3 additions & 2 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"wine_prefix": "Wine Prefix",
"wine_prefix_description": "The Wine prefix used to run this game",
"launch_options": "Launch Options",
"launch_options_description": "Advanced users may choose to enter modifications to their launch options",
"launch_options_description": "Advanced users may choose to enter modifications to their launch options (experimental feature)",
"launch_options_placeholder": "No parameter specified",
"no_download_option_info": "No information available",
"backup_deletion_failed": "Failed to delete backup",
Expand All @@ -178,7 +178,8 @@
"select_folder": "Select folder",
"backup_from": "Backup from {{date}}",
"custom_backup_location_set": "Custom backup location set",
"no_directory_selected": "No directory selected"
"no_directory_selected": "No directory selected",
"no_write_permission": "Cannot download into this directory. Click here to learn more."
},
"activation": {
"title": "Activate Hydra",
Expand Down
5 changes: 3 additions & 2 deletions src/locales/pt-BR/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"wine_prefix": "Prefixo Wine",
"wine_prefix_description": "O prefixo Wine que foi utilizado para instalar o jogo",
"launch_options": "Opções de Inicialização",
"launch_options_description": "Usuários avançados podem adicionar opções de inicialização no jogo",
"launch_options_description": "Usuários avançados podem adicionar opções de inicialização no jogo (experimental)",
"launch_options_placeholder": "Nenhum parâmetro informado",
"no_download_option_info": "Sem informações disponíveis",
"backup_deletion_failed": "Falha ao apagar backup",
Expand All @@ -167,7 +167,8 @@
"select_folder": "Selecione a pasta",
"manage_files_description": "Gerencie quais arquivos serão feitos backup",
"clear": "Limpar",
"no_directory_selected": "Nenhum diretório selecionado"
"no_directory_selected": "Nenhum diretório selecionado",
"no_write_permission": "O download não pode ser feito neste diretório. Clique aqui para saber mais."
},
"activation": {
"title": "Ativação",
Expand Down
2 changes: 2 additions & 0 deletions src/main/events/auth/get-session-hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const getSessionHash = async (_event: Electron.IpcMainInvokeEvent) => {
if (!auth) return null;
const payload = jwt.decode(auth.accessToken) as jwt.JwtPayload;

if (!payload) return null;

return payload.sessionId;
};

Expand Down
6 changes: 5 additions & 1 deletion src/main/events/cloud-save/get-game-artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HydraApi } from "@main/services";
import { registerEvent } from "../register-event";
import type { GameArtifact, GameShop } from "@types";
import { SubscriptionRequiredError } from "@shared";
import { SubscriptionRequiredError, UserNotLoggedInError } from "@shared";

const getGameArtifacts = async (
_event: Electron.IpcMainInvokeEvent,
Expand All @@ -22,6 +22,10 @@ const getGameArtifacts = async (
return [];
}

if (err instanceof UserNotLoggedInError) {
return [];
}

throw err;
});
};
Expand Down
15 changes: 15 additions & 0 deletions src/main/events/hardware/check-folder-write-permission.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from "node:fs";

import { registerEvent } from "../register-event";

const checkFolderWritePermission = async (
_event: Electron.IpcMainInvokeEvent,
path: string
) =>
new Promise((resolve) => {
fs.access(path, fs.constants.W_OK, (err) => {
resolve(!err);
});
});

registerEvent("checkFolderWritePermission", checkFolderWritePermission);
4 changes: 2 additions & 2 deletions src/main/events/hardware/get-disk-free-space.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import checkDiskSpace from "check-disk-space";
import disk from "diskusage";

import { registerEvent } from "../register-event";

const getDiskFreeSpace = async (
_event: Electron.IpcMainInvokeEvent,
path: string
) => checkDiskSpace(path);
) => disk.check(path);

registerEvent("getDiskFreeSpace", getDiskFreeSpace);
9 changes: 0 additions & 9 deletions src/main/events/helpers/parse-launch-options.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/main/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "./catalogue/get-trending-games";
import "./catalogue/get-publishers";
import "./catalogue/get-developers";
import "./hardware/get-disk-free-space";
import "./hardware/check-folder-write-permission";
import "./library/add-game-to-library";
import "./library/create-game-shortcut";
import "./library/close-game";
Expand All @@ -30,6 +31,8 @@ import "./library/select-game-wine-prefix";
import "./misc/open-checkout";
import "./misc/open-external";
import "./misc/show-open-dialog";
import "./misc/get-features";
import "./misc/show-item-in-folder";
import "./torrenting/cancel-game-download";
import "./torrenting/pause-game-download";
import "./torrenting/resume-game-download";
Expand Down Expand Up @@ -71,7 +74,6 @@ import "./cloud-save/delete-game-artifact";
import "./cloud-save/select-game-backup-path";
import "./notifications/publish-new-repacks-notification";
import { isPortableVersion } from "@main/helpers";
import "./misc/show-item-in-folder";

ipcMain.handle("ping", () => "pong");
ipcMain.handle("getVersion", () => appVersion);
Expand Down
12 changes: 2 additions & 10 deletions src/main/events/library/open-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,23 @@ import { gameRepository } from "@main/repository";

import { registerEvent } from "../register-event";
import { shell } from "electron";
import { spawn } from "child_process";
import { parseExecutablePath } from "../helpers/parse-executable-path";
import { parseLaunchOptions } from "../helpers/parse-launch-options";

const openGame = async (
_event: Electron.IpcMainInvokeEvent,
gameId: number,
executablePath: string,
launchOptions: string | null
) => {
// TODO: revisit this for launchOptions
const parsedPath = parseExecutablePath(executablePath);
const parsedParams = parseLaunchOptions(launchOptions);

await gameRepository.update(
{ id: gameId },
{ executablePath: parsedPath, launchOptions }
);

if (process.platform === "linux" || process.platform === "darwin") {
shell.openPath(parsedPath);
}

if (process.platform === "win32") {
spawn(parsedPath, parsedParams, { shell: false, detached: true });
}
shell.openPath(parsedPath);
};

registerEvent("openGame", openGame);
8 changes: 8 additions & 0 deletions src/main/events/misc/get-features.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { registerEvent } from "../register-event";
import { HydraApi } from "@main/services";

const getFeatures = async (_event: Electron.IpcMainInvokeEvent) => {
return HydraApi.get<string[]>("/features", null, { needsAuth: false });
};

registerEvent("getFeatures", getFeatures);
11 changes: 2 additions & 9 deletions src/main/events/misc/open-checkout.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { shell } from "electron";
import { registerEvent } from "../register-event";
import {
userAuthRepository,
userPreferencesRepository,
} from "@main/repository";
import { userAuthRepository } from "@main/repository";
import { HydraApi } from "@main/services";

const openCheckout = async (_event: Electron.IpcMainInvokeEvent) => {
const [userAuth, userPreferences] = await Promise.all([
userAuthRepository.findOne({ where: { id: 1 } }),
userPreferencesRepository.findOne({ where: { id: 1 } }),
]);
const userAuth = await userAuthRepository.findOne({ where: { id: 1 } });

if (!userAuth) {
return;
Expand All @@ -22,7 +16,6 @@ const openCheckout = async (_event: Electron.IpcMainInvokeEvent) => {

const params = new URLSearchParams({
token: paymentToken,
lng: userPreferences?.language || "en",
});

shell.openExternal(
Expand Down
19 changes: 9 additions & 10 deletions src/main/services/window-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export class WindowManager {

this.mainWindow.webContents.session.webRequest.onBeforeSendHeaders(
(details, callback) => {
if (details.webContentsId !== this.mainWindow?.webContents.id) {
if (
details.webContentsId !== this.mainWindow?.webContents.id ||
details.url.includes("chatwoot")
) {
return callback(details);
}

Expand All @@ -81,15 +84,11 @@ export class WindowManager {

this.mainWindow.webContents.session.webRequest.onHeadersReceived(
(details, callback) => {
if (details.webContentsId !== this.mainWindow?.webContents.id) {
return callback(details);
}

if (details.url.includes("featurebase")) {
return callback(details);
}

if (details.url.includes("chatwoot")) {
if (
details.webContentsId !== this.mainWindow?.webContents.id ||
details.url.includes("featurebase") ||
details.url.includes("chatwoot")
) {
return callback(details);
}

Expand Down
3 changes: 3 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ contextBridge.exposeInMainWorld("electron", {
/* Hardware */
getDiskFreeSpace: (path: string) =>
ipcRenderer.invoke("getDiskFreeSpace", path),
checkFolderWritePermission: (path: string) =>
ipcRenderer.invoke("checkFolderWritePermission", path),

/* Cloud save */
uploadSaveGame: (
Expand Down Expand Up @@ -226,6 +228,7 @@ contextBridge.exposeInMainWorld("electron", {
ipcRenderer.invoke("showOpenDialog", options),
showItemInFolder: (path: string) =>
ipcRenderer.invoke("showItemInFolder", path),
getFeatures: () => ipcRenderer.invoke("getFeatures"),
platform: process.platform,

/* Auto update */
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export function Modal({
}, [onClose]);

const isTopMostModal = () => {
if (
document.querySelector(
".featurebase-widget-overlay.featurebase-display-block"
)
)
return false;
const openModals = document.querySelectorAll("[role=dialog]");

return (
Expand Down
8 changes: 2 additions & 6 deletions src/renderer/src/components/text-field/text-field.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useId, useMemo, useState } from "react";
import type { RecipeVariants } from "@vanilla-extract/recipes";
import type { FieldError, FieldErrorsImpl, Merge } from "react-hook-form";
import { EyeClosedIcon, EyeIcon } from "@primer/octicons-react";
import { useTranslation } from "react-i18next";

Expand All @@ -23,7 +22,7 @@ export interface TextFieldProps
HTMLDivElement
>;
rightContent?: React.ReactNode | null;
error?: FieldError | Merge<FieldError, FieldErrorsImpl<any>> | undefined;
error?: string | React.ReactNode;
}

export const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(
Expand Down Expand Up @@ -55,10 +54,7 @@ export const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(
}, [props.type, isPasswordVisible]);

const hintContent = useMemo(() => {
if (error && error.message)
return (
<small className={styles.errorLabel}>{error.message as string}</small>
);
if (error) return <small className={styles.errorLabel}>{error}</small>;

if (hint) return <small>{hint}</small>;
return null;
Expand Down
10 changes: 3 additions & 7 deletions src/renderer/src/context/game-details/game-details.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ export function GameDetailsContextProvider({
abortControllerRef.current = abortController;

window.electron
.getGameShopDetails(
objectId!,
shop as GameShop,
getSteamLanguage(i18n.language)
)
.getGameShopDetails(objectId, shop, getSteamLanguage(i18n.language))
.then((result) => {
if (abortController.signal.aborted) return;

Expand All @@ -140,14 +136,14 @@ export function GameDetailsContextProvider({
setIsLoading(false);
});

window.electron.getGameStats(objectId, shop as GameShop).then((result) => {
window.electron.getGameStats(objectId, shop).then((result) => {
if (abortController.signal.aborted) return;
setStats(result);
});

if (userDetails) {
window.electron
.getUnlockedAchievements(objectId, shop as GameShop)
.getUnlockedAchievements(objectId, shop)
.then((achievements) => {
if (abortController.signal.aborted) return;
setAchievements(achievements);
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/src/declaration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type {
CatalogueSearchPayload,
} from "@types";
import type { AxiosProgressEvent } from "axios";
import type { DiskSpace } from "check-disk-space";
import type disk from "diskusage";

declare global {
declare module "*.svg" {
Expand Down Expand Up @@ -140,7 +140,8 @@ declare global {
) => Promise<{ fingerprint: string }>;

/* Hardware */
getDiskFreeSpace: (path: string) => Promise<DiskSpace>;
getDiskFreeSpace: (path: string) => Promise<disk.DiskUsage>;
checkFolderWritePermission: (path: string) => Promise<boolean>;

/* Cloud save */
uploadSaveGame: (
Expand Down Expand Up @@ -195,6 +196,7 @@ declare global {
options: Electron.OpenDialogOptions
) => Promise<Electron.OpenDialogReturnValue>;
showItemInFolder: (path: string) => Promise<void>;
getFeatures: () => Promise<string[]>;
platform: NodeJS.Platform;

/* Auto update */
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from "./redux";
export * from "./use-user-details";
export * from "./use-format";
export * from "./use-repacks";
export * from "./use-feature";
Loading

0 comments on commit 59bc23b

Please sign in to comment.