diff --git a/EDMarketConnector.py b/EDMarketConnector.py index d6eaa750..9ead323c 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -872,7 +872,10 @@ class AppWindow(object): 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 or monitor.mode == 'CQC' + ): return # In CQC or on crew - do nothing if companion.session.state == companion.Session.STATE_AUTH: @@ -1171,9 +1174,18 @@ class AppWindow(object): config.set('cmdrs', config.get_list('cmdrs', default=[]) + [monitor.cmdr]) self.login() + if monitor.mode == 'CQC' and entry['event']: + err = plug.notify_journal_entry_cqc(monitor.cmdr, monitor.is_beta, entry, monitor.state) + if err: + self.status['text'] = err + if not config.get_int('hotkey_mute'): + hotkeymgr.play_bad() + + return # in CQC + if not entry['event'] or not monitor.mode: - # logger.trace('Startup or in CQC, returning') - return # Startup or in CQC + # logger.trace('Startup, returning') + return # Startup if entry['event'] in ['StartUp', 'LoadGame'] and monitor.started: logger.info('Startup or LoadGame event') @@ -1335,6 +1347,7 @@ class AppWindow(object): self.button['text'] = self.theme_button['text'] = _('Update') # LANG: Update button in main window self.button['state'] = self.theme_button['state'] = (monitor.cmdr and monitor.mode and + monitor.mode == 'CQC' and not monitor.state['Captain'] and monitor.system and tk.NORMAL or tk.DISABLED) diff --git a/monitor.py b/monitor.py index 01a614e7..4f8802e8 100644 --- a/monitor.py +++ b/monitor.py @@ -529,7 +529,15 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # Odyssey: bool self.cmdr = entry['Commander'] # 'Open', 'Solo', 'Group', or None for CQC (and Training - but no LoadGame event) - self.mode = entry.get('GameMode') + if not entry.get('Ship') and not entry.get('GameMode') or entry.get('GameMode', '').lower() == 'cqc': + if 'cqc-loadgame-events' in trace_on: + logger.trace(f'loadgame to cqc: {entry}') + + self.mode = 'CQC' + + else: + self.mode = entry.get('GameMode') + self.group = entry.get('Group') self.planet = None self.system = None diff --git a/plug.py b/plug.py index af4a50ac..2899c237 100644 --- a/plug.py +++ b/plug.py @@ -1,6 +1,7 @@ """ Plugin hooks for EDMC - Ian Norton, Jonathan Harris """ +import copy import importlib import logging import operator @@ -272,6 +273,31 @@ def notify_journal_entry(cmdr, is_beta, system, station, entry, state): return error +def notify_journal_entry_cqc(cmdr, is_beta, entry, state): + """ + Send a journal entry to each plugin. + :param cmdr: The Cmdr name, or None if not yet known + :param entry: The journal entry as a dictionary + :param state: A dictionary containing info about the Cmdr, current ship and cargo + :param is_beta: whether the player is in a Beta universe. + :returns: Error message from the first plugin that returns one (if any) + """ + + error = None + for plugin in PLUGINS: + cqc_callback = plugin._get_func('journal_entry_cqc') + if cqc_callback is not None and callable(cqc_callback): + try: + # Pass a copy of the journal entry in case the callee modifies it + newerror = cqc_callback(cmdr, is_beta, copy.deepcopy(entry), copy.deepcopy(state)) + error = error or newerror + + except Exception: + logger.exception(f'Plugin "{plugin.name}" failed while handling CQC mode journal entry') + + return error + + def notify_dashboard_entry(cmdr, is_beta, entry): """ Send a status entry to each plugin.