@@ -24,15 +24,13 @@ public class PullRequestStatusBarManager : IPullRequestStatusBarManager
2424 static readonly ILogger log = LogManager . ForContext < PullRequestStatusBarManager > ( ) ;
2525 const string StatusBarPartName = "PART_SccStatusBarHost" ;
2626
27- readonly IVSGitExt gitExt ;
27+ readonly Lazy < IVSGitExt > gitExt ;
2828 readonly Lazy < IPullRequestSessionManager > pullRequestSessionManager ;
2929 readonly IUsageTracker usageTracker ;
3030 readonly IGitHubServiceProvider serviceProvider ;
3131
32- Window mainWindow ;
33-
3432 [ ImportingConstructor ]
35- public PullRequestStatusBarManager ( IVSGitExt gitExt , Lazy < IPullRequestSessionManager > pullRequestSessionManager ,
33+ public PullRequestStatusBarManager ( Lazy < IVSGitExt > gitExt , Lazy < IPullRequestSessionManager > pullRequestSessionManager ,
3634 IUsageTracker usageTracker , IGitHubServiceProvider serviceProvider )
3735 {
3836 this . gitExt = gitExt ;
@@ -45,23 +43,24 @@ public PullRequestStatusBarManager(IVSGitExt gitExt, Lazy<IPullRequestSessionMan
4543 /// Lazily initialize when user enters the context of a GitHub repository.
4644 /// </summary>
4745 /// <param name="window">Visual Studio's main window.</param>
48- public void Initialize ( Window window )
46+ public async Task InitializeAsync ( )
4947 {
50- mainWindow = window ;
48+ await ThreadingHelper . SwitchToMainThreadAsync ( ) ;
49+
5150 OnActiveRepositoriesChanged ( ) ;
52- gitExt . ActiveRepositoriesChanged += OnActiveRepositoriesChanged ;
51+ gitExt . Value . ActiveRepositoriesChanged += OnActiveRepositoriesChanged ;
5352 }
5453
5554 void OnActiveRepositoriesChanged ( )
5655 {
57- if ( gitExt . ActiveRepositories . Count > 0 )
56+ if ( gitExt . Value . ActiveRepositories . Count > 0 )
5857 {
59- InitializeAsync ( ) . Forget ( ) ;
60- gitExt . ActiveRepositoriesChanged -= OnActiveRepositoriesChanged ;
58+ StartShowingStatus ( ) . Forget ( ) ;
59+ gitExt . Value . ActiveRepositoriesChanged -= OnActiveRepositoriesChanged ;
6160 }
6261 }
6362
64- async Task InitializeAsync ( )
63+ async Task StartShowingStatus ( )
6564 {
6665 try
6766 {
@@ -103,7 +102,7 @@ PullRequestStatusViewModel CreatePullRequestStatusViewModel(IPullRequestModel pu
103102
104103 void ShowStatus ( PullRequestStatusViewModel pullRequestStatusViewModel = null )
105104 {
106- var statusBar = FindSccStatusBar ( ) ;
105+ var statusBar = FindSccStatusBar ( Application . Current . MainWindow ) ;
107106 if ( statusBar != null )
108107 {
109108 var githubStatusBar = Find < PullRequestStatusView > ( statusBar ) ;
@@ -134,7 +133,7 @@ static T Find<T>(StatusBar statusBar)
134133 return default ( T ) ;
135134 }
136135
137- StatusBar FindSccStatusBar ( )
136+ StatusBar FindSccStatusBar ( Window mainWindow )
138137 {
139138 var contentControl = mainWindow ? . Template ? . FindName ( StatusBarPartName , mainWindow ) as ContentControl ;
140139 return contentControl ? . Content as StatusBar ;
0 commit comments