From 48f9468c6d2128186fddf058dc97a496e140ea37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lidwin?= Date: Thu, 15 Feb 2024 15:45:12 +0100 Subject: [PATCH 1/5] fix: fallback to normal gog url when adtraction is blocked --- src/common/types.ts | 17 ++++++++++++++++- src/frontend/screens/WebView/index.tsx | 19 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/common/types.ts b/src/common/types.ts index a71b654fec..fd47a61689 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -8,7 +8,12 @@ import { GameMetadataInner, LegendaryInstallInfo } from './types/legendary' -import { IpcRendererEvent, TitleBarOverlay } from 'electron' +import { + IpcRendererEvent, + TitleBarOverlay, + UploadFile, + UploadRawData +} from 'electron' import { ChildProcess } from 'child_process' import type { HowLongToBeatEntry } from 'backend/wiki_game_info/howlongtobeat/utils' import { NileInstallInfo, NileInstallPlatform } from './types/nile' @@ -542,6 +547,16 @@ type ElWebview = { reload: () => void isLoading: () => boolean getURL: () => string + loadURL: ( + url: string, + options?: { + httpReferer?: string + userAgent?: string + extraHeaders?: string + postData?: (UploadRawData | UploadFile)[] + baseURLForDataURL?: string + } + ) => Promise copy: () => string selectAll: () => void findInPage: (text: string | RegExp) => void diff --git a/src/frontend/screens/WebView/index.tsx b/src/frontend/screens/WebView/index.tsx index 594700ec1c..5f043d0c69 100644 --- a/src/frontend/screens/WebView/index.tsx +++ b/src/frontend/screens/WebView/index.tsx @@ -217,8 +217,24 @@ export default function WebView({ store }: Props) { } } - webview.addEventListener('dom-ready', loadstop) + const onerror = (error: any) => { + const { errorCode, validatedURL } = error + // Connection refused + if ( + errorCode === -102 && + validatedURL && + validatedURL.match(/track\.adtraction\.com/) + ) { + const parsedUrl = new URL(validatedURL) + const redirectUrl = parsedUrl.searchParams.get('url') + if (redirectUrl) { + webview.loadURL(redirectUrl) + } + } + } + webview.addEventListener('dom-ready', loadstop) + webview.addEventListener('did-fail-load', onerror) // if the page title changed it's because the store loaded so there's // connectivity, we can update the status without waiting for the checks const updateConnectivity = () => { @@ -231,6 +247,7 @@ export default function WebView({ store }: Props) { return () => { webview.removeEventListener('ipc-message', onIpcMessage) webview.removeEventListener('dom-ready', loadstop) + webview.removeEventListener('did-fail-load', onerror) webview.removeEventListener('page-title-updated', updateConnectivity) } } From 66223722b7ab00c77990dd2c77ea62a9d844ba0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lidwin?= Date: Thu, 15 Feb 2024 16:28:13 +0100 Subject: [PATCH 2/5] fix: typing --- src/common/types.ts | 32 +------------------ .../components/UI/WebviewControls/index.tsx | 3 +- src/frontend/screens/WebView/index.tsx | 6 ++-- 3 files changed, 5 insertions(+), 36 deletions(-) diff --git a/src/common/types.ts b/src/common/types.ts index fd47a61689..6fba95bea7 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -8,12 +8,7 @@ import { GameMetadataInner, LegendaryInstallInfo } from './types/legendary' -import { - IpcRendererEvent, - TitleBarOverlay, - UploadFile, - UploadRawData -} from 'electron' +import { IpcRendererEvent, TitleBarOverlay } from 'electron' import { ChildProcess } from 'child_process' import type { HowLongToBeatEntry } from 'backend/wiki_game_info/howlongtobeat/utils' import { NileInstallInfo, NileInstallPlatform } from './types/nile' @@ -539,31 +534,6 @@ interface GamepadActionArgsWithoutMetadata { metadata?: undefined } -type ElWebview = { - canGoBack: () => boolean - canGoForward: () => boolean - goBack: () => void - goForward: () => void - reload: () => void - isLoading: () => boolean - getURL: () => string - loadURL: ( - url: string, - options?: { - httpReferer?: string - userAgent?: string - extraHeaders?: string - postData?: (UploadRawData | UploadFile)[] - baseURLForDataURL?: string - } - ) => Promise - copy: () => string - selectAll: () => void - findInPage: (text: string | RegExp) => void -} - -export type WebviewType = HTMLWebViewElement & ElWebview - export type InstallPlatform = | LegendaryInstallPlatform | GogInstallPlatform diff --git a/src/frontend/components/UI/WebviewControls/index.tsx b/src/frontend/components/UI/WebviewControls/index.tsx index 56f3179b42..f29c867991 100644 --- a/src/frontend/components/UI/WebviewControls/index.tsx +++ b/src/frontend/components/UI/WebviewControls/index.tsx @@ -7,12 +7,11 @@ import { import cx from 'classnames' import React, { SyntheticEvent, useCallback, useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' -import { WebviewType } from 'common/types' import SvgButton from '../SvgButton' import './index.css' interface WebviewControlsProps { - webview: WebviewType | null + webview: Electron.WebviewTag | null initURL: string openInBrowser: boolean } diff --git a/src/frontend/screens/WebView/index.tsx b/src/frontend/screens/WebView/index.tsx index 5f043d0c69..fc25832666 100644 --- a/src/frontend/screens/WebView/index.tsx +++ b/src/frontend/screens/WebView/index.tsx @@ -11,7 +11,7 @@ import { useNavigate, useLocation, useParams } from 'react-router' import { UpdateComponent } from 'frontend/components/UI' import WebviewControls from 'frontend/components/UI/WebviewControls' import ContextProvider from 'frontend/state/ContextProvider' -import { Runner, WebviewType } from 'common/types' +import { Runner } from 'common/types' import './index.css' import LoginWarning from '../Login/components/LoginWarning' import { NileLoginData } from 'common/types/nile' @@ -49,7 +49,7 @@ export default function WebView({ store }: Props) { null ) const navigate = useNavigate() - const webviewRef = useRef(null) + const webviewRef = useRef(null) let lang = i18n.language if (i18n.language === 'pt') { @@ -217,7 +217,7 @@ export default function WebView({ store }: Props) { } } - const onerror = (error: any) => { + const onerror = (error: Electron.DidFailLoadEvent) => { const { errorCode, validatedURL } = error // Connection refused if ( From 7c12c9a64566e08e6a7b942b6bd4c51c906a83e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lidwin?= Date: Fri, 16 Feb 2024 22:16:13 +0100 Subject: [PATCH 3/5] match any adtraction error --- src/frontend/screens/WebView/index.tsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/frontend/screens/WebView/index.tsx b/src/frontend/screens/WebView/index.tsx index fc25832666..19597a8fe5 100644 --- a/src/frontend/screens/WebView/index.tsx +++ b/src/frontend/screens/WebView/index.tsx @@ -217,14 +217,9 @@ export default function WebView({ store }: Props) { } } - const onerror = (error: Electron.DidFailLoadEvent) => { - const { errorCode, validatedURL } = error + const onerror = ({ validatedURL }: Electron.DidFailLoadEvent) => { // Connection refused - if ( - errorCode === -102 && - validatedURL && - validatedURL.match(/track\.adtraction\.com/) - ) { + if (validatedURL && validatedURL.match(/track\.adtraction\.com/)) { const parsedUrl = new URL(validatedURL) const redirectUrl = parsedUrl.searchParams.get('url') if (redirectUrl) { From 6e258dc6ba413ebd4b568285a20e7fa45978fdd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lidwin?= Date: Sat, 17 Feb 2024 17:14:28 +0100 Subject: [PATCH 4/5] improv: use gog.com url if redirectUrl is undefined --- src/frontend/screens/WebView/index.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/frontend/screens/WebView/index.tsx b/src/frontend/screens/WebView/index.tsx index 19597a8fe5..fa07981bd4 100644 --- a/src/frontend/screens/WebView/index.tsx +++ b/src/frontend/screens/WebView/index.tsx @@ -222,9 +222,7 @@ export default function WebView({ store }: Props) { if (validatedURL && validatedURL.match(/track\.adtraction\.com/)) { const parsedUrl = new URL(validatedURL) const redirectUrl = parsedUrl.searchParams.get('url') - if (redirectUrl) { - webview.loadURL(redirectUrl) - } + webview.loadURL(redirectUrl || 'https://gog.com') } } From 89164e33c3102e1086a353917f34929c4aca6fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lidwin?= Date: Tue, 27 Feb 2024 16:50:56 +0100 Subject: [PATCH 5/5] feat: show a warning about blocked adtraction --- public/locales/en/translation.json | 5 +++ src/frontend/screens/WebView/index.tsx | 56 +++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 63182b7042..17ee306f40 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -9,6 +9,11 @@ "zoom": "Zoom" }, "add_game": "Add Game", + "adtraction-locked": { + "description": "It seems the track.adtraction.com domain was unable to load or is blocked. With adtraction, any purchase you make in the GOG store supports Heroic financially. Consider removing the block if you wish to contribute.", + "dont-show-again": "Don't show this warning again", + "title": "Adtraction is blocked" + }, "Amazon Games": "Amazon Games", "anticheat": { "anticheats": "Anticheats", diff --git a/src/frontend/screens/WebView/index.tsx b/src/frontend/screens/WebView/index.tsx index fa07981bd4..05270d4c59 100644 --- a/src/frontend/screens/WebView/index.tsx +++ b/src/frontend/screens/WebView/index.tsx @@ -8,13 +8,18 @@ import React, { import { useTranslation } from 'react-i18next' import { useNavigate, useLocation, useParams } from 'react-router' -import { UpdateComponent } from 'frontend/components/UI' +import { ToggleSwitch, UpdateComponent } from 'frontend/components/UI' import WebviewControls from 'frontend/components/UI/WebviewControls' import ContextProvider from 'frontend/state/ContextProvider' import { Runner } from 'common/types' import './index.css' import LoginWarning from '../Login/components/LoginWarning' import { NileLoginData } from 'common/types/nile' +import { + Dialog, + DialogContent, + DialogHeader +} from 'frontend/components/UI/Dialog' interface Props { store?: 'epic' | 'gog' | 'amazon' @@ -218,11 +223,13 @@ export default function WebView({ store }: Props) { } const onerror = ({ validatedURL }: Electron.DidFailLoadEvent) => { - // Connection refused if (validatedURL && validatedURL.match(/track\.adtraction\.com/)) { const parsedUrl = new URL(validatedURL) const redirectUrl = parsedUrl.searchParams.get('url') webview.loadURL(redirectUrl || 'https://gog.com') + if (!localStorage.getItem('adtraction-warning')) { + setShowAdtractionWarning(true) + } } } @@ -275,6 +282,12 @@ export default function WebView({ store }: Props) { null | 'epic' | 'gog' | 'amazon' >(null) + const [showAdtractionWarning, setShowAdtractionWarning] = + useState(false) + + const [dontShowAdtractionWarning, setDontShowAdtractionWarning] = + useState(false) + useEffect(() => { if (startUrl.match(/epicgames\.com/) && !epic.username) { setShowLoginWarningFor('epic') @@ -322,6 +335,45 @@ export default function WebView({ store }: Props) { onClose={onLoginWarningClosed} /> )} + {showAdtractionWarning && ( + { + setShowAdtractionWarning(false) + dontShowAdtractionWarning && + localStorage.setItem('adtraction-warning', 'true') + }} + > + { + setShowAdtractionWarning(false) + dontShowAdtractionWarning && + localStorage.setItem('adtraction-warning', 'true') + }} + > + {t('adtraction-locked.title', 'Adtraction is blocked')} + + +

+ {t( + 'adtraction-locked.description', + 'It seems the track.adtraction.com domain was unable to load or is blocked. With adtraction, any purchase you make in the GOG store supports Heroic financially. Consider removing the block if you wish to contribute.' + )} +

+ + setDontShowAdtractionWarning(e.target.checked) + } + title={t( + 'adtraction-locked.dont-show-again', + "Don't show this warning again" + )} + /> +
+
+ )} ) }