[cli/utils] Fix webview login on Windows

Now using exchange code every time!
This commit is contained in:
derrod 2022-09-01 02:00:19 +02:00
parent f26c8ab0a1
commit 5a20f12461
2 changed files with 15 additions and 13 deletions

View file

@ -165,7 +165,7 @@ class LegendaryCLI:
sid = sid.strip('"')
exchange_token = self.core.auth_sid(sid)
else:
if do_webview_login(callback_sid=self.core.auth_sid, callback_code=self.core.auth_code):
if do_webview_login(callback_code=self.core.auth_code):
logger.info(f'Successfully logged in as "{self.core.lgd.userdata["displayName"]}" via WebView')
else:
logger.error('WebView login attempt failed, please see log for details.')

View file

@ -70,7 +70,7 @@ class MockLauncher:
if self.inject_js:
self.window.evaluate_js(window_js)
if 'logout' in url:
if 'logout' in url and self.callback_sid:
# prepare to close browser after logout redirect
self.destroy_on_load = True
@ -87,7 +87,8 @@ class MockLauncher:
# skip logging out on those platforms and directly use the exchange code we're given.
# On windows we have to do a little dance with the SID to create a session that
# remains valid after logging out in the embedded browser.
if self.window.gui.renderer in ('gtkwebkit2', 'qtwebengine', 'qtwebkit'):
# Update: Epic broke SID login, we'll also do this on Windows now
# if self.window.gui.renderer in ('gtkwebkit2', 'qtwebengine', 'qtwebkit'):
self.destroy_on_load = True
try:
self.callback_result = self.callback_code(exchange_code)
@ -125,7 +126,8 @@ def do_webview_login(callback_sid=None, callback_code=None):
api = MockLauncher(callback_sid=callback_sid, callback_code=callback_code)
logger.info('Opening Epic Games login window...')
window = webview.create_window(f'Legendary {__version__} - Epic Games Account Login',
url=login_url, width=768, height=1024, js_api=api)
url=logout_url if not callback_sid else login_url,
width=768, height=1024, js_api=api)
api.window = window
window.events.loaded += api.on_loaded