@@ -383,13 +383,14 @@ class LocksView : Subview
383
383
{
384
384
[ NonSerialized ] private bool isBusy ;
385
385
386
+ [ SerializeField ] private bool currentRemoteHasUpdate ;
386
387
[ SerializeField ] private bool currentStatusEntriesHasUpdate ;
387
388
[ SerializeField ] private bool currentLocksHasUpdate ;
388
- [ SerializeField ] private bool currentUserHasUpdate ;
389
+ [ SerializeField ] private bool keychainHasUpdate ;
389
390
[ SerializeField ] private LocksControl locksControl ;
391
+ [ SerializeField ] private CacheUpdateEvent lastCurrentRemoteChangedEvent ;
390
392
[ SerializeField ] private CacheUpdateEvent lastLocksChangedEvent ;
391
393
[ SerializeField ] private CacheUpdateEvent lastStatusEntriesChangedEvent ;
392
- [ SerializeField ] private CacheUpdateEvent lastUserChangedEvent ;
393
394
[ SerializeField ] private List < GitLock > lockedFiles = new List < GitLock > ( ) ;
394
395
[ SerializeField ] private List < GitStatusEntry > gitStatusEntries = new List < GitStatusEntry > ( ) ;
395
396
[ SerializeField ] private string currentUsername ;
@@ -407,6 +408,7 @@ public override void OnEnable()
407
408
408
409
AttachHandlers ( Repository ) ;
409
410
ValidateCachedData ( Repository ) ;
411
+ KeychainConnectionsChanged ( ) ;
410
412
}
411
413
412
414
public override void OnDisable ( )
@@ -523,9 +525,10 @@ private void AttachHandlers(IRepository repository)
523
525
return ;
524
526
}
525
527
528
+ Platform . Keychain . ConnectionsChanged += KeychainConnectionsChanged ;
529
+ repository . CurrentRemoteChanged += RepositoryOnCurrentRemoteChanged ;
526
530
repository . LocksChanged += RepositoryOnLocksChanged ;
527
- repository . LocksChanged += RepositoryOnStatusEntriesChanged ;
528
- User . Changed += UserOnChanged ;
531
+ repository . StatusEntriesChanged += RepositoryOnStatusEntriesChanged ;
529
532
}
530
533
531
534
private void DetachHandlers ( IRepository repository )
@@ -535,9 +538,20 @@ private void DetachHandlers(IRepository repository)
535
538
return ;
536
539
}
537
540
541
+ Platform . Keychain . ConnectionsChanged -= KeychainConnectionsChanged ;
542
+ repository . CurrentRemoteChanged -= RepositoryOnCurrentRemoteChanged ;
538
543
repository . LocksChanged -= RepositoryOnLocksChanged ;
539
- repository . LocksChanged -= RepositoryOnStatusEntriesChanged ;
540
- User . Changed -= UserOnChanged ;
544
+ repository . StatusEntriesChanged -= RepositoryOnStatusEntriesChanged ;
545
+ }
546
+
547
+ private void RepositoryOnCurrentRemoteChanged ( CacheUpdateEvent cacheUpdateEvent )
548
+ {
549
+ if ( ! lastCurrentRemoteChangedEvent . Equals ( cacheUpdateEvent ) )
550
+ {
551
+ lastCurrentRemoteChangedEvent = cacheUpdateEvent ;
552
+ currentRemoteHasUpdate = true ;
553
+ Redraw ( ) ;
554
+ }
541
555
}
542
556
543
557
private void RepositoryOnLocksChanged ( CacheUpdateEvent cacheUpdateEvent )
@@ -560,21 +574,17 @@ private void RepositoryOnStatusEntriesChanged(CacheUpdateEvent cacheUpdateEvent)
560
574
}
561
575
}
562
576
563
- private void UserOnChanged ( CacheUpdateEvent cacheUpdateEvent )
577
+ private void KeychainConnectionsChanged ( )
564
578
{
565
- if ( ! lastUserChangedEvent . Equals ( cacheUpdateEvent ) )
566
- {
567
- lastUserChangedEvent = cacheUpdateEvent ;
568
- currentUserHasUpdate = true ;
569
- Redraw ( ) ;
570
- }
579
+ keychainHasUpdate = true ;
580
+ Redraw ( ) ;
571
581
}
572
582
573
583
private void ValidateCachedData ( IRepository repository )
574
584
{
585
+ repository . CheckAndRaiseEventsIfCacheNewer ( CacheType . RepositoryInfo , lastCurrentRemoteChangedEvent ) ;
575
586
repository . CheckAndRaiseEventsIfCacheNewer ( CacheType . GitLocks , lastLocksChangedEvent ) ;
576
587
repository . CheckAndRaiseEventsIfCacheNewer ( CacheType . GitStatus , lastStatusEntriesChangedEvent ) ;
577
- User . CheckAndRaiseEventsIfCacheNewer ( CacheType . GitUser , lastUserChangedEvent ) ;
578
588
}
579
589
580
590
private void MaybeUpdateData ( )
@@ -584,15 +594,33 @@ private void MaybeUpdateData()
584
594
return ;
585
595
}
586
596
587
- if ( currentUserHasUpdate )
597
+ if ( keychainHasUpdate || currentRemoteHasUpdate )
588
598
{
589
- //TODO: ONE_USER_LOGIN This assumes only ever one user can login
590
- var keychainConnection = Platform . Keychain . Connections . FirstOrDefault ( ) ;
591
- if ( keychainConnection != null )
592
- currentUsername = keychainConnection . Username ;
599
+ Connection [ ] connections ;
600
+ if ( HasRepository && ! string . IsNullOrEmpty ( Repository . CloneUrl ) )
601
+ {
602
+ var host = Repository . CloneUrl
603
+ . ToRepositoryUri ( )
604
+ . GetComponents ( UriComponents . Host , UriFormat . SafeUnescaped ) ;
605
+
606
+ connections = Platform . Keychain . Connections . OrderByDescending ( x => x . Host == host ) . ToArray ( ) ;
607
+ }
608
+ else
609
+ {
610
+ connections = Platform . Keychain . Connections . OrderByDescending ( HostAddress . IsGitHubDotCom ) . ToArray ( ) ;
611
+ }
612
+
613
+ if ( connections . Any ( ) )
614
+ {
615
+ currentUsername = connections . First ( ) . Username ;
616
+ }
593
617
else
618
+ {
594
619
currentUsername = "" ;
595
- currentUserHasUpdate = false ;
620
+ }
621
+
622
+ keychainHasUpdate = false ;
623
+ currentRemoteHasUpdate = false ;
596
624
}
597
625
598
626
if ( currentLocksHasUpdate )
0 commit comments