Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit aea0fb7

Browse files
committed
Tweak names of things, store id and unity version in the model
1 parent 01749ef commit aea0fb7

File tree

3 files changed

+38
-45
lines changed

3 files changed

+38
-45
lines changed

src/GitHub.Api/Metrics/UsageModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ namespace GitHub.Unity
66
{
77
class Usage
88
{
9+
public string Id { get; set; }
910
public DateTime Date { get; set; }
10-
public bool IsGitHubUser { get; set; }
11-
public bool IsEnterpriseUser { get; set; }
1211
public string AppVersion { get; set; }
1312
public string UnityVersion { get; set; }
1413
public string Lang { get; set; }
@@ -17,7 +16,8 @@ class Usage
1716

1817
class UsageModel
1918
{
20-
public List<Usage> Reports { get; } = new List<Usage>();
19+
public List<Usage> Reports { get; set; } = new List<Usage>();
20+
public string Id { get; set; }
2121

2222
private Usage currentUsage;
2323

@@ -38,7 +38,7 @@ public Usage GetCurrentUsage()
3838

3939
if (currentUsage == null)
4040
{
41-
currentUsage = new Usage { Date = date };
41+
currentUsage = new Usage { Date = date, Id = Id };
4242
Reports.Add(currentUsage);
4343
}
4444

src/GitHub.Api/Metrics/UsageTracker.cs

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public UsageTracker(NPath storePath, string id, string unityVersion)
3131

3232
private UsageStore LoadUsage()
3333
{
34+
UsageStore result = null;
3435
string json = null;
3536
if (storePath.FileExists())
3637
{
@@ -39,38 +40,28 @@ private UsageStore LoadUsage()
3940
try
4041
{
4142
json = storePath.ReadAllText(Encoding.UTF8);
43+
if (json != null)
44+
{
45+
result = SimpleJson.DeserializeObject<UsageStore>(json);
46+
}
4247
}
4348
catch (Exception ex)
4449
{
45-
Logger.Error(ex, "LoadUsage Error {0}", ex.Message);
46-
}
47-
}
50+
Logger.Warning(ex, "Error Loading Usage: {0}; Deleting File", storePath);
4851

49-
UsageStore result;
50-
try
51-
{
52-
if (json != null)
53-
{
54-
result = SimpleJson.DeserializeObject<UsageStore>(json);
55-
}
56-
else
57-
{
58-
result = new UsageStore();
52+
try
53+
{
54+
storePath.DeleteIfExists();
55+
}
56+
catch {}
5957
}
6058
}
61-
catch (Exception ex)
59+
60+
if (result == null)
6261
{
6362
result = new UsageStore();
64-
65-
Logger.Warning(ex, "Error Loading Usage: {0}; Deleting File", storePath);
66-
67-
try
68-
{
69-
storePath.DeleteIfExists();
70-
}
71-
catch{}
63+
result.Model.Id = id;
7264
}
73-
7465
//TODO: Figure out these values
7566
//result.Model.Lang = CultureInfo.InstalledUICulture.IetfLanguageTag;
7667
//result.Model.AppVersion = AssemblyVersionInformation.Version;
@@ -134,7 +125,7 @@ private async Task TimerTick()
134125

135126
if (!Enabled)
136127
{
137-
Logger.Warning("Tracking Disabled");
128+
Logger.Warning("Metrics Disabled");
138129
return;
139130
}
140131
}
@@ -152,7 +143,7 @@ private async Task TimerTick()
152143

153144
if (!Enabled)
154145
{
155-
Logger.Warning("Tracking Disabled");
146+
Logger.Warning("Metrics Disabled");
156147
return;
157148
}
158149

@@ -169,14 +160,15 @@ private async Task SendUsage(UsageStore usage)
169160
var currentTimeOffset = DateTimeOffset.UtcNow;
170161
var beforeDate = currentTimeOffset.Date;
171162

163+
var success = false;
172164
var extractReports = usage.Model.SelectReports(beforeDate);
173165
if (!extractReports.Any())
174166
{
175167
Logger.Trace("No items to send");
168+
success = true;
176169
}
177170
else
178171
{
179-
var success = false;
180172
try
181173
{
182174
await metricsService.PostUsage(extractReports);
@@ -187,14 +179,14 @@ private async Task SendUsage(UsageStore usage)
187179
Logger.Warning(ex, "Error Sending Usage");
188180
}
189181

190-
if (success)
191-
{
192-
usage.Model.RemoveReports(beforeDate);
193-
}
194182
}
195183

196-
usage.LastUpdated = currentTimeOffset;
197-
SaveUsage(usage);
184+
if (success)
185+
{
186+
usage.Model.RemoveReports(beforeDate);
187+
usage.LastUpdated = currentTimeOffset;
188+
SaveUsage(usage);
189+
}
198190
}
199191

200192
public void IncrementLaunchCount()
@@ -203,6 +195,7 @@ public void IncrementLaunchCount()
203195

204196
var usage = usageStore.Model.GetCurrentUsage();
205197
usage.NumberOfStartups++;
198+
usage.UnityVersion = unityVersion;
206199

207200
Logger.Trace("IncrementLaunchCount Date:{0} NumberOfStartups:{1}", usage.Date, usage.NumberOfStartups);
208201

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class SettingsView : Subview
6161
private const string GitRepositoryRemoteLabel = "Remote";
6262
private const string GitRepositorySave = "Save Repository";
6363
private const string DebugSettingsTitle = "Debug";
64-
private const string UserTrackingSettingsTitle = "User Tracking";
64+
private const string PrivacyTitle = "Privacy";
6565
private const string EnableTraceLoggingLabel = "Enable Trace Logging";
66-
private const string EnableUserTrackingLabel = "Enable User Tracking";
66+
private const string MetricsOptInLabel = "Help us improve by sending anonymous usage data";
6767

6868
private Vector2 lockScrollPos;
6969

@@ -201,7 +201,7 @@ public override void OnGUI()
201201
}
202202

203203
OnInstallPathGUI();
204-
OnTrackingSettingsGui();
204+
OnPrivacyGui();
205205
OnLoggingSettingsGui();
206206
}
207207

@@ -654,21 +654,21 @@ private void OnInstallPathGUI()
654654
GUI.enabled = true;
655655
}
656656

657-
private void OnTrackingSettingsGui()
657+
private void OnPrivacyGui()
658658
{
659-
GUILayout.Label(UserTrackingSettingsTitle, EditorStyles.boldLabel);
659+
GUILayout.Label(PrivacyTitle, EditorStyles.boldLabel);
660660

661661
GUI.enabled = !busy;
662662

663-
var trackingEnabled = EntryPoint.UsageTracker.Enabled;
663+
var metricsEnabled = EntryPoint.UsageTracker.Enabled;
664664
EditorGUI.BeginChangeCheck();
665665
{
666-
trackingEnabled = EditorGUILayout.Toggle(EnableUserTrackingLabel, trackingEnabled);
666+
metricsEnabled = EditorGUILayout.Toggle(MetricsOptInLabel, metricsEnabled);
667667
}
668668
if (EditorGUI.EndChangeCheck())
669669
{
670-
EntryPoint.UsageTracker.Enabled = trackingEnabled;
671-
Manager.UserSettings.Set("UserTrackingEnabled", trackingEnabled);
670+
EntryPoint.UsageTracker.Enabled = metricsEnabled;
671+
Manager.UserSettings.Set("MetricsEnabled", metricsEnabled);
672672

673673
GUI.FocusControl(null);
674674
}

0 commit comments

Comments
 (0)