Skip to content

Commit 2fdc413

Browse files
authored
Fixed an issue where app center wasn't logging events (#5894)
1 parent 45faf35 commit 2fdc413

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

Files/ViewModels/MainPageViewModel.cs

-23
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
using Files.Helpers;
44
using Files.UserControls.MultitaskingControl;
55
using Files.Views;
6-
using Microsoft.AppCenter;
7-
using Microsoft.AppCenter.Analytics;
8-
using Microsoft.AppCenter.Crashes;
96
using Microsoft.Toolkit.Mvvm.ComponentModel;
107
using Microsoft.Toolkit.Mvvm.Input;
118
using Microsoft.Toolkit.Uwp;
12-
using Newtonsoft.Json.Linq;
139
using System;
1410
using System.Collections.Generic;
1511
using System.Collections.ObjectModel;
@@ -54,8 +50,6 @@ public MainPageViewModel()
5450
OpenNewWindowAcceleratorCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(OpenNewWindowAccelerator);
5551
CloseSelectedTabKeyboardAcceleratorCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(CloseSelectedTabKeyboardAccelerator);
5652
AddNewInstanceAcceleratorCommand = new RelayCommand<KeyboardAcceleratorInvokedEventArgs>(AddNewInstanceAccelerator);
57-
58-
StartAppCenter();
5953
}
6054

6155
private void NavigateToNumberedTabKeyboardAccelerator(KeyboardAcceleratorInvokedEventArgs e)
@@ -468,22 +462,5 @@ public static async void Control_ContentChanged(object sender, TabItemArguments
468462
}
469463
await UpdateTabInfo(matchingTabItem, e.NavigationArg);
470464
}
471-
472-
private async void StartAppCenter()
473-
{
474-
JObject obj;
475-
try
476-
{
477-
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///Resources/AppCenterKey.txt"));
478-
var lines = await FileIO.ReadTextAsync(file);
479-
obj = JObject.Parse(lines);
480-
}
481-
catch
482-
{
483-
return;
484-
}
485-
486-
AppCenter.Start((string)obj.SelectToken("key"), typeof(Analytics), typeof(Crashes));
487-
}
488465
}
489466
}

Files/ViewModels/SettingsViewModel.cs

+21
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
using Files.Enums;
55
using Files.Filesystem;
66
using Files.Helpers;
7+
using Microsoft.AppCenter;
78
using Microsoft.AppCenter.Analytics;
9+
using Microsoft.AppCenter.Crashes;
810
using Microsoft.Toolkit.Mvvm.ComponentModel;
911
using Microsoft.Toolkit.Mvvm.Input;
1012
using Microsoft.Toolkit.Uwp;
1113
using Microsoft.Toolkit.Uwp.UI;
14+
using Newtonsoft.Json.Linq;
1215
using System;
1316
using System.Collections.ObjectModel;
1417
using System.Linq;
@@ -50,6 +53,7 @@ private async Task<SettingsViewModel> Initialize()
5053
FileTagsSettings = new FileTagsSettings();
5154

5255
// Send analytics to AppCenter
56+
await StartAppCenter();
5357
TrackAnalytics();
5458

5559
return this;
@@ -65,6 +69,23 @@ private SettingsViewModel()
6569
{
6670
}
6771

72+
private async Task StartAppCenter()
73+
{
74+
JObject obj;
75+
try
76+
{
77+
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///Resources/AppCenterKey.txt"));
78+
var lines = await FileIO.ReadTextAsync(file);
79+
obj = JObject.Parse(lines);
80+
}
81+
catch
82+
{
83+
return;
84+
}
85+
86+
AppCenter.Start((string)obj.SelectToken("key"), typeof(Analytics), typeof(Crashes));
87+
}
88+
6889
private void TrackAnalytics()
6990
{
7091
Analytics.TrackEvent($"{nameof(DisplayedTimeStyle)} {DisplayedTimeStyle}");

0 commit comments

Comments
 (0)