77using VisualStudioDiscordRPC . Shared . Nests ;
88using VisualStudioDiscordRPC . Shared . Nests . Base ;
99using VisualStudioDiscordRPC . Shared . Observers ;
10+ using VisualStudioDiscordRPC . Shared . Plugs . TimerPlugs ;
1011
1112namespace VisualStudioDiscordRPC . Shared
1213{
@@ -25,6 +26,7 @@ public class DiscordRpcController
2526 private readonly LocalizationService _localizationService ;
2627 private readonly SettingsService _settingsService ;
2728 private readonly VsObserver _vsObserver ;
29+ private readonly PlugService _plugService ;
2830
2931 private readonly RichPresence _sharedRichPresence ;
3032 private readonly object _richPresenceSync = new object ( ) ;
@@ -103,6 +105,7 @@ public DiscordRpcController(int updateMillisecondsTimeout)
103105 {
104106 _settingsService = ServiceRepository . Default . GetService < SettingsService > ( ) ;
105107 _vsObserver = ServiceRepository . Default . GetService < VsObserver > ( ) ;
108+ _plugService = ServiceRepository . Default . GetService < PlugService > ( ) ;
106109
107110 var applicationId = _settingsService . Read < string > ( SettingsKeys . ApplicationID ) ;
108111
@@ -223,6 +226,8 @@ private void OnTextEditorLineChanged(EnvDTE.TextPoint startPoint, EnvDTE.TextPoi
223226 {
224227 if ( _enabled && _isIdling )
225228 SetDirty ( ) ;
229+ else
230+ _lastDirtyTime = DateTime . Now ;
226231 }
227232
228233 public void RefreshAll ( )
@@ -237,12 +242,17 @@ public void RefreshAll()
237242
238243 private void SetDirty ( )
239244 {
245+ bool wasIdling = _isIdling ;
246+
240247 lock ( _dirtyFlagSync )
241248 {
242249 _isDirty = true ;
243250 _isIdling = false ;
244251 _lastDirtyTime = DateTime . Now ;
245252 }
253+
254+ if ( wasIdling )
255+ OnEndIdling ( ) ;
246256 }
247257
248258 private void SendRichPresenceData ( )
@@ -304,6 +314,19 @@ private void OnRpcUpdate()
304314 private void OnIdle ( )
305315 {
306316 _discordRpcClient . SetPresence ( IdlingRichPresence ) ;
317+
318+ }
319+
320+ private void OnEndIdling ( )
321+ {
322+ bool resetTimersAfterIdling = _settingsService . Read < bool > ( SettingsKeys . ResetTimersAfterIdling ) ;
323+ if ( ! resetTimersAfterIdling )
324+ return ;
325+
326+ var timerPlugs = _plugService . GetPlugsOfType < BaseTimerPlug > ( ) ;
327+
328+ foreach ( var timerPlug in timerPlugs )
329+ timerPlug . SyncTimestamp ( ) ;
307330 }
308331 }
309332}
0 commit comments