Skip to content

[FIX] Adtraction fallback #3575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,21 +534,6 @@ interface GamepadActionArgsWithoutMetadata {
metadata?: undefined
}

type ElWebview = {
canGoBack: () => boolean
canGoForward: () => boolean
goBack: () => void
goForward: () => void
reload: () => void
isLoading: () => boolean
getURL: () => string
copy: () => string
selectAll: () => void
findInPage: (text: string | RegExp) => void
}

export type WebviewType = HTMLWebViewElement & ElWebview

export type InstallPlatform =
| LegendaryInstallPlatform
| GogInstallPlatform
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/components/UI/WebviewControls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 15 additions & 3 deletions src/frontend/screens/WebView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -49,7 +49,7 @@ export default function WebView({ store }: Props) {
null
)
const navigate = useNavigate()
const webviewRef = useRef<WebviewType>(null)
const webviewRef = useRef<Electron.WebviewTag>(null)

let lang = i18n.language
if (i18n.language === 'pt') {
Expand Down Expand Up @@ -217,8 +217,19 @@ export default function WebView({ store }: Props) {
}
}

webview.addEventListener('dom-ready', loadstop)
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')
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 = () => {
Expand All @@ -231,6 +242,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)
}
}
Expand Down