From e978d84f5f3a76ecd0f963c91fe9148e1b52af82 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:21:20 -0300 Subject: [PATCH 1/3] feat: intercepting cookies --- src/renderer/src/cookies.ts | 52 +++++++++++++++++++++++++++++++++++++ src/renderer/src/main.tsx | 3 +++ 2 files changed, 55 insertions(+) create mode 100644 src/renderer/src/cookies.ts diff --git a/src/renderer/src/cookies.ts b/src/renderer/src/cookies.ts new file mode 100644 index 000000000..b2122d831 --- /dev/null +++ b/src/renderer/src/cookies.ts @@ -0,0 +1,52 @@ +export function addCookieInterceptor() { + Object.defineProperty(document, "cookie", { + enumerable: true, + configurable: true, + get() { + const cookies = localStorage.getItem("cookies") || ""; + console.log("get cookie", cookies); + return cookies; + }, + set(cookieString) { + try { + console.log("setting cookie", cookieString); + const [cookieName, cookieValue] = cookieString.split(";")[0].split("="); + + const currentCookies = localStorage.getItem("cookies") || ""; + + console.log("pre cookies obj", currentCookies); + const cookiesObject = parseCookieStringsToObjects(currentCookies); + cookiesObject[cookieName] = cookieValue; + console.log("cookiesObject", cookiesObject); + + const newString = Object.entries(cookiesObject) + .map(([key, value]) => { + return key + "=" + value; + }) + .join("; "); + + console.log("set cookie", newString); + localStorage.setItem("cookies", newString); + } catch (err) { + console.error(err); + } + }, + }); +} + +const parseCookieStringsToObjects = ( + cookieStrings: string +): { [key: string]: string } => { + const result = {}; + + if (cookieStrings === "") return result; + + console.log(cookieStrings); + cookieStrings.split(";").forEach((cookieString) => { + console.log("forEach", cookieString); + const [name, value] = cookieString.split("="); + result[name.trim()] = value.trim(); + }); + + return result; +}; 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) From 7595f19af389f8a208e09163c486c15be5016dae Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:50:39 -0300 Subject: [PATCH 2/3] feat: remove console log --- src/renderer/src/cookies.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/renderer/src/cookies.ts b/src/renderer/src/cookies.ts index b2122d831..66d046c3b 100644 --- a/src/renderer/src/cookies.ts +++ b/src/renderer/src/cookies.ts @@ -3,21 +3,16 @@ export function addCookieInterceptor() { enumerable: true, configurable: true, get() { - const cookies = localStorage.getItem("cookies") || ""; - console.log("get cookie", cookies); - return cookies; + return localStorage.getItem("cookies") || ""; }, set(cookieString) { try { - console.log("setting cookie", cookieString); const [cookieName, cookieValue] = cookieString.split(";")[0].split("="); const currentCookies = localStorage.getItem("cookies") || ""; - console.log("pre cookies obj", currentCookies); const cookiesObject = parseCookieStringsToObjects(currentCookies); cookiesObject[cookieName] = cookieValue; - console.log("cookiesObject", cookiesObject); const newString = Object.entries(cookiesObject) .map(([key, value]) => { @@ -25,7 +20,6 @@ export function addCookieInterceptor() { }) .join("; "); - console.log("set cookie", newString); localStorage.setItem("cookies", newString); } catch (err) { console.error(err); @@ -41,9 +35,7 @@ const parseCookieStringsToObjects = ( if (cookieStrings === "") return result; - console.log(cookieStrings); cookieStrings.split(";").forEach((cookieString) => { - console.log("forEach", cookieString); const [name, value] = cookieString.split("="); result[name.trim()] = value.trim(); }); From 0dea7004794a2323fd3f7f5b05573798a4d265d0 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:18:37 -0300 Subject: [PATCH 3/3] feat: adjustments on clear button --- src/locales/en/translation.json | 3 +- src/locales/es/translation.json | 6 +- src/locales/pt-BR/translation.json | 4 +- .../events/library/select-game-wine-prefix.ts | 4 +- .../events/library/update-executable-path.ts | 8 ++- src/preload/index.ts | 4 +- src/renderer/src/declaration.d.ts | 10 ++- .../modals/game-options-modal.tsx | 63 ++++++++++--------- 8 files changed, 62 insertions(+), 40 deletions(-) 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/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/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 && ( -
- -
- )} )}