Core update. Base core features are done (main app doesn't compile)
Related Work Items: #416, #422, #423, #424
This commit is contained in:
@@ -6,19 +6,17 @@ using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.Storage;
|
||||
using FoxTube.Services;
|
||||
|
||||
namespace FoxTube.Utils
|
||||
{
|
||||
public static class Metrics
|
||||
{
|
||||
static readonly ApplicationDataContainer storage = ApplicationData.Current.RoamingSettings;
|
||||
|
||||
static readonly Stopwatch sw = new Stopwatch();
|
||||
public static TimeSpan Uptime
|
||||
{
|
||||
get => (TimeSpan?)storage.Values["Metrics.SpentTime"] ?? TimeSpan.FromSeconds(0);
|
||||
set => storage.Values["Metrics.SpentTime"] = value;
|
||||
get => Storage.GetValue<TimeSpan?>(Storage.Metrics.Uptime) ?? TimeSpan.FromSeconds(0);
|
||||
set => Storage.SetValue(Storage.Metrics.Uptime, value);
|
||||
}
|
||||
public static string CurrentVersion
|
||||
{
|
||||
@@ -32,11 +30,11 @@ namespace FoxTube.Utils
|
||||
static Metrics()
|
||||
{
|
||||
sw.Start();
|
||||
if (!Settings.AllowAnalytics)
|
||||
if (!Storage.GetValue<bool>(Storage.Settings.AllowAnalytics))
|
||||
return;
|
||||
|
||||
AppCenter.Start("45774462-9ea7-438a-96fc-03982666f39e", typeof(Analytics), typeof(Crashes));
|
||||
AppCenter.SetCountryCode(Settings.Region);
|
||||
AppCenter.Start(SecretConstants.MetricsId, typeof(Analytics), typeof(Crashes));
|
||||
AppCenter.SetCountryCode(Storage.GetValue<string>(Storage.Settings.Region));
|
||||
AppCenter.LogLevel = LogLevel.Verbose;
|
||||
}
|
||||
|
||||
@@ -45,23 +43,30 @@ namespace FoxTube.Utils
|
||||
sw.Stop();
|
||||
Uptime += sw.Elapsed;
|
||||
|
||||
AddEvent("Session closed",
|
||||
("Duration", sw.Elapsed.ToString()),
|
||||
("Spend time total", Uptime.ToString()));
|
||||
if (Storage.GetValue<bool>(Storage.Settings.AllowAnalytics))
|
||||
AddEvent("Session closed",
|
||||
("Duration", sw.Elapsed.ToString()),
|
||||
("Spend time total", Uptime.ToString()));
|
||||
}
|
||||
|
||||
public static void AddEvent(string eventName, params (string key, string value)[] details) =>
|
||||
Analytics.TrackEvent(eventName,
|
||||
details.Length < 1 ? null :
|
||||
details.Select(i => new KeyValuePair<string, string>(i.key, i.value)) as Dictionary<string, string>);
|
||||
public static void AddEvent(string eventName, params (string key, string value)[] details)
|
||||
{
|
||||
if (Storage.GetValue<bool>(Storage.Settings.AllowAnalytics))
|
||||
Analytics.TrackEvent(eventName,
|
||||
details.Length < 1 ? null :
|
||||
details.Select(i => new KeyValuePair<string, string>(i.key, i.value)) as Dictionary<string, string>);
|
||||
}
|
||||
|
||||
public static void SendReport(Exception exception, ErrorAttachmentLog[] logs = null, params (string key, string value)[] details)
|
||||
{
|
||||
logs ??= new ErrorAttachmentLog[0];
|
||||
Crashes.TrackError(exception,
|
||||
details.Length < 1 ? null :
|
||||
details.Select(i => new KeyValuePair<string, string>(i.key, i.value)) as Dictionary<string, string>,
|
||||
logs);
|
||||
if (Storage.GetValue<bool>(Storage.Settings.AllowAnalytics))
|
||||
{
|
||||
logs ??= new ErrorAttachmentLog[0];
|
||||
Crashes.TrackError(exception ?? new Exception("Unknown exception"),
|
||||
details.Length < 1 ? null :
|
||||
details.Select(i => new KeyValuePair<string, string>(i.key, i.value)) as Dictionary<string, string>,
|
||||
logs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user