Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 8887a83

Browse files
committed
Ensure that the GitHubPaneViewModel is initalized.
- Renamed `IGitHubToolWindowManager.ShowHomePane` to `ShowGitHubPane` because the latter is what we call it these days - Make `IGitHubToolWindowManager.ShowGitHubPane` async to make sure that `GitHubPaneViewModel.InitializeAsync` has finished before passing back a refrence to the `GitHubPaneViewModel` - Make the methods that call `IGitHubToolWindowManager.ShowGitHubPane` `void async` with logging when they fail
1 parent 8ca54d7 commit 8887a83

File tree

6 files changed

+47
-26
lines changed

6 files changed

+47
-26
lines changed

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ protected override Task InitializeAsync(CancellationToken cancellationToken, IPr
156156
return Task.CompletedTask;
157157
}
158158

159-
public IGitHubPaneViewModel ShowHomePane()
159+
public async Task<IGitHubPaneViewModel> ShowGitHubPane()
160160
{
161161
var pane = ShowToolWindow(new Guid(GitHubPane.GitHubPaneGuid));
162162
if (pane == null)
@@ -166,7 +166,10 @@ public IGitHubPaneViewModel ShowHomePane()
166166
{
167167
ErrorHandler.Failed(frame.Show());
168168
}
169-
return (IGitHubPaneViewModel)((FrameworkElement)pane.Content).DataContext;
169+
170+
var viewModel = (IGitHubPaneViewModel)((FrameworkElement)pane.Content).DataContext;
171+
await viewModel.InitializeAsync(pane);
172+
return viewModel;
170173
}
171174

172175
static ToolWindowPane ShowToolWindow(Guid windowGuid)

src/GitHub.VisualStudio/IServiceProviderPackage.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.InteropServices;
3+
using System.Threading.Tasks;
34
using GitHub.ViewModels.GitHubPane;
45

56
namespace GitHub.VisualStudio
@@ -12,6 +13,6 @@ public interface IServiceProviderPackage : IServiceProvider, Microsoft.VisualStu
1213
[ComVisible(true)]
1314
public interface IGitHubToolWindowManager
1415
{
15-
IGitHubPaneViewModel ShowHomePane();
16+
Task<IGitHubPaneViewModel> ShowGitHubPane();
1617
}
1718
}
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
using GitHub.Exports;
2-
using GitHub.UI;
3-
using GitHub.VisualStudio.UI;
4-
using System;
5-
using GitHub.Services;
1+
using System;
2+
using GitHub.Exports;
63
using GitHub.Extensions;
4+
using GitHub.Logging;
5+
using GitHub.Services;
6+
using Serilog;
77

88
namespace GitHub.VisualStudio.Menus
99
{
1010
[ExportMenu(MenuType = MenuType.OpenPullRequests)]
1111
public class OpenPullRequests : MenuBase, IMenuHandler
1212
{
13+
static readonly ILogger log = LogManager.ForContext<ShowCurrentPullRequest>();
14+
1315
public OpenPullRequests(IGitHubServiceProvider serviceProvider)
1416
: base(serviceProvider)
1517
{
@@ -19,10 +21,17 @@ public OpenPullRequests(IGitHubServiceProvider serviceProvider)
1921
public Guid Guid => Guids.guidGitHubCmdSet;
2022
public int CmdId => PkgCmdIDList.openPullRequestsCommand;
2123

22-
public void Activate(object data = null)
24+
public async void Activate(object data = null)
2325
{
24-
var host = ServiceProvider.TryGetService<IGitHubToolWindowManager>().ShowHomePane();
25-
host.ShowPullRequests().Forget();
26+
try
27+
{
28+
var host = await ServiceProvider.TryGetService<IGitHubToolWindowManager>().ShowGitHubPane();
29+
await host.ShowPullRequests();
30+
}
31+
catch (Exception ex)
32+
{
33+
log.Error(ex, "Error showing opening pull requests");
34+
}
2635
}
2736
}
2837
}
Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
using System;
22
using GitHub.Exports;
3-
using GitHub.UI;
4-
using GitHub.Services;
53
using GitHub.Extensions;
6-
using GitHub.Models;
4+
using GitHub.Logging;
5+
using GitHub.Services;
6+
using Serilog;
77

88
namespace GitHub.VisualStudio.Menus
99
{
1010
[ExportMenu(MenuType = MenuType.OpenPullRequests)]
1111
public class ShowCurrentPullRequest : MenuBase, IMenuHandler
1212
{
13+
static readonly ILogger log = LogManager.ForContext<ShowCurrentPullRequest>();
14+
1315
public ShowCurrentPullRequest(IGitHubServiceProvider serviceProvider)
1416
: base(serviceProvider)
1517
{
@@ -19,19 +21,26 @@ public ShowCurrentPullRequest(IGitHubServiceProvider serviceProvider)
1921
public Guid Guid => Guids.guidGitHubCmdSet;
2022
public int CmdId => PkgCmdIDList.showCurrentPullRequestCommand;
2123

22-
public void Activate(object data = null)
24+
public async void Activate(object data = null)
2325
{
24-
var pullRequestSessionManager = ServiceProvider.ExportProvider.GetExportedValueOrDefault<IPullRequestSessionManager>();
25-
var session = pullRequestSessionManager?.CurrentSession;
26-
if (session == null)
26+
try
2727
{
28-
return; // No active PR session.
29-
}
28+
var pullRequestSessionManager = ServiceProvider.ExportProvider.GetExportedValueOrDefault<IPullRequestSessionManager>();
29+
var session = pullRequestSessionManager?.CurrentSession;
30+
if (session == null)
31+
{
32+
return; // No active PR session.
33+
}
3034

31-
var pullRequest = session.PullRequest;
32-
var manager = ServiceProvider.TryGetService<IGitHubToolWindowManager>();
33-
var host = manager.ShowHomePane();
34-
host.ShowPullRequest(session.RepositoryOwner, host.LocalRepository.Name, pullRequest.Number);
35+
var pullRequest = session.PullRequest;
36+
var manager = ServiceProvider.TryGetService<IGitHubToolWindowManager>();
37+
var host = await manager.ShowGitHubPane();
38+
await host.ShowPullRequest(session.RepositoryOwner, host.LocalRepository.Name, pullRequest.Number);
39+
}
40+
catch (Exception ex)
41+
{
42+
log.Error(ex, "Error showing current pull request");
43+
}
3544
}
3645
}
3746
}

src/GitHub.VisualStudio/Menus/ShowGitHubPane.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public ShowGitHubPane(IGitHubServiceProvider serviceProvider)
1717

1818
public void Activate(object data = null)
1919
{
20-
ServiceProvider.TryGetService<IGitHubToolWindowManager>()?.ShowHomePane();
20+
ServiceProvider.TryGetService<IGitHubToolWindowManager>()?.ShowGitHubPane();
2121
}
2222
}
2323
}

src/GitHub.VisualStudio/UI/GitHubPane.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public void Initialize(IServiceProvider serviceProvider)
8989

9090
var factory = provider.GetService<IViewViewModelFactory>();
9191
viewModel = provider.ExportProvider.GetExportedValue<IGitHubPaneViewModel>();
92-
viewModel.InitializeAsync(this).Forget();
9392

9493
View = factory.CreateView<IGitHubPaneViewModel>();
9594
View.DataContext = viewModel;

0 commit comments

Comments
 (0)