From 25ed649b7ae973a990c38ff6438eb16ff7660d1e Mon Sep 17 00:00:00 2001
From: Athanasius <Athanasius@miggy.org>
Date: Tue, 6 Dec 2022 15:34:12 +0000
Subject: [PATCH 1/2] monitor/NavRoute: Load NavRoute after catching_up ends.

This is to allow restart of EDMarketConnector whilst the game is running
to have `state['NavRoute']` hold data when the synthetic `StartUp` event
is passed to plugins.

NB: Probably need to note this in PLUGINS.md
---
 monitor.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/monitor.py b/monitor.py
index d8c5707e..4a7a2369 100644
--- a/monitor.py
+++ b/monitor.py
@@ -397,6 +397,12 @@ class EDLogs(FileSystemEventHandler):  # type: ignore # See below
                 except Exception as ex:
                     logger.debug(f'Invalid journal entry:\n{line!r}\n', exc_info=ex)
 
+            # One-shot attempt to read in latest NavRoute, if present
+            navroute_data = self._parse_navroute_file()
+            if navroute_data is not None:
+                # If it's NavRouteClear contents, just keep those anyway.
+                self.state['NavRoute'] = navroute_data
+
             self.catching_up = False
             log_pos = loghandle.tell()
 

From 3e15aa0fe6ad58d9a465ae0690f565ca20c270a4 Mon Sep 17 00:00:00 2001
From: Athanasius <Athanasius@miggy.org>
Date: Tue, 6 Dec 2022 15:42:59 +0000
Subject: [PATCH 2/2] PLUGINS.md: More fully document `state['NavRoute'`

This includes the "catching up" load of the data.
---
 PLUGINS.md | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/PLUGINS.md b/PLUGINS.md
index 011f1224..97f2275a 100644
--- a/PLUGINS.md
+++ b/PLUGINS.md
@@ -597,7 +597,7 @@ This gets called when EDMarketConnector sees a new entry in the game's journal.
 Content of `state` (updated to the current journal entry):
 
 | Field                |            Type             | Description                                                                                                     |
-| :------------------- | :-------------------------: | :-------------------------------------------------------------------------------------------------------------- |
+| :------------------- | :-------------------------: |:----------------------------------------------------------------------------------------------------------------|
 | `GameLanguage`       |       `Optional[str]`       | `language` value from `Fileheader` event.                                                                       |
 | `GameVersion`        |       `Optional[str]`       | `version` value from `Fileheader` event.                                                                        |
 | `GameBuild`          |       `Optional[str]`       | `build` value from `Fileheader` event.                                                                          |
@@ -626,7 +626,7 @@ Content of `state` (updated to the current journal entry):
 | `ModulesValue`       |            `int`            | Value of the current ship's modules                                                                             |
 | `Rebuy`              |            `int`            | Current ship's rebuy cost                                                                                       |
 | `Modules`            |           `dict`            | Currently fitted modules                                                                                        |
-| `NavRoute`           |           `dict`            | Last plotted multi-hop route                                                                                    |
+| `NavRoute`           |           `dict`            | Last plotted multi-hop route[1]                                                                                 |
 | `ModuleInfo`         |           `dict`            | Last loaded ModulesInfo.json data                                                                               |
 | `IsDocked`           |           `bool`            | Whether the Cmdr is currently docked *in their own ship*.                                                       |
 | `OnFoot`             |           `bool`            | Whether the Cmdr is on foot                                                                                     |
@@ -638,15 +638,29 @@ Content of `state` (updated to the current journal entry):
 | `BackpackJSON`       |           `dict`            | Content of Backpack.json as of last read.                                                                       |
 | `ShipLockerJSON`     |           `dict`            | Content of ShipLocker.json as of last read.                                                                     |
 | `SuitCurrent`        |           `dict`            | CAPI-returned data of currently worn suit.  NB: May be `None` if no data.                                       |
-| `Suits`              |          `dict`[1]          | CAPI-returned data of owned suits.  NB: May be `None` if no data.                                               |
+| `Suits`              |          `dict`[2]          | CAPI-returned data of owned suits.  NB: May be `None` if no data.                                               |
 | `SuitLoadoutCurrent` |           `dict`            | CAPI-returned data of current Suit Loadout.  NB: May be `None` if no data.                                      |
-| `SuitLoadouts`       |          `dict`[1]          | CAPI-returned data of all Suit Loadouts.  NB: May be `None` if no data.                                         |
+| `SuitLoadouts`       |          `dict`[2]          | CAPI-returned data of all Suit Loadouts.  NB: May be `None` if no data.                                         |
 | `Taxi`               |      `Optional[bool]`       | Whether or not we're currently in a taxi. NB: This is best effort with what the journals provide.               |
 | `Dropship`           |      `Optional[bool]`       | Whether or not the above taxi is a Dropship                                                                     |
 | `Body`               |       `Optional[str]`       | The body we're currently on / in the SOI of                                                                     |
 | `BodyType`           |       `Optional[str]`       | The type of body that `Body` refers to                                                                          |
 
-[1] - Some data from the CAPI is sometimes returned as a `list` (when all 
+[1] - Contents of `NavRoute` not changed if a `NavRouteClear` event is seen,
+but plugins will see the `NavRouteClear` event.
+
+If EDMarketConnector is restarted whilst the game is running then
+`NavRoute` will be populated with current 'NavRoute.json' contents (assuming
+that the file exists).  Thus `NavRoute` will have the data when the
+synthetic `StartUp` event is sent to plugins.  NB: If the contents of the file
+indicate a `NavRouteClear` then that's what will be passed.
+
+If the *game* is restarted then `Fileheader` in the new Journal file will
+cause `state['NavRoute'] = None`, but if you open the galaxy map in-game and
+cause an automatic re-plot of last route, then a new `NavRoute` event will
+also be generated and passed to plugins.
+
+[2] - Some data from the CAPI is sometimes returned as a `list` (when all 
 members are present) and other times as an integer-keyed `dict` (when at 
 least one member is missing, so the indices are not contiguous).  We choose to
 always convert to the integer-keyed `dict` form so that code utilising the data
@@ -733,6 +747,14 @@ In general on-foot, including being in a taxi, might not set this 100%
 correctly.  Its main use in core code is to detect being docked so as to send
 any stored EDDN messages due to "Delay sending until docked" option.
 
+
+New in version 5.7.0:
+
+`state['NavRoute']` will be populated from the file, if present, if you
+re-start EDMarketConnector.  That will be present when plugins are invoked
+with the synthetic `StartUp` event.  NB: Might just be a `NavRouteClear` event
+if that's what was in the file.
+
 ___
 
 ##### Synthetic Events