Skip to content

fix: use egs's flow for epic login #4379

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 1 commit into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ asarUnpack:
- build/win_icon.ico
- build/icon-dark.png
- build/icon-light.png
- build/webviewPreload.js
- build/bin/**/*
- '!build/bin/legendary.LICENSE'

Expand Down
6 changes: 3 additions & 3 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@
"gamemode": "Feral GameMode applies automatic and temporary tweaks to the system when running games. Enabling may improve performance.",
"gamescope": {
"additionalOptions": "Additional commandline flags to pass into gamescope.",
"forceGrabCursor": "Always use relative mouse mode instead of flipping dependent on cursor visibility. (Useful for when applications keep losing focus)",
"fpsLimiter": "The amount of frames gamescope should limit to. E.g. 60",
"fpsLimiterNoFocus": "The frame rate limit gamescope should limit per second if the game is not focused.",
"gameHeight": "The height resolution used by the game. A 16:9 aspect ratio is assumed by gamescope.",
"gameWidth": "The width resolution used by the game. A 16:9 aspect ratio is assumed by gamescope.",
"upscaleHeight": "The height resolution used by gamescope. A 16:9 aspect ratio is assumed.",
"upscaleMethod": "The upscaling method gamescope should use.",
"upscaleWidth": "The width resolution used by gamescope. A 16:9 aspect ratio is assumed.",
"forceGrabCursor": "Always use relative mouse mode instead of flipping dependent on cursor visibility. (Useful for when applications keep losing focus)"
"upscaleWidth": "The width resolution used by gamescope. A 16:9 aspect ratio is assumed."
},
"general": "Sync with EGL if you have a working installation of the Epic Games Launcher elsewhere and want to import your games to avoid downloading them again.",
"mangohud": "MangoHUD is an overlay that displays and monitors FPS, temperatures, CPU/GPU load and other system resources.",
Expand Down Expand Up @@ -653,9 +653,9 @@
"fsync": "Enable Fsync",
"gamemode": "Use GameMode (Feral Game Mode needs to be installed)",
"gamescope": {
"enableForceGrabCursor": "Enable Force Grab Cursor",
"enableLimiter": "Enable FPS Limiter",
"enableUpscaling": "Enables Upscaling",
"enableForceGrabCursor": "Enable Force Grab Cursor",
"missingMsg": "We could not found gamescope on the PATH. Install it or add it to the PATH."
},
"hideChangelogsOnStartup": "Don't show changelogs on Startup",
Expand Down
9 changes: 0 additions & 9 deletions public/webviewPreload.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/backend/api/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ export const getGOGLinuxInstallersLangs = async (appName: string) =>
ipcRenderer.invoke('getGOGLinuxInstallersLangs', appName)
export const getAlternativeWine = async () =>
ipcRenderer.invoke('getAlternativeWine')
export const getLocalPeloadPath = async () =>
ipcRenderer.invoke('getLocalPeloadPath')
export const getShellPath = async (saveLocation: string) =>
ipcRenderer.invoke('getShellPath', saveLocation)
export const callTool = async (toolArgs: Tools) =>
Expand Down
4 changes: 0 additions & 4 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ import {
wineprefixFAQ,
customThemesWikiLink,
createNecessaryFolders,
fixAsarPath,
isSnap,
isWindows,
isMac
Expand Down Expand Up @@ -772,9 +771,6 @@ ipcMain.handle('login', async (event, sid) => LegendaryUser.login(sid))
ipcMain.handle('authGOG', async (event, code) => GOGUser.login(code))
ipcMain.handle('logoutLegendary', LegendaryUser.logout)
ipcMain.on('logoutGOG', GOGUser.logout)
ipcMain.handle('getLocalPeloadPath', async () => {
return fixAsarPath(join('file://', publicDir, 'webviewPreload.js'))
})

ipcMain.handle('getAmazonLoginData', NileUser.getLoginData)
ipcMain.handle('authAmazon', async (event, data) => NileUser.login(data))
Expand Down
1 change: 0 additions & 1 deletion src/common/typedefs/ipcBridge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ interface AsyncIPCFunctions {
logoutLegendary: () => Promise<void>
logoutAmazon: () => Promise<void>
getAlternativeWine: () => Promise<WineInstallation[]>
getLocalPeloadPath: () => Promise<string>
readConfig: (config_class: 'library' | 'user') => Promise<GameInfo[] | string>
requestSettings: (appName: string) => Promise<AppSettings | GameSettings>
writeConfig: (args: { appName: string; config: Partial<AppSettings> }) => void
Expand Down
86 changes: 30 additions & 56 deletions src/frontend/screens/WebView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function WebView() {
lang = 'pt-BR'
}

const epicLoginUrl = 'https://legendary.gl/epiclogin'
const epicLoginUrl = 'https://www.epicgames.com/id/login?responseType=code'

const epicStore = `https://www.epicgames.com/store/${lang}/`
const gogStore = `https://af.gog.com?as=1838482841`
Expand Down Expand Up @@ -103,27 +103,6 @@ export default function WebView() {
}
}

const isEpicLogin = runner === 'legendary' && startUrl === epicLoginUrl
const [preloadPath, setPreloadPath] = useState('')

useEffect(() => {
let mounted = true
const fetchLocalPreloadPath = async () => {
const path = await window.api.getLocalPeloadPath()
if (mounted) {
setPreloadPath(path)
}
}

if (isEpicLogin) {
fetchLocalPreloadPath()
}

return () => {
mounted = false
}
}, [isEpicLogin])

useEffect(() => {
if (pathname !== '/loginweb/nile') return
console.log('Loading amazon login data')
Expand Down Expand Up @@ -169,26 +148,7 @@ export default function WebView() {

useLayoutEffect(() => {
const webview = webviewRef.current
if (webview && ((preloadPath && isEpicLogin) || !isEpicLogin)) {
const onIpcMessage = async (event: unknown) => {
const e = event as { channel: string; args: string[] }
if (e.channel === 'processEpicLoginCode') {
try {
setLoading({
refresh: true,
message: t('status.logging', 'Logging In...')
})
await epic.login(e.args[0])
handleSuccessfulLogin()
} catch (error) {
console.error(error)
window.api.logError(String(error))
}
}
}

webview.addEventListener('ipc-message', onIpcMessage)

if (webview) {
const loadstop = async () => {
setLoading({ ...loading, refresh: false })
// Ignore the login handling if not on login page
Expand All @@ -199,14 +159,12 @@ export default function WebView() {
if (pageUrl.match(gogEmbedRegExp)) {
const parsedURL = new URL(pageUrl)
const code = parsedURL.searchParams.get('code')
setLoading({
refresh: true,
message: t('status.logging', 'Logging In...')
})
if (code) {
gog.login(code).then(() => {
handleSuccessfulLogin()
setLoading({
refresh: true,
message: t('status.logging', 'Logging In...')
})
gog.login(code).then(() => handleSuccessfulLogin())
}
}
} else if (runner === 'nile') {
Expand All @@ -218,6 +176,19 @@ export default function WebView() {
if (code) {
handleAmazonLogin(code)
}
} else if (runner == 'legendary') {
const pageUrl = webview.getURL()
const parsedUrl = new URL(pageUrl)
if (parsedUrl.hostname === 'localhost') {
const code = parsedUrl.searchParams.get('code')
if (code) {
setLoading({
refresh: true,
message: t('status.logging', 'Logging In...')
})
epic.login(code).then(() => handleSuccessfulLogin())
}
}
}
}

Expand Down Expand Up @@ -255,14 +226,13 @@ export default function WebView() {
webview.addEventListener('page-title-updated', updateConnectivity)

return () => {
webview.removeEventListener('ipc-message', onIpcMessage)
webview.removeEventListener('dom-ready', loadstop)
webview.removeEventListener('did-fail-load', onerror)
webview.removeEventListener('page-title-updated', updateConnectivity)
}
}
return
}, [webviewRef.current, preloadPath, amazonLoginData, runner])
}, [webviewRef.current, amazonLoginData, runner])

useEffect(() => {
const webview = webviewRef.current
Expand Down Expand Up @@ -299,7 +269,11 @@ export default function WebView() {
useState<boolean>(false)

useEffect(() => {
if (startUrl.match(/epicgames\.com/) && !epic.username) {
if (
startUrl.match(/epicgames\.com/) &&
startUrl.indexOf('/id/login') < 0 &&
!epic.username
) {
setShowLoginWarningFor('epic')
} else if (
startUrl.match(/gog\.com/) &&
Expand All @@ -318,9 +292,10 @@ export default function WebView() {
setShowLoginWarningFor(null)
}

if (!preloadPath && isEpicLogin) {
return <></>
}
const userAgent =
startUrl === epicLoginUrl
? 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) EpicGamesLauncher'
: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/200.0 HeroicGamesLauncher'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe we don't need those double UA tbh, I only added this one to try to fix some issues with random errors on epic login, server errors.

Copy link
Member Author

@imLinguin imLinguin Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking it may be worth keeping for some browser side loaded apps. Or in the future let users configure user agent strings for browser apps


return (
<div className="WebView">
Expand All @@ -338,8 +313,7 @@ export default function WebView() {
partition="persist:epicstore"
src={startUrl}
allowpopups={trueAsStr}
useragent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/200.0"
{...(preloadPath ? { preload: preloadPath } : {})}
useragent={userAgent}
/>
{showLoginWarningFor && (
<LoginWarning
Expand Down
Loading