diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index a762d655f..940e3185b 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -167,7 +167,8 @@ "manage_files_description": "Manage which files will be backed up and restored", "select_folder": "Select folder", "backup_from": "Backup from {{date}}", - "custom_backup_location_set": "Custom backup location set" + "custom_backup_location_set": "Custom backup location set", + "no_directory_selected": "No directory selected" }, "activation": { "title": "Activate Hydra", diff --git a/src/locales/es/translation.json b/src/locales/es/translation.json index 2679a9fd8..ab34be1f8 100644 --- a/src/locales/es/translation.json +++ b/src/locales/es/translation.json @@ -100,7 +100,7 @@ "open_screenshot": "Abrir captura {{number}}", "download_settings": "Ajustes de descarga", "downloader": "Método de descarga", - "select_executable": "Seleccionar ejecutable", + "select_executable": "Seleccionar", "no_executable_selected": "No se seleccionó un ejecutable", "open_folder": "Abrir carpeta", "open_download_location": "Ver archivos descargados", @@ -166,7 +166,9 @@ "manage_files_description": "Gestiona los archivos que serán respaldados y restaurados", "select_folder": "Seleccionar carpeta", "backup_from": "Copia de seguridad de {{date}}", - "custom_backup_location_set": "Se configuró la carpeta de copia de seguridad" + "custom_backup_location_set": "Se configuró la carpeta de copia de seguridad", + "clear": "Limpiar", + "no_directory_selected": "No se seleccionó un directório" }, "activation": { "title": "Activar Hydra", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index 43c18a480..e724cdc37 100644 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -162,7 +162,9 @@ "backup_from": "Backup de {{date}}", "custom_backup_location_set": "Localização customizada selecionada", "select_folder": "Selecione a pasta", - "manage_files_description": "Gerencie quais arquivos serão feitos backup" + "manage_files_description": "Gerencie quais arquivos serão feitos backup", + "clear": "Limpar", + "no_directory_selected": "Nenhum diretório selecionado" }, "activation": { "title": "Ativação", diff --git a/src/main/events/library/select-game-wine-prefix.ts b/src/main/events/library/select-game-wine-prefix.ts index a75a3cb0d..d9f01c084 100644 --- a/src/main/events/library/select-game-wine-prefix.ts +++ b/src/main/events/library/select-game-wine-prefix.ts @@ -5,9 +5,9 @@ import { registerEvent } from "../register-event"; const selectGameWinePrefix = async ( _event: Electron.IpcMainInvokeEvent, id: number, - winePrefixPath: string + winePrefixPath: string | null ) => { - return gameRepository.update({ id }, { winePrefixPath }); + return gameRepository.update({ id }, { winePrefixPath: winePrefixPath }); }; registerEvent("selectGameWinePrefix", selectGameWinePrefix); diff --git a/src/main/events/library/update-executable-path.ts b/src/main/events/library/update-executable-path.ts index 9be36ab1d..aee807715 100644 --- a/src/main/events/library/update-executable-path.ts +++ b/src/main/events/library/update-executable-path.ts @@ -6,14 +6,18 @@ import { parseExecutablePath } from "../helpers/parse-executable-path"; const updateExecutablePath = async ( _event: Electron.IpcMainInvokeEvent, id: number, - executablePath: string + executablePath: string | null ) => { + const parsedPath = executablePath + ? parseExecutablePath(executablePath) + : null; + return gameRepository.update( { id, }, { - executablePath: parseExecutablePath(executablePath), + executablePath: parsedPath, } ); }; diff --git a/src/preload/index.ts b/src/preload/index.ts index 3f2f677a2..f9d196448 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -87,9 +87,9 @@ contextBridge.exposeInMainWorld("electron", { ipcRenderer.invoke("addGameToLibrary", objectId, title, shop), createGameShortcut: (id: number) => ipcRenderer.invoke("createGameShortcut", id), - updateExecutablePath: (id: number, executablePath: string) => + updateExecutablePath: (id: number, executablePath: string | null) => ipcRenderer.invoke("updateExecutablePath", id, executablePath), - selectGameWinePrefix: (id: number, winePrefixPath: string) => + selectGameWinePrefix: (id: number, winePrefixPath: string | null) => ipcRenderer.invoke("selectGameWinePrefix", id, winePrefixPath), verifyExecutablePathInUse: (executablePath: string) => ipcRenderer.invoke("verifyExecutablePathInUse", executablePath), diff --git a/src/renderer/src/cookies.ts b/src/renderer/src/cookies.ts new file mode 100644 index 000000000..66d046c3b --- /dev/null +++ b/src/renderer/src/cookies.ts @@ -0,0 +1,44 @@ +export function addCookieInterceptor() { + Object.defineProperty(document, "cookie", { + enumerable: true, + configurable: true, + get() { + return localStorage.getItem("cookies") || ""; + }, + set(cookieString) { + try { + const [cookieName, cookieValue] = cookieString.split(";")[0].split("="); + + const currentCookies = localStorage.getItem("cookies") || ""; + + const cookiesObject = parseCookieStringsToObjects(currentCookies); + cookiesObject[cookieName] = cookieValue; + + const newString = Object.entries(cookiesObject) + .map(([key, value]) => { + return key + "=" + value; + }) + .join("; "); + + localStorage.setItem("cookies", newString); + } catch (err) { + console.error(err); + } + }, + }); +} + +const parseCookieStringsToObjects = ( + cookieStrings: string +): { [key: string]: string } => { + const result = {}; + + if (cookieStrings === "") return result; + + cookieStrings.split(";").forEach((cookieString) => { + const [name, value] = cookieString.split("="); + result[name.trim()] = value.trim(); + }); + + return result; +}; diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 2ffcfab74..93c423e0d 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -80,8 +80,14 @@ declare global { shop: GameShop ) => Promise; createGameShortcut: (id: number) => Promise; - updateExecutablePath: (id: number, executablePath: string) => Promise; - selectGameWinePrefix: (id: number, winePrefixPath: string) => Promise; + updateExecutablePath: ( + id: number, + executablePath: string | null + ) => Promise; + selectGameWinePrefix: ( + id: number, + winePrefixPath: string | null + ) => Promise; verifyExecutablePathInUse: (executablePath: string) => Promise; getLibrary: () => Promise; openGameInstaller: (gameId: number) => Promise; diff --git a/src/renderer/src/main.tsx b/src/renderer/src/main.tsx index 79ca509b3..8f729df9e 100644 --- a/src/renderer/src/main.tsx +++ b/src/renderer/src/main.tsx @@ -21,6 +21,7 @@ import resources from "@locales"; import { RepacksContextProvider } from "./context"; import { SuspenseWrapper } from "./components"; import { logger } from "./logger"; +import { addCookieInterceptor } from "./cookies"; const Home = React.lazy(() => import("./pages/home/home")); const GameDetails = React.lazy( @@ -37,6 +38,8 @@ const Achievements = React.lazy( console.log = logger.log; +addCookieInterceptor(); + i18n .use(LanguageDetector) .use(initReactI18next) diff --git a/src/renderer/src/pages/game-details/modals/game-options-modal.tsx b/src/renderer/src/pages/game-details/modals/game-options-modal.tsx index 614fa4a07..e5c83ec48 100644 --- a/src/renderer/src/pages/game-details/modals/game-options-modal.tsx +++ b/src/renderer/src/pages/game-details/modals/game-options-modal.tsx @@ -96,7 +96,7 @@ export function GameOptionsModal({ }; const handleClearExecutablePath = async () => { - await window.electron.updateExecutablePath(game.id, ""); + await window.electron.updateExecutablePath(game.id, null); updateGame(); }; @@ -112,7 +112,7 @@ export function GameOptionsModal({ }; const handleClearWinePrefixPath = async () => { - await window.electron.selectGameWinePrefix(game.id, ""); + await window.electron.selectGameWinePrefix(game.id, null); updateGame(); }; @@ -155,14 +155,21 @@ export function GameOptionsModal({ disabled placeholder={t("no_executable_selected")} rightContent={ - + <> + + {game.executablePath && ( + + )} + } /> @@ -178,9 +185,6 @@ export function GameOptionsModal({ - )} @@ -199,23 +203,26 @@ export function GameOptionsModal({ disabled placeholder={t("no_directory_selected")} rightContent={ - + <> + + {game.winePrefixPath && ( + + )} + } /> - {game.winePrefixPath && ( -
- -
- )} )}