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

Commit 293ddd5

Browse files
authored
Merge pull request #992 from github/merge-2.2.0.11
Merge 2.2.0.11 into master
2 parents 2604bfd + 792acc4 commit 293ddd5

File tree

4 files changed

+41
-42
lines changed

4 files changed

+41
-42
lines changed

src/GitHub.App/Models/RepositoryHost.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public IObservable<AuthenticationResult> LogIn(string usernameOrEmail, string pa
122122
// Try to get an authorization token, save it, then get the user to log in:
123123
.SelectMany(fingerprint => ApiClient.GetOrCreateApplicationAuthenticationCode(interceptingTwoFactorChallengeHandler))
124124
.SelectMany(saveAuthorizationToken)
125-
.SelectMany(_ => GetUserFromApi())
125+
.SelectMany(_ => GetUserFromApiWithDelay())
126126
.Catch<UserAndScopes, ApiException>(firstTryEx =>
127127
{
128128
var exception = firstTryEx as AuthorizationException;
@@ -163,7 +163,7 @@ public IObservable<AuthenticationResult> LogIn(string usernameOrEmail, string pa
163163
})
164164
// Then save the authorization token (if there is one) and get the user:
165165
.SelectMany(saveAuthorizationToken)
166-
.SelectMany(_ => GetUserFromApi());
166+
.SelectMany(_ => GetUserFromApiWithDelay());
167167
}
168168

169169
return Observable.Throw<UserAndScopes>(firstTryEx);
@@ -178,7 +178,7 @@ public IObservable<AuthenticationResult> LogIn(string usernameOrEmail, string pa
178178
// instead of 404 to signal that it's not allowed. In the name of backwards compatibility we
179179
// test for both 404 (NotFoundException) and 403 (ForbiddenException) here.
180180
if (isEnterprise && (retryEx is NotFoundException || retryEx is ForbiddenException || retryEx.StatusCode == (HttpStatusCode)422))
181-
return GetUserFromApi();
181+
return GetUserFromApiWithDelay();
182182

183183
// Other errors are "real" so we pass them along:
184184
return Observable.Throw<UserAndScopes>(retryEx);
@@ -268,6 +268,15 @@ IObservable<AuthenticationResult> LoginWithApiUser(UserAndScopes userAndScopes)
268268
});
269269
}
270270

271+
IObservable<UserAndScopes> GetUserFromApiWithDelay()
272+
{
273+
// It seems that attempting to use a token immediately sometimes fails, add a delay
274+
// of 1s to allow the token to propagate.
275+
return Observable.Defer(() =>
276+
Observable.Timer(TimeSpan.FromMilliseconds(1000))
277+
.SelectMany(_ => ApiClient.GetUser()));
278+
}
279+
271280
IObservable<UserAndScopes> GetUserFromApi()
272281
{
273282
return Observable.Defer(() => ApiClient.GetUser());

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class GitHubHomeSection : TeamExplorerSectionBase, IGitHubHomeSection
2626
{
2727
public const string GitHubHomeSectionId = "72008232-2104-4FA0-A189-61B0C6F91198";
2828
const string TrainingUrl = "https://services.github.com/on-demand/windows/visual-studio";
29+
readonly static Guid welcomeMessageGuid = new Guid(Guids.TeamExplorerWelcomeMessage);
2930

3031
readonly IVisualStudioBrowser visualStudioBrowser;
3132
readonly ITeamExplorerServices teamExplorerServices;
@@ -53,25 +54,6 @@ public GitHubHomeSection(IGitHubServiceProvider serviceProvider,
5354
var openOnGitHub = ReactiveCommand.Create();
5455
openOnGitHub.Subscribe(_ => DoOpenOnGitHub());
5556
OpenOnGitHub = openOnGitHub;
56-
57-
// We want to display a welcome message but only if Team Explorer isn't
58-
// already displaying the "Install 3rd Party Tools" message. To do this
59-
// we need to set a timer and check in the tick as at this point the message
60-
// won't be initialized.
61-
if (!settings.HideTeamExplorerWelcomeMessage)
62-
{
63-
var timer = new DispatcherTimer();
64-
timer.Interval = new TimeSpan(10);
65-
timer.Tick += (s, e) =>
66-
{
67-
timer.Stop();
68-
if (!IsGitToolsMessageVisible())
69-
{
70-
ShowWelcomeMessage();
71-
}
72-
};
73-
timer.Start();
74-
}
7557
}
7658

7759
bool IsGitToolsMessageVisible()
@@ -93,12 +75,24 @@ protected async override void RepoChanged(bool changed)
9375
RepoName = ActiveRepoName;
9476
RepoUrl = ActiveRepoUri.ToString();
9577
Icon = GetIcon(false, true, false);
78+
79+
// We want to display a welcome message but only if Team Explorer isn't
80+
// already displaying the "Install 3rd Party Tools" message and the current repo is hosted on GitHub.
81+
if (!settings.HideTeamExplorerWelcomeMessage && !IsGitToolsMessageVisible())
82+
{
83+
ShowWelcomeMessage();
84+
}
85+
9686
Debug.Assert(SimpleApiClient != null,
9787
"If we're in this block, simpleApiClient cannot be null. It was created by UpdateStatus");
9888
var repo = await SimpleApiClient.GetRepository();
9989
Icon = GetIcon(repo.Private, true, repo.Fork);
10090
IsLoggedIn = IsUserAuthenticated();
10191
}
92+
else
93+
{
94+
teamExplorerServices.HideNotification(welcomeMessageGuid);
95+
}
10296
}
10397

10498
public override async void Refresh()
@@ -108,6 +102,7 @@ public override async void Refresh()
108102
{
109103
IsLoggedIn = IsUserAuthenticated();
110104
}
105+
111106
base.Refresh();
112107
}
113108

@@ -149,7 +144,6 @@ void DoOpenOnGitHub()
149144

150145
void ShowWelcomeMessage()
151146
{
152-
var welcomeMessageGuid = new Guid(Guids.TeamExplorerWelcomeMessage);
153147
teamExplorerServices.ShowMessage(
154148
Resources.TeamExplorerWelcomeMessage,
155149
new RelayCommand(o =>

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,4 +734,4 @@
734734
<Target Name="AfterBuild">
735735
</Target>
736736
-->
737-
</Project>
737+
</Project>

src/GitHub.VisualStudio/Services/UsageTracker.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
using GitHub.Extensions;
1212
using System.Threading.Tasks;
1313
using GitHub.Helpers;
14+
using System.Threading;
1415

1516
namespace GitHub.Services
1617
{
17-
public class UsageTracker : IUsageTracker
18+
public sealed class UsageTracker : IUsageTracker, IDisposable
1819
{
1920
const string StoreFileName = "ghfvs.usage";
2021
static readonly Calendar cal = CultureInfo.InvariantCulture.Calendar;
2122

2223
readonly IGitHubServiceProvider gitHubServiceProvider;
23-
readonly DispatcherTimer timer;
24-
2524
IMetricsService client;
2625
IConnectionManager connectionManager;
2726
IPackageSettings userSettings;
2827
IVSServices vsservices;
28+
Timer timer;
2929
string storePath;
3030
bool firstRun = true;
3131

@@ -61,13 +61,16 @@ public UsageTracker(IGitHubServiceProvider gitHubServiceProvider)
6161
};
6262
dirCreate = (path) => System.IO.Directory.CreateDirectory(path);
6363

64-
this.timer = new DispatcherTimer(
65-
TimeSpan.FromMinutes(3),
66-
DispatcherPriority.Background,
64+
this.timer = new Timer(
6765
TimerTick,
68-
ThreadingHelper.MainThreadDispatcher);
66+
null,
67+
TimeSpan.FromMinutes(3),
68+
TimeSpan.FromHours(8));
69+
}
6970

70-
RunTimer();
71+
public void Dispose()
72+
{
73+
timer?.Dispose();
7174
}
7275

7376
public async Task IncrementLaunchCount()
@@ -244,14 +247,7 @@ void SaveUsage(UsageStore store)
244247
writeAllText(storePath, json, Encoding.UTF8);
245248
}
246249

247-
void RunTimer()
248-
{
249-
// The timer first ticks after 3 minutes to allow things to settle down after startup.
250-
// This will be changed to 8 hours after the first tick by the TimerTick method.
251-
timer.Start();
252-
}
253-
254-
void TimerTick(object sender, EventArgs e)
250+
void TimerTick(object state)
255251
{
256252
TimerTick()
257253
.Catch(ex =>
@@ -268,13 +264,13 @@ async Task TimerTick()
268264
if (firstRun)
269265
{
270266
await IncrementLaunchCount();
271-
timer.Interval = TimeSpan.FromHours(8);
272267
firstRun = false;
273268
}
274269

275270
if (client == null || !userSettings.CollectMetrics)
276271
{
277-
timer.Stop();
272+
timer.Dispose();
273+
timer = null;
278274
return;
279275
}
280276

0 commit comments

Comments
 (0)