mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-13 05:42:10 +03:00
Fix CAPI update properly for on-foot/embarking.
* Stop relying on self.status['text'] as indicator, set and use `err`.
This commit is contained in:
parent
72d200f616
commit
5c99ef1243
@ -741,6 +741,7 @@ class AppWindow(object):
|
|||||||
auto_update = not event
|
auto_update = not event
|
||||||
play_sound = (auto_update or int(event.type) == self.EVENT_VIRTUAL) and not config.get_int('hotkey_mute')
|
play_sound = (auto_update or int(event.type) == self.EVENT_VIRTUAL) and not config.get_int('hotkey_mute')
|
||||||
play_bad = False
|
play_bad = False
|
||||||
|
err: Optional[str] = None
|
||||||
|
|
||||||
if not monitor.cmdr or not monitor.mode or monitor.state['Captain'] or not monitor.system:
|
if not monitor.cmdr or not monitor.mode or monitor.state['Captain'] or not monitor.system:
|
||||||
return # In CQC or on crew - do nothing
|
return # In CQC or on crew - do nothing
|
||||||
@ -773,19 +774,18 @@ class AppWindow(object):
|
|||||||
# Validation
|
# Validation
|
||||||
if 'commander' not in data:
|
if 'commander' not in data:
|
||||||
# This can happen with EGS Auth if no commander created yet
|
# This can happen with EGS Auth if no commander created yet
|
||||||
self.status['text'] = _('CAPI: No commander data returned')
|
err = self.status['text'] = _('CAPI: No commander data returned')
|
||||||
|
|
||||||
elif not data.get('commander', {}).get('name'):
|
elif not data.get('commander', {}).get('name'):
|
||||||
self.status['text'] = _("Who are you?!") # Shouldn't happen
|
err = self.status['text'] = _("Who are you?!") # Shouldn't happen
|
||||||
|
|
||||||
elif (not data.get('lastSystem', {}).get('name')
|
elif (not data.get('lastSystem', {}).get('name')
|
||||||
or (data['commander'].get('docked') or monitor.state['OnFoot']
|
or (data['commander'].get('docked') or monitor.state['OnFoot']
|
||||||
and not data.get('lastStarport', {}).get('name'))
|
and not data.get('lastStarport', {}).get('name'))):
|
||||||
or (monitor.state['OnFoot'] and data['lastStarport']['name'] != monitor.station)):
|
err = self.status['text'] = _("Where are you?!") # Shouldn't happen
|
||||||
self.status['text'] = _("Where are you?!") # Shouldn't happen
|
|
||||||
|
|
||||||
elif not data.get('ship', {}).get('name') or not data.get('ship', {}).get('modules'):
|
elif not data.get('ship', {}).get('name') or not data.get('ship', {}).get('modules'):
|
||||||
self.status['text'] = _("What are you flying?!") # Shouldn't happen
|
err = self.status['text'] = _("What are you flying?!") # Shouldn't happen
|
||||||
|
|
||||||
elif monitor.cmdr and data['commander']['name'] != monitor.cmdr:
|
elif monitor.cmdr and data['commander']['name'] != monitor.cmdr:
|
||||||
# Companion API Commander doesn't match Journal
|
# Companion API Commander doesn't match Journal
|
||||||
@ -812,6 +812,8 @@ class AppWindow(object):
|
|||||||
# CAPI lastStarport must match
|
# CAPI lastStarport must match
|
||||||
raise companion.ServerLagging()
|
raise companion.ServerLagging()
|
||||||
|
|
||||||
|
self.holdofftime = querytime + companion.holdoff
|
||||||
|
|
||||||
elif not monitor.state['OnFoot'] and data['ship']['id'] != monitor.state['ShipID']:
|
elif not monitor.state['OnFoot'] and data['ship']['id'] != monitor.state['ShipID']:
|
||||||
# CAPI ship must match
|
# CAPI ship must match
|
||||||
raise companion.ServerLagging()
|
raise companion.ServerLagging()
|
||||||
@ -841,14 +843,16 @@ class AppWindow(object):
|
|||||||
|
|
||||||
# Export market data
|
# Export market data
|
||||||
if not self.export_market_data(data):
|
if not self.export_market_data(data):
|
||||||
|
err = 'Error: Exporting Market data'
|
||||||
play_bad = True
|
play_bad = True
|
||||||
|
|
||||||
self.holdofftime = querytime + companion.holdoff
|
self.holdofftime = querytime + companion.holdoff
|
||||||
|
|
||||||
# Companion API problem
|
# Companion API problem
|
||||||
except companion.ServerLagging as e:
|
except companion.ServerLagging as e:
|
||||||
|
err = str(e)
|
||||||
if retrying:
|
if retrying:
|
||||||
self.status['text'] = str(e)
|
self.status['text'] = err
|
||||||
play_bad = True
|
play_bad = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -857,17 +861,17 @@ class AppWindow(object):
|
|||||||
return # early exit to avoid starting cooldown count
|
return # early exit to avoid starting cooldown count
|
||||||
|
|
||||||
except companion.CmdrError as e: # Companion API return doesn't match Journal
|
except companion.CmdrError as e: # Companion API return doesn't match Journal
|
||||||
self.status['text'] = str(e)
|
err = self.status['text'] = str(e)
|
||||||
play_bad = True
|
play_bad = True
|
||||||
companion.session.invalidate()
|
companion.session.invalidate()
|
||||||
self.login()
|
self.login()
|
||||||
|
|
||||||
except Exception as e: # Including CredentialsError, ServerError
|
except Exception as e: # Including CredentialsError, ServerError
|
||||||
logger.debug('"other" exception', exc_info=e)
|
logger.debug('"other" exception', exc_info=e)
|
||||||
self.status['text'] = str(e)
|
err = self.status['text'] = str(e)
|
||||||
play_bad = True
|
play_bad = True
|
||||||
|
|
||||||
if not self.status['text']: # no errors
|
if not err: # not self.status['text']: # no errors
|
||||||
self.status['text'] = strftime(_('Last updated at %H:%M:%S'), localtime(querytime))
|
self.status['text'] = strftime(_('Last updated at %H:%M:%S'), localtime(querytime))
|
||||||
|
|
||||||
if play_sound and play_bad:
|
if play_sound and play_bad:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user