Skip to content

Commit 262d2ec

Browse files
committed
fix: use egs's flow for epic login
1 parent d6c662f commit 262d2ec

File tree

7 files changed

+33
-85
lines changed

7 files changed

+33
-85
lines changed

electron-builder.yml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ asarUnpack:
1313
- build/win_icon.ico
1414
- build/icon-dark.png
1515
- build/icon-light.png
16-
- build/webviewPreload.js
1716
- build/bin/**/*
1817
- '!build/bin/legendary.LICENSE'
1918

public/locales/en/translation.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,14 @@
324324
"gamemode": "Feral GameMode applies automatic and temporary tweaks to the system when running games. Enabling may improve performance.",
325325
"gamescope": {
326326
"additionalOptions": "Additional commandline flags to pass into gamescope.",
327+
"forceGrabCursor": "Always use relative mouse mode instead of flipping dependent on cursor visibility. (Useful for when applications keep losing focus)",
327328
"fpsLimiter": "The amount of frames gamescope should limit to. E.g. 60",
328329
"fpsLimiterNoFocus": "The frame rate limit gamescope should limit per second if the game is not focused.",
329330
"gameHeight": "The height resolution used by the game. A 16:9 aspect ratio is assumed by gamescope.",
330331
"gameWidth": "The width resolution used by the game. A 16:9 aspect ratio is assumed by gamescope.",
331332
"upscaleHeight": "The height resolution used by gamescope. A 16:9 aspect ratio is assumed.",
332333
"upscaleMethod": "The upscaling method gamescope should use.",
333-
"upscaleWidth": "The width resolution used by gamescope. A 16:9 aspect ratio is assumed.",
334-
"forceGrabCursor": "Always use relative mouse mode instead of flipping dependent on cursor visibility. (Useful for when applications keep losing focus)"
334+
"upscaleWidth": "The width resolution used by gamescope. A 16:9 aspect ratio is assumed."
335335
},
336336
"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.",
337337
"mangohud": "MangoHUD is an overlay that displays and monitors FPS, temperatures, CPU/GPU load and other system resources.",
@@ -653,9 +653,9 @@
653653
"fsync": "Enable Fsync",
654654
"gamemode": "Use GameMode (Feral Game Mode needs to be installed)",
655655
"gamescope": {
656+
"enableForceGrabCursor": "Enable Force Grab Cursor",
656657
"enableLimiter": "Enable FPS Limiter",
657658
"enableUpscaling": "Enables Upscaling",
658-
"enableForceGrabCursor": "Enable Force Grab Cursor",
659659
"missingMsg": "We could not found gamescope on the PATH. Install it or add it to the PATH."
660660
},
661661
"hideChangelogsOnStartup": "Don't show changelogs on Startup",

public/webviewPreload.js

-9
This file was deleted.

src/backend/api/misc.ts

-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ export const getGOGLinuxInstallersLangs = async (appName: string) =>
107107
ipcRenderer.invoke('getGOGLinuxInstallersLangs', appName)
108108
export const getAlternativeWine = async () =>
109109
ipcRenderer.invoke('getAlternativeWine')
110-
export const getLocalPeloadPath = async () =>
111-
ipcRenderer.invoke('getLocalPeloadPath')
112110
export const getShellPath = async (saveLocation: string) =>
113111
ipcRenderer.invoke('getShellPath', saveLocation)
114112
export const callTool = async (toolArgs: Tools) =>

src/backend/main.ts

-13
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ import {
8080
wineprefixFAQ,
8181
customThemesWikiLink,
8282
createNecessaryFolders,
83-
fixAsarPath,
8483
isSnap,
8584
isWindows,
8685
isMac
@@ -764,18 +763,6 @@ ipcMain.handle('getUserInfo', async () => {
764763
})
765764

766765
ipcMain.handle('getAmazonUserInfo', async () => NileUser.getUserData())
767-
768-
// Checks if the user have logged in with Legendary already
769-
ipcMain.handle('isLoggedIn', LegendaryUser.isLoggedIn)
770-
771-
ipcMain.handle('login', async (event, sid) => LegendaryUser.login(sid))
772-
ipcMain.handle('authGOG', async (event, code) => GOGUser.login(code))
773-
ipcMain.handle('logoutLegendary', LegendaryUser.logout)
774-
ipcMain.on('logoutGOG', GOGUser.logout)
775-
ipcMain.handle('getLocalPeloadPath', async () => {
776-
return fixAsarPath(join('file://', publicDir, 'webviewPreload.js'))
777-
})
778-
779766
ipcMain.handle('getAmazonLoginData', NileUser.getLoginData)
780767
ipcMain.handle('authAmazon', async (event, data) => NileUser.login(data))
781768
ipcMain.handle('logoutAmazon', NileUser.logout)

src/common/typedefs/ipcBridge.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ interface AsyncIPCFunctions {
202202
logoutLegendary: () => Promise<void>
203203
logoutAmazon: () => Promise<void>
204204
getAlternativeWine: () => Promise<WineInstallation[]>
205-
getLocalPeloadPath: () => Promise<string>
206205
readConfig: (config_class: 'library' | 'user') => Promise<GameInfo[] | string>
207206
requestSettings: (appName: string) => Promise<AppSettings | GameSettings>
208207
writeConfig: (args: { appName: string; config: Partial<AppSettings> }) => void

src/frontend/screens/WebView/index.tsx

+30-56
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default function WebView() {
6161
lang = 'pt-BR'
6262
}
6363

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

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

106-
const isEpicLogin = runner === 'legendary' && startUrl === epicLoginUrl
107-
const [preloadPath, setPreloadPath] = useState('')
108-
109-
useEffect(() => {
110-
let mounted = true
111-
const fetchLocalPreloadPath = async () => {
112-
const path = await window.api.getLocalPeloadPath()
113-
if (mounted) {
114-
setPreloadPath(path)
115-
}
116-
}
117-
118-
if (isEpicLogin) {
119-
fetchLocalPreloadPath()
120-
}
121-
122-
return () => {
123-
mounted = false
124-
}
125-
}, [isEpicLogin])
126-
127106
useEffect(() => {
128107
if (pathname !== '/loginweb/nile') return
129108
console.log('Loading amazon login data')
@@ -169,26 +148,7 @@ export default function WebView() {
169148

170149
useLayoutEffect(() => {
171150
const webview = webviewRef.current
172-
if (webview && ((preloadPath && isEpicLogin) || !isEpicLogin)) {
173-
const onIpcMessage = async (event: unknown) => {
174-
const e = event as { channel: string; args: string[] }
175-
if (e.channel === 'processEpicLoginCode') {
176-
try {
177-
setLoading({
178-
refresh: true,
179-
message: t('status.logging', 'Logging In...')
180-
})
181-
await epic.login(e.args[0])
182-
handleSuccessfulLogin()
183-
} catch (error) {
184-
console.error(error)
185-
window.api.logError(String(error))
186-
}
187-
}
188-
}
189-
190-
webview.addEventListener('ipc-message', onIpcMessage)
191-
151+
if (webview) {
192152
const loadstop = async () => {
193153
setLoading({ ...loading, refresh: false })
194154
// Ignore the login handling if not on login page
@@ -199,14 +159,12 @@ export default function WebView() {
199159
if (pageUrl.match(gogEmbedRegExp)) {
200160
const parsedURL = new URL(pageUrl)
201161
const code = parsedURL.searchParams.get('code')
202-
setLoading({
203-
refresh: true,
204-
message: t('status.logging', 'Logging In...')
205-
})
206162
if (code) {
207-
gog.login(code).then(() => {
208-
handleSuccessfulLogin()
163+
setLoading({
164+
refresh: true,
165+
message: t('status.logging', 'Logging In...')
209166
})
167+
gog.login(code).then(() => handleSuccessfulLogin())
210168
}
211169
}
212170
} else if (runner === 'nile') {
@@ -218,6 +176,19 @@ export default function WebView() {
218176
if (code) {
219177
handleAmazonLogin(code)
220178
}
179+
} else if (runner == 'legendary') {
180+
const pageUrl = webview.getURL()
181+
const parsedUrl = new URL(pageUrl)
182+
if (parsedUrl.hostname === 'localhost') {
183+
const code = parsedUrl.searchParams.get('code')
184+
if (code) {
185+
setLoading({
186+
refresh: true,
187+
message: t('status.logging', 'Logging In...')
188+
})
189+
epic.login(code).then(() => handleSuccessfulLogin())
190+
}
191+
}
221192
}
222193
}
223194

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

257228
return () => {
258-
webview.removeEventListener('ipc-message', onIpcMessage)
259229
webview.removeEventListener('dom-ready', loadstop)
260230
webview.removeEventListener('did-fail-load', onerror)
261231
webview.removeEventListener('page-title-updated', updateConnectivity)
262232
}
263233
}
264234
return
265-
}, [webviewRef.current, preloadPath, amazonLoginData, runner])
235+
}, [webviewRef.current, amazonLoginData, runner])
266236

267237
useEffect(() => {
268238
const webview = webviewRef.current
@@ -299,7 +269,11 @@ export default function WebView() {
299269
useState<boolean>(false)
300270

301271
useEffect(() => {
302-
if (startUrl.match(/epicgames\.com/) && !epic.username) {
272+
if (
273+
startUrl.match(/epicgames\.com/) &&
274+
startUrl.indexOf('/id/login') < 0 &&
275+
!epic.username
276+
) {
303277
setShowLoginWarningFor('epic')
304278
} else if (
305279
startUrl.match(/gog\.com/) &&
@@ -318,9 +292,10 @@ export default function WebView() {
318292
setShowLoginWarningFor(null)
319293
}
320294

321-
if (!preloadPath && isEpicLogin) {
322-
return <></>
323-
}
295+
const userAgent =
296+
startUrl === epicLoginUrl
297+
? 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) EpicGamesLauncher'
298+
: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/200.0 HeroicGamesLauncher'
324299

325300
return (
326301
<div className="WebView">
@@ -338,8 +313,7 @@ export default function WebView() {
338313
partition="persist:epicstore"
339314
src={startUrl}
340315
allowpopups={trueAsStr}
341-
useragent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/200.0"
342-
{...(preloadPath ? { preload: preloadPath } : {})}
316+
useragent={userAgent}
343317
/>
344318
{showLoginWarningFor && (
345319
<LoginWarning

0 commit comments

Comments
 (0)