mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 01:45:28 +00:00
[cli/utils] Fix webview login on Windows
Now using exchange code every time!
This commit is contained in:
parent
f26c8ab0a1
commit
5a20f12461
|
@ -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.')
|
||||
|
|
|
@ -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,16 +87,17 @@ 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'):
|
||||
self.destroy_on_load = True
|
||||
try:
|
||||
self.callback_result = self.callback_code(exchange_code)
|
||||
except Exception as e:
|
||||
logger.error(f'Logging in via exchange-code failed with {e!r}')
|
||||
finally:
|
||||
# We cannot destroy the browser from here,
|
||||
# so we'll load a small goodbye site first.
|
||||
self.window.load_url(goodbye_url)
|
||||
# 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)
|
||||
except Exception as e:
|
||||
logger.error(f'Logging in via exchange-code failed with {e!r}')
|
||||
finally:
|
||||
# We cannot destroy the browser from here,
|
||||
# so we'll load a small goodbye site first.
|
||||
self.window.load_url(goodbye_url)
|
||||
|
||||
def trigger_sid_exchange(self, *args, **kwargs):
|
||||
# check if code-based login hasn't already set the destroy flag
|
||||
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue