Skip to content

Commit

Permalink
Added Wine detection to anlytics
Browse files Browse the repository at this point in the history
Limited game state filter selection to one entry
  • Loading branch information
Yelo420 committed Oct 28, 2024
1 parent 193f106 commit 074aa73
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# GameVault App Changelog

## 1.12.6
Recommended Gamevault Server Version: `v13.0.0`
## 1.13.0
Recommended Gamevault Server Version: `v13.1.0`
### Changes

- You can now filter by game state in the library
Expand Down
2 changes: 1 addition & 1 deletion gamevault/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
[assembly: AssemblyVersion("1.12.6.0")]
[assembly: AssemblyVersion("1.13.0.0")]
[assembly: AssemblyCopyright("© Phalcode™. All Rights Reserved.")]
#if DEBUG
[assembly: XmlnsDefinition("debug-mode", "Namespace")]
Expand Down
24 changes: 12 additions & 12 deletions gamevault/Helper/AnalyticsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,9 @@ internal AnalyticsHelper()

client = new HttpClient();
client.DefaultRequestHeaders.UserAgent.Clear();
//client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Mozilla", "5.0"));
//client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("(Windows NT 10.0; Win64; x64)"));
//client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("AppleWebKit", "537.36"));
//client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("(KHTML, like Gecko)"));
//client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Chrome", "129.0.0.0"));
//client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Safari", "537.36"));
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("GameVault", SettingsViewModel.Instance.Version));
string plattform = IsWineRunning() ? "Linux" : "Windows NT";
var userAgent = $"GameVault/{SettingsViewModel.Instance.Version} ({plattform})";
client.DefaultRequestHeaders.UserAgent.ParseAdd(userAgent);
try
{
TimeZoneInfo.TryConvertWindowsIdToIanaId(TimeZoneInfo.Local.Id, RegionInfo.CurrentRegion.TwoLetterISORegionName, out timeZone);
Expand Down Expand Up @@ -176,16 +172,15 @@ private async Task SendHeartBeat(string url)
catch (Exception e) { }

}
public async Task SendPageView(UserControl page, UserControl prevPage)
public async Task SendPageView(UserControl page)
{
if (!trackingEnabled)
return;

try
{
string? pageString = ParseUserControl(page);
string? prevPageString = ParseUserControl(prevPage);
var jsonContent = new StringContent(JsonSerializer.Serialize(new AnalyticsData() { Timezone = timeZone, CurrentPage = pageString, PreviousPage = prevPageString, Language = language }), Encoding.UTF8, "application/json");
var jsonContent = new StringContent(JsonSerializer.Serialize(new AnalyticsData() { Timezone = timeZone, CurrentPage = pageString, Language = language }), Encoding.UTF8, "application/json");
await client.PostAsync(AnalyticsTargets.LG, jsonContent);
}
catch (Exception e) { }
Expand Down Expand Up @@ -270,6 +265,12 @@ public object GetSysInfo()
string cpu = $"{CPU["Name"]} - {CPU["MaxClockSpeed"]} MHz - {CPU["NumberOfCores"]} Core";
return new { app_version = SettingsViewModel.Instance.Version, hardware_os = os, hardware_ram = ram, hardware_cpu = cpu, };
}
private bool IsWineRunning()
{
// Search for WINLOGON process
int p = Process.GetProcessesByName("winlogon").Length;
return p == 0;
}
private class AnalyticsData
{
[JsonPropertyName("pid")]
Expand All @@ -281,8 +282,7 @@ private class AnalyticsData
public string? Timezone { get; set; }
[JsonPropertyName("pg")]
public string? CurrentPage { get; set; }
[JsonPropertyName("prev")]
public string? PreviousPage { get; set; }

[JsonPropertyName("lc")]
public string? Language { get; set; }
[JsonPropertyName("meta")]
Expand Down
8 changes: 8 additions & 0 deletions gamevault/UserControls/GeneralControls/PillSelector.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public Selection SelectionType
get => (Selection)GetValue(SelectionTypeProperty);
set => SetValue(SelectionTypeProperty, value);
}
public static readonly DependencyProperty MaxSelectionProperty = DependencyProperty.Register(name: "MaxSelection", propertyType: typeof(int), ownerType: typeof(PillSelector));
public int MaxSelection
{
get => (int)GetValue(MaxSelectionProperty);
set => SetValue(MaxSelectionProperty, value);
}
public event EventHandler EntriesUpdated;
private bool loaded = false;
private InputTimer debounceTimer { get; set; }
Expand Down Expand Up @@ -174,6 +180,8 @@ private void Search_TextChanged(object sender, TextChangedEventArgs e)
private void AddEntry_Click(object sender, MouseButtonEventArgs e)
{
if (selectedEntries.Contains((Pill)((FrameworkElement)sender).DataContext)) return;
if (MaxSelection > 0 && selectedEntries.Count >= MaxSelection) return;

selectedEntries.Add((Pill)((FrameworkElement)sender).DataContext);
uiSelectedEntries.ItemsSource = null;
uiSelectedEntries.ItemsSource = selectedEntries;
Expand Down
2 changes: 1 addition & 1 deletion gamevault/UserControls/LibraryUserControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<local:PillSelector x:Name="uiFilterGameTypeSelector" SelectionType="GameType" Margin="12,0,24,0" Width="175" EntriesUpdated="FilterUpdated"/>
<local:PillSelector x:Name="uiFilterTagSelector" SelectionType="Tags" Margin="0,0,24,0" Width="175" EntriesUpdated="FilterUpdated"/>
<local:PillSelector x:Name="uiFilterGenreSelector" SelectionType="Genres" Margin="0,0,24,0" Width="175" EntriesUpdated="FilterUpdated"/>
<local:PillSelector x:Name="uiFilterGameStateSelector" SelectionType="GameState" Margin="0,0,23,0" Width="175" EntriesUpdated="FilterUpdated"/>
<local:PillSelector x:Name="uiFilterGameStateSelector" SelectionType="GameState" MaxSelection="1" Margin="0,0,23,0" Width="175" EntriesUpdated="FilterUpdated"/>
<StackPanel Margin="0,0,97,0">
<TextBlock Text="Release Year" FontSize="15"/>
<local:DateRangeSelector x:Name="uiFilterReleaseDateRangeSelector" EntriesUpdated="FilterUpdated"/>
Expand Down
2 changes: 1 addition & 1 deletion gamevault/UserControls/LibraryUserControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private string ApplyFilter(string filter)
string gameStates = uiFilterGameStateSelector.GetSelectedEntries();
if (gameStates != string.Empty)
{
filter += $"&filter.progresses.state=$in:{gameStates}&filter.progresses.user.id=$eq:{LoginManager.Instance.GetCurrentUser()?.ID}";
filter += $"&filter.progresses.state=$eq:{gameStates}&filter.progresses.user.id=$eq:{LoginManager.Instance.GetCurrentUser()?.ID}";
}
if (uiFilterBookmarks.IsChecked == true)
{
Expand Down
2 changes: 1 addition & 1 deletion gamevault/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public UserControl ActiveControl
if (m_ActiveControl != null) { m_ActiveControl.Visibility = System.Windows.Visibility.Collapsed; }
if (value != null)
{
AnalyticsHelper.Instance.SendPageView(value, m_ActiveControl);
AnalyticsHelper.Instance.SendPageView(value);
}
m_ActiveControl = value;
if (m_ActiveControl != null)
Expand Down

0 comments on commit 074aa73

Please sign in to comment.