diff --git a/gui/esiFittings.py b/gui/esiFittings.py index 34ad42384..6b6ca4d36 100644 --- a/gui/esiFittings.py +++ b/gui/esiFittings.py @@ -227,21 +227,6 @@ class EveFittings(AuxiliaryFrame): self.fitView.update([]) -class ESIServerExceptionHandler: - def __init__(self, parentWindow, ex): - pyfalog.error(ex) - with wx.MessageDialog( - parentWindow, - _t("There was an issue starting up the localized server, try setting " - "Login Authentication Method to Manual by going to Preferences -> EVE SS0 -> " - "Login Authentication Method. If this doesn't fix the problem please file an " - "issue on Github."), - _t("Add Character Error"), - wx.OK | wx.ICON_ERROR - ) as dlg: - dlg.ShowModal() - - class ESIExceptionHandler: # todo: make this a generate excetpion handler for all calls def __init__(self, ex): diff --git a/gui/ssoLogin.py b/gui/ssoLogin.py index a1e3d2a16..cce7615ff 100644 --- a/gui/ssoLogin.py +++ b/gui/ssoLogin.py @@ -60,11 +60,16 @@ class SsoLogin(wx.Dialog): if server.name == "Serenity": webbrowser.open(config.SSO_LOGOFF_SERENITY) time.sleep(1) + self.okBtn = self.FindWindow(wx.ID_OK) - webbrowser.open(uri) self.okBtn.Enable(False) + # Ensure we clean up once they hit the "OK" button + self.okBtn.Bind(wx.EVT_BUTTON, self.OnDestroy) + + webbrowser.open(uri) self.mainFrame.Bind(GE.EVT_SSO_LOGIN, self.OnLogin) + # Ensure we clean up if ESC is pressed self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy) def OnTextEnter(self, event): @@ -76,10 +81,13 @@ class SsoLogin(wx.Dialog): event.Skip() def OnLogin(self, event): + # This would normally happen if it was logged in via server auto-login. In this case, the modal is done, we effectively want to cancel out self.EndModal(wx.ID_CANCEL) event.Skip() def OnDestroy(self, event): + # Clean up by unbinding some events and stopping the server self.mainFrame.Unbind(GE.EVT_SSO_LOGIN, handler=self.OnLogin) + self.Unbind(wx.EVT_WINDOW_DESTROY, handler=self.OnDestroy) self.sEsi.stopServer() event.Skip() diff --git a/service/esi.py b/service/esi.py index 606dd9742..1bfa103b7 100644 --- a/service/esi.py +++ b/service/esi.py @@ -22,6 +22,7 @@ import gui.mainFrame from requests import Session pyfalog = Logger(__name__) +_t = wx.GetTranslation class Esi(EsiAccess): @@ -104,16 +105,32 @@ class Esi(EsiAccess): start_server = self.settings.get('loginMode') == EsiLoginMethod.SERVER and self.server_base.supports_auto_login with gui.ssoLogin.SsoLogin(self.server_base, start_server) as dlg: if dlg.ShowModal() == wx.ID_OK: - if self.default_server_name == "Serenity": - s = re.search(r'(?<=code=)[a-zA-Z0-9\-_]*', dlg.ssoInfoCtrl.Value.strip()) - if s: - # skip state verification and go directly through the auth code processing - self.handleLogin(s.group) + from gui.esiFittings import ESIExceptionHandler + + try: + if self.default_server_name == "Serenity": + s = re.search(r'(?<=code=)[a-zA-Z0-9\-_]*', dlg.ssoInfoCtrl.Value.strip()) + if s: + # skip state verification and go directly through the auth code processing + self.handleLogin(s.group) + else: + pass + # todo: throw error else: - pass - # todo: throw error - else: - self.handleServerRequest(json.loads(base64.b64decode(dlg.ssoInfoCtrl.Value.strip()))) + self.handleServerRequest(json.loads(base64.b64decode(dlg.ssoInfoCtrl.Value.strip()))) + except GenericSsoError as ex: + pyfalog.error(ex) + with wx.MessageDialog( + self.mainFrame, + str(ex), + _t("SSO Error"), + wx.OK | wx.ICON_ERROR + ) as dlg: + dlg.ShowModal() + except APIException as ex: + pyfalog.error(ex) + ESIExceptionHandler(ex) + pass def stopServer(self):