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

Commit 91fcd67

Browse files
committed
Don't change button visibility if repo has changed
There can be delay before IsAGitHubRepo returns its result. If the repository changes before the call returns, the button can end up with the visibility for the wrong repository. This fix only sets the button visibility if the repository hasn't changed. Button is invalidated multiple times, so one of them returns the visibility for the correct repository.
1 parent b864050 commit 91fcd67

File tree

7 files changed

+25
-16
lines changed

7 files changed

+25
-16
lines changed

src/GitHub.TeamFoundation.14/Base/EnsureLoggedInSection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async Task CheckLogin()
4545
if (ActiveRepo == null || ActiveRepoUri == null)
4646
return;
4747

48-
var isgithub = await IsAGitHubRepo();
48+
var isgithub = await IsAGitHubRepo(ActiveRepoUri);
4949
if (!isgithub)
5050
return;
5151

src/GitHub.TeamFoundation.14/Base/TeamExplorerNavigationItemBase.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
using System.Drawing;
44
using GitHub.Api;
55
using GitHub.Extensions;
6+
using GitHub.Logging;
67
using GitHub.Services;
78
using GitHub.UI;
89
using GitHub.VisualStudio.Helpers;
910
using Microsoft.TeamFoundation.Controls;
1011
using Microsoft.VisualStudio.PlatformUI;
12+
using Serilog;
1113

1214
namespace GitHub.VisualStudio.Base
1315
{
1416
public class TeamExplorerNavigationItemBase : TeamExplorerItemBase, ITeamExplorerNavigationItem2
1517
{
18+
static readonly ILogger log = LogManager.ForContext<TeamExplorerNavigationItemBase>();
19+
1620
readonly Octicon octicon;
1721

1822
public TeamExplorerNavigationItemBase(IGitHubServiceProvider serviceProvider,
@@ -38,7 +42,16 @@ public TeamExplorerNavigationItemBase(IGitHubServiceProvider serviceProvider,
3842
public override async void Invalidate()
3943
{
4044
IsVisible = false;
41-
IsVisible = await IsAGitHubRepo();
45+
46+
var uri = ActiveRepoUri;
47+
var isVisible = await IsAGitHubRepo(uri);
48+
if (ActiveRepoUri != uri)
49+
{
50+
log.Information("Not setting button visibility because repository changed from {BeforeUrl} to {AfterUrl}", uri, ActiveRepoUri);
51+
return;
52+
}
53+
54+
IsVisible = isVisible;
4255
}
4356

4457
void OnThemeChanged()

src/GitHub.TeamFoundation.14/Home/ForkNavigationItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public override async void Invalidate()
9797
{
9898
IsVisible = false;
9999

100-
if ((packageSettings?.ForkButton ?? false) && await IsAGitHubDotComRepo())
100+
if ((packageSettings?.ForkButton ?? false) && await IsAGitHubDotComRepo(ActiveRepoUri))
101101
{
102102
var connection = await ConnectionManager.GetConnection(ActiveRepo);
103103
IsVisible = connection?.IsLoggedIn ?? false;

src/GitHub.TeamFoundation.14/Home/GitHubHomeSection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected async override void RepoChanged()
6464

6565
base.RepoChanged();
6666

67-
IsVisible = await IsAGitHubRepo();
67+
IsVisible = await IsAGitHubRepo(ActiveRepoUri);
6868

6969
if (IsVisible)
7070
{
@@ -93,7 +93,7 @@ protected async override void RepoChanged()
9393

9494
public override async void Refresh()
9595
{
96-
IsVisible = await IsAGitHubRepo();
96+
IsVisible = await IsAGitHubRepo(ActiveRepoUri);
9797
if (IsVisible)
9898
{
9999
IsLoggedIn = await IsUserAuthenticated();

src/GitHub.TeamFoundation.14/Home/IssuesNavigationItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public override async void Invalidate()
4040
{
4141
IsVisible = false;
4242

43-
var visible = await IsAGitHubRepo();
43+
var visible = await IsAGitHubRepo(ActiveRepoUri);
4444
if (visible)
4545
{
4646
var repo = await SimpleApiClient.GetRepository();

src/GitHub.TeamFoundation.14/Home/WikiNavigationItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override void Execute()
3838

3939
public override async void Invalidate()
4040
{
41-
var visible = await IsAGitHubRepo();
41+
var visible = await IsAGitHubRepo(ActiveRepoUri);
4242
if (visible)
4343
{
4444
var repo = await SimpleApiClient.GetRepository();

src/GitHub.VisualStudio.UI/Base/TeamExplorerItemBase.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,8 @@ protected virtual void RepoChanged()
123123
}
124124
}
125125

126-
protected async Task<RepositoryOrigin> GetRepositoryOrigin()
126+
protected async Task<RepositoryOrigin> GetRepositoryOrigin(UriString uri)
127127
{
128-
if (ActiveRepo == null)
129-
return RepositoryOrigin.NonGitRepository;
130-
131-
var uri = ActiveRepoUri;
132128
if (uri == null)
133129
return RepositoryOrigin.Other;
134130

@@ -154,15 +150,15 @@ protected async Task<RepositoryOrigin> GetRepositoryOrigin()
154150
return RepositoryOrigin.Other;
155151
}
156152

157-
protected async Task<bool> IsAGitHubRepo()
153+
protected async Task<bool> IsAGitHubRepo(UriString uri)
158154
{
159-
var origin = await GetRepositoryOrigin();
155+
var origin = await GetRepositoryOrigin(uri);
160156
return origin == RepositoryOrigin.DotCom || origin == RepositoryOrigin.Enterprise;
161157
}
162158

163-
protected async Task<bool> IsAGitHubDotComRepo()
159+
protected async Task<bool> IsAGitHubDotComRepo(UriString uri)
164160
{
165-
var origin = await GetRepositoryOrigin();
161+
var origin = await GetRepositoryOrigin(uri);
166162
return origin == RepositoryOrigin.DotCom;
167163
}
168164

0 commit comments

Comments
 (0)