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

Commit 6c1eb5d

Browse files
author
Steven Kirk
committed
Send usage data.
1 parent 24a5fec commit 6c1eb5d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

script

src/GitHub.App/Services/UsageTracker.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ public UsageTracker(
5555
this.repositoryHosts = repositoryHosts;
5656
this.userSettings = userSettings;
5757
this.client = (IMetricsService)serviceProvider.GetService(typeof(IMetricsService));
58+
59+
userSettings.WhenAny(x => x.CollectMetrics, x => x.Value)
60+
// If SendUsageData is true we'll subscribe to the Run()
61+
// observable (which is a timer) and thus kick off the
62+
// tracker. The Run method will produce on unit per tick
63+
// but we don't care about that at all so we'll ignore
64+
// that and instead send true or false down the chain
65+
// indicating that the tracker is running or not.
66+
.Select(sendUsageData => sendUsageData
67+
? Run()
68+
.IgnoreElements()
69+
.Select(_ => true)
70+
.StartWith(true)
71+
: Observable.Return(false))
72+
.Switch()
73+
// The first value will be what initially kicks off the
74+
// tracker. The second value (if there is one) will signal
75+
// that the user has opted in or out of usage tracking.
76+
.Skip(1)
77+
.Select(sendUsageData => sendUsageData ? OptIn() : OptOut())
78+
.Switch()
79+
.Subscribe();
5880
}
5981

6082
IBlobCache LocalMachineCache => cache.Value.LocalMachine;

0 commit comments

Comments
 (0)