mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 13:34:54 +03:00
Merge pull request #1282 from hydralauncher/fix/intercepting-cookies
Fix/intercepting cookies
This commit is contained in:
commit
7e44b3dedb
@ -167,7 +167,8 @@
|
|||||||
"manage_files_description": "Manage which files will be backed up and restored",
|
"manage_files_description": "Manage which files will be backed up and restored",
|
||||||
"select_folder": "Select folder",
|
"select_folder": "Select folder",
|
||||||
"backup_from": "Backup from {{date}}",
|
"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": {
|
"activation": {
|
||||||
"title": "Activate Hydra",
|
"title": "Activate Hydra",
|
||||||
|
@ -100,7 +100,7 @@
|
|||||||
"open_screenshot": "Abrir captura {{number}}",
|
"open_screenshot": "Abrir captura {{number}}",
|
||||||
"download_settings": "Ajustes de descarga",
|
"download_settings": "Ajustes de descarga",
|
||||||
"downloader": "Método de descarga",
|
"downloader": "Método de descarga",
|
||||||
"select_executable": "Seleccionar ejecutable",
|
"select_executable": "Seleccionar",
|
||||||
"no_executable_selected": "No se seleccionó un ejecutable",
|
"no_executable_selected": "No se seleccionó un ejecutable",
|
||||||
"open_folder": "Abrir carpeta",
|
"open_folder": "Abrir carpeta",
|
||||||
"open_download_location": "Ver archivos descargados",
|
"open_download_location": "Ver archivos descargados",
|
||||||
@ -166,7 +166,9 @@
|
|||||||
"manage_files_description": "Gestiona los archivos que serán respaldados y restaurados",
|
"manage_files_description": "Gestiona los archivos que serán respaldados y restaurados",
|
||||||
"select_folder": "Seleccionar carpeta",
|
"select_folder": "Seleccionar carpeta",
|
||||||
"backup_from": "Copia de seguridad de {{date}}",
|
"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": {
|
"activation": {
|
||||||
"title": "Activar Hydra",
|
"title": "Activar Hydra",
|
||||||
|
@ -162,7 +162,9 @@
|
|||||||
"backup_from": "Backup de {{date}}",
|
"backup_from": "Backup de {{date}}",
|
||||||
"custom_backup_location_set": "Localização customizada selecionada",
|
"custom_backup_location_set": "Localização customizada selecionada",
|
||||||
"select_folder": "Selecione a pasta",
|
"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": {
|
"activation": {
|
||||||
"title": "Ativação",
|
"title": "Ativação",
|
||||||
|
@ -5,9 +5,9 @@ import { registerEvent } from "../register-event";
|
|||||||
const selectGameWinePrefix = async (
|
const selectGameWinePrefix = async (
|
||||||
_event: Electron.IpcMainInvokeEvent,
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
id: number,
|
id: number,
|
||||||
winePrefixPath: string
|
winePrefixPath: string | null
|
||||||
) => {
|
) => {
|
||||||
return gameRepository.update({ id }, { winePrefixPath });
|
return gameRepository.update({ id }, { winePrefixPath: winePrefixPath });
|
||||||
};
|
};
|
||||||
|
|
||||||
registerEvent("selectGameWinePrefix", selectGameWinePrefix);
|
registerEvent("selectGameWinePrefix", selectGameWinePrefix);
|
||||||
|
@ -6,14 +6,18 @@ import { parseExecutablePath } from "../helpers/parse-executable-path";
|
|||||||
const updateExecutablePath = async (
|
const updateExecutablePath = async (
|
||||||
_event: Electron.IpcMainInvokeEvent,
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
id: number,
|
id: number,
|
||||||
executablePath: string
|
executablePath: string | null
|
||||||
) => {
|
) => {
|
||||||
|
const parsedPath = executablePath
|
||||||
|
? parseExecutablePath(executablePath)
|
||||||
|
: null;
|
||||||
|
|
||||||
return gameRepository.update(
|
return gameRepository.update(
|
||||||
{
|
{
|
||||||
id,
|
id,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
executablePath: parseExecutablePath(executablePath),
|
executablePath: parsedPath,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -87,9 +87,9 @@ contextBridge.exposeInMainWorld("electron", {
|
|||||||
ipcRenderer.invoke("addGameToLibrary", objectId, title, shop),
|
ipcRenderer.invoke("addGameToLibrary", objectId, title, shop),
|
||||||
createGameShortcut: (id: number) =>
|
createGameShortcut: (id: number) =>
|
||||||
ipcRenderer.invoke("createGameShortcut", id),
|
ipcRenderer.invoke("createGameShortcut", id),
|
||||||
updateExecutablePath: (id: number, executablePath: string) =>
|
updateExecutablePath: (id: number, executablePath: string | null) =>
|
||||||
ipcRenderer.invoke("updateExecutablePath", id, executablePath),
|
ipcRenderer.invoke("updateExecutablePath", id, executablePath),
|
||||||
selectGameWinePrefix: (id: number, winePrefixPath: string) =>
|
selectGameWinePrefix: (id: number, winePrefixPath: string | null) =>
|
||||||
ipcRenderer.invoke("selectGameWinePrefix", id, winePrefixPath),
|
ipcRenderer.invoke("selectGameWinePrefix", id, winePrefixPath),
|
||||||
verifyExecutablePathInUse: (executablePath: string) =>
|
verifyExecutablePathInUse: (executablePath: string) =>
|
||||||
ipcRenderer.invoke("verifyExecutablePathInUse", executablePath),
|
ipcRenderer.invoke("verifyExecutablePathInUse", executablePath),
|
||||||
|
44
src/renderer/src/cookies.ts
Normal file
44
src/renderer/src/cookies.ts
Normal file
@ -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;
|
||||||
|
};
|
10
src/renderer/src/declaration.d.ts
vendored
10
src/renderer/src/declaration.d.ts
vendored
@ -80,8 +80,14 @@ declare global {
|
|||||||
shop: GameShop
|
shop: GameShop
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
createGameShortcut: (id: number) => Promise<boolean>;
|
createGameShortcut: (id: number) => Promise<boolean>;
|
||||||
updateExecutablePath: (id: number, executablePath: string) => Promise<void>;
|
updateExecutablePath: (
|
||||||
selectGameWinePrefix: (id: number, winePrefixPath: string) => Promise<void>;
|
id: number,
|
||||||
|
executablePath: string | null
|
||||||
|
) => Promise<void>;
|
||||||
|
selectGameWinePrefix: (
|
||||||
|
id: number,
|
||||||
|
winePrefixPath: string | null
|
||||||
|
) => Promise<void>;
|
||||||
verifyExecutablePathInUse: (executablePath: string) => Promise<Game>;
|
verifyExecutablePathInUse: (executablePath: string) => Promise<Game>;
|
||||||
getLibrary: () => Promise<LibraryGame[]>;
|
getLibrary: () => Promise<LibraryGame[]>;
|
||||||
openGameInstaller: (gameId: number) => Promise<boolean>;
|
openGameInstaller: (gameId: number) => Promise<boolean>;
|
||||||
|
@ -21,6 +21,7 @@ import resources from "@locales";
|
|||||||
import { RepacksContextProvider } from "./context";
|
import { RepacksContextProvider } from "./context";
|
||||||
import { SuspenseWrapper } from "./components";
|
import { SuspenseWrapper } from "./components";
|
||||||
import { logger } from "./logger";
|
import { logger } from "./logger";
|
||||||
|
import { addCookieInterceptor } from "./cookies";
|
||||||
|
|
||||||
const Home = React.lazy(() => import("./pages/home/home"));
|
const Home = React.lazy(() => import("./pages/home/home"));
|
||||||
const GameDetails = React.lazy(
|
const GameDetails = React.lazy(
|
||||||
@ -37,6 +38,8 @@ const Achievements = React.lazy(
|
|||||||
|
|
||||||
console.log = logger.log;
|
console.log = logger.log;
|
||||||
|
|
||||||
|
addCookieInterceptor();
|
||||||
|
|
||||||
i18n
|
i18n
|
||||||
.use(LanguageDetector)
|
.use(LanguageDetector)
|
||||||
.use(initReactI18next)
|
.use(initReactI18next)
|
||||||
|
@ -96,7 +96,7 @@ export function GameOptionsModal({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleClearExecutablePath = async () => {
|
const handleClearExecutablePath = async () => {
|
||||||
await window.electron.updateExecutablePath(game.id, "");
|
await window.electron.updateExecutablePath(game.id, null);
|
||||||
updateGame();
|
updateGame();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ export function GameOptionsModal({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleClearWinePrefixPath = async () => {
|
const handleClearWinePrefixPath = async () => {
|
||||||
await window.electron.selectGameWinePrefix(game.id, "");
|
await window.electron.selectGameWinePrefix(game.id, null);
|
||||||
updateGame();
|
updateGame();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -155,6 +155,7 @@ export function GameOptionsModal({
|
|||||||
disabled
|
disabled
|
||||||
placeholder={t("no_executable_selected")}
|
placeholder={t("no_executable_selected")}
|
||||||
rightContent={
|
rightContent={
|
||||||
|
<>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
theme="outline"
|
theme="outline"
|
||||||
@ -163,6 +164,12 @@ export function GameOptionsModal({
|
|||||||
<FileIcon />
|
<FileIcon />
|
||||||
{t("select_executable")}
|
{t("select_executable")}
|
||||||
</Button>
|
</Button>
|
||||||
|
{game.executablePath && (
|
||||||
|
<Button onClick={handleClearExecutablePath} theme="outline">
|
||||||
|
{t("clear")}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -178,9 +185,6 @@ export function GameOptionsModal({
|
|||||||
<Button onClick={handleCreateShortcut} theme="outline">
|
<Button onClick={handleCreateShortcut} theme="outline">
|
||||||
{t("create_shortcut")}
|
{t("create_shortcut")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={handleClearExecutablePath} theme="outline">
|
|
||||||
{t("clear")}
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@ -199,6 +203,7 @@ export function GameOptionsModal({
|
|||||||
disabled
|
disabled
|
||||||
placeholder={t("no_directory_selected")}
|
placeholder={t("no_directory_selected")}
|
||||||
rightContent={
|
rightContent={
|
||||||
|
<>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
theme="outline"
|
theme="outline"
|
||||||
@ -207,15 +212,17 @@ export function GameOptionsModal({
|
|||||||
<FileDirectoryIcon />
|
<FileDirectoryIcon />
|
||||||
{t("select_executable")}
|
{t("select_executable")}
|
||||||
</Button>
|
</Button>
|
||||||
}
|
|
||||||
/>
|
|
||||||
{game.winePrefixPath && (
|
{game.winePrefixPath && (
|
||||||
<div className={styles.gameOptionRow}>
|
<Button
|
||||||
<Button onClick={handleClearWinePrefixPath} theme="outline">
|
onClick={handleClearWinePrefixPath}
|
||||||
|
theme="outline"
|
||||||
|
>
|
||||||
{t("clear")}
|
{t("clear")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user