@@ -20,8 +20,8 @@ public class EliteDangerousApi
2020 private readonly StatusTracker _statusTracker = new ( ) ;
2121
2222 private readonly List < Action < FileInfo > > _journalChangedHandlers = [ ] ;
23- private readonly List < Action < IEvent > > _typedGlobalEventHandlers = [ ] ;
24- private readonly List < Action < ( string eventName , string json ) > > _untypedGlobalEventHandlers = [ ] ;
23+ private readonly List < Action < ( IEvent , EventContext ) > > _typedGlobalEventHandlers = [ ] ;
24+ private readonly List < Action < ( string eventName , string json , EventContext ) > > _untypedGlobalEventHandlers = [ ] ;
2525 private readonly Dictionary < string , List < Action < IEvent > > > _typedEventHandlers = new ( StringComparer . OrdinalIgnoreCase ) ;
2626 private readonly Dictionary < string , Type > _eventTypes = typeof ( IEvent )
2727 . Assembly
@@ -58,14 +58,14 @@ public void Start()
5858 _journalWatcher . OnContentChanged ( ( json ) =>
5959 {
6060 JournalUtils . PrepareLocalisations ( json ) ;
61- Invoke ( json ) ;
61+ Invoke ( json , new EventContext { SourceFile = _journalWatcher . CurrentFile . Name } ) ;
6262 } ) ;
6363 _journalWatcher . OnFileChanged ( file =>
6464 {
6565 foreach ( var handler in _journalChangedHandlers )
6666 SafeInvoke . Invoke ( "handling journal switch" , handler , file ) ;
6767 } ) ;
68- _statusWatchers . ForEach ( w => w . OnContentChanged ( Invoke ) ) ;
68+ _statusWatchers . ForEach ( w => w . OnContentChanged ( content => Invoke ( content , new EventContext { SourceFile = w . CurrentFile . Name } ) ) ) ;
6969 _bindingsPresetsWatcher . OnContentChanged ( HandleBindingsPreset ) ;
7070
7171 _statusWatchers . ForEach ( w => w . StartWatching ( ) ) ;
@@ -130,27 +130,27 @@ public void OnJson(string eventName, Action<(string eventName, string json)> han
130130 /// <summary>
131131 /// Listens for all events which are typed.
132132 /// </summary>
133- public void OnAll ( Action < IEvent > handler )
133+ public void OnAll ( Action < ( IEvent , EventContext ) > handler )
134134 {
135135 _typedGlobalEventHandlers . Add ( handler ) ;
136136 }
137137
138138 /// <summary>
139139 /// Listens for all events with raw JSON
140140 /// </summary>
141- public void OnAllJson ( Action < ( string eventName , string json ) > handler )
141+ public void OnAllJson ( Action < ( string eventName , string json , EventContext eventContext ) > handler )
142142 {
143143 _untypedGlobalEventHandlers . Add ( handler ) ;
144144 }
145145
146- public void Invoke ( IEvent @event )
146+ public void Invoke ( IEvent @event , EventContext eventContext )
147147 {
148- Invoke ( JsonConvert . SerializeObject ( @event , JsonUtils . SerializerSettings ) , @event ) ;
148+ Invoke ( JsonConvert . SerializeObject ( @event , JsonUtils . SerializerSettings ) , @event , eventContext ) ;
149149 }
150150
151- public void Invoke ( string json ) => Invoke ( json , null ) ;
151+ public void Invoke ( string json , EventContext eventContext ) => Invoke ( json , null , eventContext ) ;
152152
153- internal void Invoke ( string json , IEvent ? @event )
153+ internal void Invoke ( string json , IEvent ? @event , EventContext eventContext )
154154 {
155155 var eventName = JsonUtils . GetEventName ( json ) ;
156156 if ( string . IsNullOrEmpty ( eventName ) )
@@ -194,7 +194,7 @@ internal void Invoke(string json, IEvent? @event)
194194
195195 // invoke global untyped handlers
196196 foreach ( var handler in _untypedGlobalEventHandlers )
197- SafeInvoke . Invoke ( $ "{ eventName } hander", handler , ( eventName , json ) ) ;
197+ SafeInvoke . Invoke ( $ "{ eventName } hander", handler , ( eventName , json , eventContext ) ) ;
198198
199199 if ( @event != null )
200200 {
@@ -207,7 +207,7 @@ internal void Invoke(string json, IEvent? @event)
207207
208208 // invoke global typed handlers
209209 foreach ( var handler in _typedGlobalEventHandlers )
210- SafeInvoke . Invoke ( $ "{ eventName } hander", handler , @event ) ;
210+ SafeInvoke . Invoke ( $ "{ eventName } hander", handler , ( @event , eventContext ) ) ;
211211 }
212212
213213 // After Status event is processed and variables are set, invoke change events
@@ -230,7 +230,7 @@ internal void Invoke(string json, IEvent? @event)
230230
231231 // invoke global untyped handlers for synthetic event
232232 foreach ( var handler in _untypedGlobalEventHandlers )
233- SafeInvoke . Invoke ( $ "{ syntheticEventName } handler", handler , ( syntheticEventName , syntheticJson ) ) ;
233+ SafeInvoke . Invoke ( $ "{ syntheticEventName } handler", handler , ( syntheticEventName , syntheticJson , eventContext ) ) ;
234234 }
235235
236236 // Always update the tracker state, even if no fields changed
0 commit comments