1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 00:07:14 +03:00

Send ShutDown event on game close

This commit is contained in:
Jonathan Harris 2017-11-26 14:25:38 +00:00
parent e3323f8f6f
commit f65d2623ac
3 changed files with 23 additions and 6 deletions

View File

@ -114,7 +114,9 @@ Your events all get called on the main tkinter loop so be sure not to block for
This gets called when EDMC sees a new entry in the game's journal. `state` is a dictionary containing information about the Cmdr and their ship and cargo (including the effect of the current journal entry).
A special 'StartUp' entry is sent if EDMC is started while the game is already running. In this case you won't receive initial events such as "LoadGame", "Rank", "Location", etc. However the `state` dictionary will reflect the cumulative effect of these missed events.
A special "StartUp" entry is sent if EDMC is started while the game is already running. In this case you won't receive initial events such as "LoadGame", "Rank", "Location", etc. However the `state` dictionary will reflect the cumulative effect of these missed events.
Similarly, a special "ShutDown" entry is sent when the game is quitted while EDMC is running. This event is not sent when EDMC is running on a different machine or when quitting to the main menu, so you should not *rely* on receiving this event.
```python
def journal_entry(cmdr, is_beta, system, station, entry, state):

View File

@ -89,6 +89,8 @@ class EDLogs(FileSystemEventHandler):
# If 3 we need to inject a special 'StartUp' event since consumers won't see the LoadGame event.
self.live = False
self.game_was_running = False # For generation the "ShutDown" event
# Context for journal handling
self.version = None
self.is_beta = False
@ -217,8 +219,10 @@ class EDLogs(FileSystemEventHandler):
else:
loghandle = None
self.game_was_running = self.game_running()
if self.live:
if self.game_running():
if self.game_was_running:
self.event_queue.append('{ "timestamp":"%s", "event":"StartUp" }' % strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()))
else:
self.event_queue.append(None) # Generate null event to update the display (with possibly out-of-date info)
@ -264,6 +268,15 @@ class EDLogs(FileSystemEventHandler):
if threading.current_thread() != self.thread:
return # Terminate
if self.game_was_running:
if not self.game_running():
self.event_queue.append('{ "timestamp":"%s", "event":"ShutDown" }' % strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()))
self.root.event_generate('<<JournalEvent>>', when="tail")
self.game_was_running = False
else:
self.game_was_running = self.game_running()
def parse_entry(self, line):
if line is None:
return { 'event': None } # Fake startup event

View File

@ -51,8 +51,7 @@ def plugin_start():
def plugin_stop():
# Send any unsent events
if this.events:
call()
call()
# Signal thread to close and wait for it
this.queue.put(None)
this.thread.join()
@ -136,7 +135,7 @@ def credentials(cmdr):
def journal_entry(cmdr, is_beta, system, station, entry, state):
# Send any unsent events when switching accounts
if cmdr and cmdr != this.cmdr and this.events:
if cmdr and cmdr != this.cmdr:
call()
this.cmdr = cmdr
@ -293,7 +292,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
]))
if len(this.events) > old_events:
if entry['event'] == 'ShutDown' or len(this.events) > old_events:
# We have new event(s) so send to Inara
# Send cargo and materials if changed
@ -556,6 +555,9 @@ def add_event(name, timestamp, data):
# Queue a call to Inara, handled in Worker thread
def call(callback=None):
if not this.events:
return
data = OrderedDict([
('header', OrderedDict([
('appName', applongname),