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

Commit c493e1e

Browse files
committed
Ensure UsageTracker services retreived on UI thread.
Required changing most of the UsageTracker methods to be async.
1 parent ae92a2c commit c493e1e

File tree

13 files changed

+62
-62
lines changed

13 files changed

+62
-62
lines changed

src/GitHub.App/Models/RepositoryHost.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Linq;
1818
using System.Reactive.Threading.Tasks;
1919
using System.Collections.Generic;
20+
using GitHub.Extensions;
2021

2122
namespace GitHub.Models
2223
{
@@ -241,7 +242,7 @@ IObservable<AuthenticationResult> LoginWithApiUser(UserAndScopes userAndScopes)
241242
if (result.IsSuccess())
242243
{
243244
var accountCacheItem = new AccountCacheItem(userAndScopes.User);
244-
usage.IncrementLoginCount();
245+
usage.IncrementLoginCount().Forget();
245246
return ModelService.InsertUser(accountCacheItem).Select(_ => result);
246247
}
247248

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async Task<IPullRequestModel> PushAndCreatePR(IRepositoryHost host,
9191
await Task.Delay(TimeSpan.FromSeconds(5));
9292

9393
var ret = await host.ModelService.CreatePullRequest(sourceRepository, targetRepository, sourceBranch, targetBranch, title, body);
94-
usageTracker.IncrementUpstreamPullRequestCount();
94+
await usageTracker.IncrementUpstreamPullRequestCount();
9595
return ret;
9696
}
9797

src/GitHub.App/ViewModels/GistCreationViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ IObservable<Gist> OnCreateGist(object unused)
7878
newGist.Files.Add(FileName, SelectedText);
7979

8080
return gistPublishService.PublishGist(apiClient, newGist)
81-
.Do(_ => usageTracker.IncrementCreateGistCount())
81+
.Do(_ => usageTracker.IncrementCreateGistCount().Forget())
8282
.Catch<Gist, Exception>(ex =>
8383
{
8484
if (!ex.IsCriticalException())

src/GitHub.App/ViewModels/RepositoryCloneViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ IObservable<Unit> OnCloneRepository(object state)
199199
return cloneService.CloneRepository(repository.CloneUrl, repository.Name, BaseRepositoryPath)
200200
.ContinueAfter(() =>
201201
{
202-
usageTracker.IncrementCloneCount();
202+
usageTracker.IncrementCloneCount().Forget();
203203
return Observable.Return(Unit.Default);
204204
});
205205
})

src/GitHub.App/ViewModels/RepositoryCreationViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ IObservable<Unit> OnCreateRepository(object state)
268268
SelectedAccount,
269269
BaseRepositoryPath,
270270
repositoryHost.ApiClient)
271-
.Do(_ => usageTracker.IncrementCreateCount());
271+
.Do(_ => usageTracker.IncrementCreateCount().Forget());
272272
}
273273

274274
ReactiveCommand<Unit> InitializeCreateRepositoryCommand()

src/GitHub.App/ViewModels/RepositoryPublishViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ IObservable<ProgressState> OnPublishRepository(object arg)
153153
var account = SelectedAccount;
154154

155155
return repositoryPublishService.PublishRepository(newRepository, account, SelectedHost.ApiClient)
156-
.Do(_ => usageTracker.IncrementPublishCount())
156+
.Do(_ => usageTracker.IncrementPublishCount().Forget())
157157
.Select(_ => ProgressState.Success)
158158
.Catch<ProgressState, Exception>(ex =>
159159
{

src/GitHub.App/ViewModels/StartPageCloneViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ IObservable<Unit> OnCloneRepository(object state)
105105
return cloneService.CloneRepository(repository.CloneUrl, repository.Name, BaseRepositoryPath)
106106
.ContinueAfter(() =>
107107
{
108-
usageTracker.IncrementCloneCount();
108+
usageTracker.IncrementCloneCount().Forget();
109109
return Observable.Return(Unit.Default);
110110
});
111111
})
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
using GitHub.VisualStudio;
22
using System.Runtime.InteropServices;
3+
using System.Threading.Tasks;
34

45
namespace GitHub.Services
56
{
67
[Guid(Guids.UsageTrackerId)]
78
public interface IUsageTracker
89
{
9-
void IncrementLaunchCount();
10-
void IncrementCloneCount();
11-
void IncrementCreateCount();
12-
void IncrementPublishCount();
13-
void IncrementOpenInGitHubCount();
14-
void IncrementLinkToGitHubCount();
15-
void IncrementCreateGistCount();
16-
void IncrementUpstreamPullRequestCount();
17-
void IncrementLoginCount();
10+
Task IncrementLaunchCount();
11+
Task IncrementCloneCount();
12+
Task IncrementCreateCount();
13+
Task IncrementPublishCount();
14+
Task IncrementOpenInGitHubCount();
15+
Task IncrementLinkToGitHubCount();
16+
Task IncrementCreateGistCount();
17+
Task IncrementUpstreamPullRequestCount();
18+
Task IncrementLoginCount();
1819
}
1920
}

src/GitHub.VisualStudio/Menus/CopyLink.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public async void Activate([AllowNull]object data = null)
3131
Clipboard.SetText(link);
3232
var ns = ServiceProvider.TryGetService<IStatusBarNotificationService>();
3333
ns?.ShowMessage(Resources.LinkCopiedToClipboardMessage);
34-
UsageTracker.IncrementLinkToGitHubCount();
34+
await UsageTracker.IncrementLinkToGitHubCount();
3535
}
3636
catch
3737
{

src/GitHub.VisualStudio/Menus/OpenLink.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public async void Activate([AllowNull]object data = null)
2626
var browser = ServiceProvider.TryGetService<IVisualStudioBrowser>();
2727
browser?.OpenUrl(link.ToUri());
2828

29-
UsageTracker.IncrementOpenInGitHubCount();
29+
await UsageTracker.IncrementOpenInGitHubCount();
3030
}
3131

3232
public bool CanShow()

0 commit comments

Comments
 (0)