Skip to content

Commit

Permalink
Merge pull request #3237 from marticliment/telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
marticliment authored Jan 30, 2025
2 parents 4d580bd + 1b93d77 commit 0e8a527
Show file tree
Hide file tree
Showing 18 changed files with 349 additions and 14 deletions.
2 changes: 1 addition & 1 deletion UniGetUI.iss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppVersion "3.1.6-beta2"
#define MyAppVersion "3.1.6-beta3"
#define MyAppName "UniGetUI"
#define MyAppPublisher "Martí Climent"
#define MyAppURL "https://github.com/marticliment/UniGetUI"
Expand Down
2 changes: 1 addition & 1 deletion scripts/BuildNumber
Original file line number Diff line number Diff line change
@@ -1 +1 @@
77
78
2 changes: 1 addition & 1 deletion src/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
[assembly: AssemblyCopyright("2025, Martí Climent")]
[assembly: AssemblyVersion("3.1.6.0")]
[assembly: AssemblyFileVersion("3.1.6.0")]
[assembly: AssemblyInformationalVersion("3.1.6-beta2")]
[assembly: AssemblyInformationalVersion("3.1.6-beta3")]
[assembly: SupportedOSPlatform("windows10.0.19041")]
5 changes: 3 additions & 2 deletions src/UniGetUI.Core.Data/CoreData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public static class CoreData
{
private static int? __code_page;
public static int CODE_PAGE { get => __code_page ??= GetCodePage(); }
public const string VersionName = "3.1.6-beta2"; // Do not modify this line, use file scripts/apply_versions.py
public const int BuildNumber = 77; // Do not modify this line, use file scripts/apply_versions.py
public const string VersionName = "3.1.6-beta3"; // Do not modify this line, use file scripts/apply_versions.py
public const int BuildNumber = 78; // Do not modify this line, use file scripts/apply_versions.py

public const string UserAgentString = $"UniGetUI/{VersionName} (https://marticliment.com/unigetui/; [email protected])";

Expand Down Expand Up @@ -120,6 +120,7 @@ public static string UniGetUI_DefaultBackupDirectory
}

public static bool IsDaemon;
public static bool WasDaemon;

/// <summary>
/// The ID of the notification that is used to inform the user that updates are available
Expand Down
2 changes: 2 additions & 0 deletions src/UniGetUI.Core.LanguageEngine/LanguageEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace UniGetUI.Core.Language
public class LanguageEngine
{
private Dictionary<string, string> MainLangDict = [];
public static string SelectedLocale = "??";

[NotNull]
public string? Locale { get; private set; }
Expand Down Expand Up @@ -48,6 +49,7 @@ public void LoadLanguage(string lang)
Formatter = new() { Locale = Locale.Replace('_', '-') };

LoadStaticTranslation();
SelectedLocale = Locale;
Logger.Info("Loaded language locale: " + Locale);
}

Expand Down
19 changes: 14 additions & 5 deletions src/UniGetUI.Interface.Enums/UniGetUI.Interface.Enums.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>x64</Platforms>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
<Platforms>x64</Platforms>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<WindowsSdkPackageVersion>10.0.26100.53</WindowsSdkPackageVersion>
<SdkVersion>8.0.404</SdkVersion>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<PublishSelfContained>true</PublishSelfContained>
<Authors>Martí Climent and the contributors</Authors>
<PublisherName>Martí Climent</PublisherName>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

<ItemGroup>
Expand Down
146 changes: 146 additions & 0 deletions src/UniGetUI.Interface.Telemetry/TelemetryHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using System.Net;
using UniGetUI.Core.Data;
using UniGetUI.Core.Language;
using UniGetUI.Core.Logging;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.Tools;
using UniGetUI.PackageEngine;
using UniGetUI.PackageEngine.Interfaces;

namespace UniGetUI.Interface.Telemetry;

public static class TelemetryHandler
{
private const string HOST = "https://marticliment.com/unigetui/statistics";

private static string[] SettingsToSend =
{
"DisableAutoUpdateWingetUI",
"EnableUniGetUIBeta",
"DisableSystemTray",
"DisableNotifications",
"DisableAutoCheckforUpdates",
"AutomaticallyUpdatePackages",
"AskToDeleteNewDesktopShortcuts",
"EnablePackageBackup",
"DoCacheAdminRights",
"DoCacheAdminRightsForBatches",
"ForceLegacyBundledWinGet",
"UseSystemChocolatey",
"SP1", // UniGetUI is portable
"SP2" // UniGetUI was started as daemon
};

public static async void Initialize()
{
try
{
if (Settings.Get("DisableTelemetry")) return;
await CoreTools.WaitForInternetConnection();

if (Settings.GetValue("TelemetryClientToken").Length != 64)
{
Settings.SetValue("TelemetryClientToken", CoreTools.RandomString(64));
}

string ID = Settings.GetValue("TelemetryClientToken");

int mask = 0x1;
int ManagerMagicValue = 0;

foreach (var manager in PEInterface.Managers)
{
if(manager.IsEnabled()) ManagerMagicValue |= mask;
mask = mask << 1;
if(manager.IsEnabled() && manager.Status.Found) ManagerMagicValue |= mask;
mask = mask << 1;

if (mask == 0x1)
throw new OverflowException();
}

int SettingsMagicValue = 0;
mask = 0x1;
foreach (var setting in SettingsToSend)
{
bool enabled;
if (setting == "SP1") enabled = File.Exists("ForceUniGetUIPortable");
else if (setting == "SP2") enabled = CoreData.WasDaemon;
else if (setting.StartsWith("Disable")) enabled = !Settings.Get(setting);
else enabled = Settings.Get(setting);

if(enabled) SettingsMagicValue |= mask;
mask = mask << 1;

if (mask == 0x1)
throw new OverflowException();
}

var request = new HttpRequestMessage(HttpMethod.Post, $"{HOST}/activity");

request.Headers.Add("clientId", ID);
request.Headers.Add("clientVersion", CoreData.VersionName);
request.Headers.Add("activeManagers", ManagerMagicValue.ToString());
request.Headers.Add("activeSettings", SettingsMagicValue.ToString());
request.Headers.Add("language", LanguageEngine.SelectedLocale);

HttpClient _httpClient = new(CoreData.GenericHttpClientParameters);
HttpResponseMessage response = await _httpClient.SendAsync(request);

if (response.IsSuccessStatusCode)
{
Logger.Debug("[Telemetry] Call to /activity succeeded");
}
else
{
Logger.Warn($"[Telemetry] Call to /activity failed with error code {response.StatusCode}");
}
}
catch (Exception ex)
{
Logger.Error("[Telemetry] Hard crash when calling /activity");
Logger.Error(ex);
}
}

public static async void PackageInstalled(IPackage package)
{
try
{
if (Settings.Get("DisableTelemetry")) return;
await CoreTools.WaitForInternetConnection();

if (Settings.GetValue("TelemetryClientToken").Length != 64)
{
Settings.SetValue("TelemetryClientToken", CoreTools.RandomString(64));
}

string ID = Settings.GetValue("TelemetryClientToken");


var request = new HttpRequestMessage(HttpMethod.Post, $"{HOST}/install");

request.Headers.Add("clientId", ID);
request.Headers.Add("packageId", package.Id);
request.Headers.Add("managerName", package.Manager.Name);
request.Headers.Add("sourceName", package.Source.Name);

HttpClient _httpClient = new(CoreData.GenericHttpClientParameters);
HttpResponseMessage response = await _httpClient.SendAsync(request);

if (response.IsSuccessStatusCode)
{
Logger.Debug("[Telemetry] Call to /install succeeded");
}
else
{
Logger.Warn($"[Telemetry] Call to /install failed with error code {response.StatusCode}");
}
}
catch (Exception ex)
{
Logger.Error("[Telemetry] Hard crash when calling /install");
Logger.Error(ex);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier>
<Platforms>x64</Platforms>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<WindowsSdkPackageVersion>10.0.26100.53</WindowsSdkPackageVersion>
<SdkVersion>8.0.404</SdkVersion>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<PublishSelfContained>true</PublishSelfContained>
<Authors>Martí Climent and the contributors</Authors>
<PublisherName>Martí Climent</PublisherName>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<IsPackable>false</IsPackable>
<RootNamespace>UniGetUI.Interface.Telemetry</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\UniGetUI.Core.Settings\UniGetUI.Core.Settings.csproj" />
<ProjectReference Include="..\UniGetUI.Core.Tools\UniGetUI.Core.Tools.csproj" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<ProjectReference Include="..\UniGetUI.PAckageEngine.Interfaces\UniGetUI.PackageEngine.Interfaces.csproj" />
<ProjectReference Include="..\UniGetUI.PackageEngine.PackageEngine\UniGetUI.PackageEngine.PEInterface.csproj" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions src/UniGetUI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniGetUI.PackageEngine.Mana
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniGetUI.PackageEngine.Operations", "UniGetUI.PackageEngine.Operations\UniGetUI.PackageEngine.Operations.csproj", "{727866B8-BBD5-43B9-933A-78199F65429C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniGetUI.Interface.Telemetry", "UniGetUI.Interface.Telemetry\UniGetUI.Interface.Telemetry.csproj", "{3C8BF564-B4B5-44A7-9D8C-102C2F820EAF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -256,6 +258,10 @@ Global
{727866B8-BBD5-43B9-933A-78199F65429C}.Debug|x64.Build.0 = Debug|x64
{727866B8-BBD5-43B9-933A-78199F65429C}.Release|x64.ActiveCfg = Release|x64
{727866B8-BBD5-43B9-933A-78199F65429C}.Release|x64.Build.0 = Release|x64
{3C8BF564-B4B5-44A7-9D8C-102C2F820EAF}.Debug|x64.ActiveCfg = Debug|x64
{3C8BF564-B4B5-44A7-9D8C-102C2F820EAF}.Debug|x64.Build.0 = Debug|x64
{3C8BF564-B4B5-44A7-9D8C-102C2F820EAF}.Release|x64.ActiveCfg = Release|x64
{3C8BF564-B4B5-44A7-9D8C-102C2F820EAF}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -301,6 +307,7 @@ Global
{54DA0549-366F-4E70-B5D1-0B8891D0A2A5} = {95168D0B-1B2C-4295-B6D4-D5BAF781B9FA}
{E337A71E-3C30-4315-B8F1-57CBC5CF50A6} = {95168D0B-1B2C-4295-B6D4-D5BAF781B9FA}
{727866B8-BBD5-43B9-933A-78199F65429C} = {7940E867-EEBA-4AFD-9904-1536F003239C}
{3C8BF564-B4B5-44A7-9D8C-102C2F820EAF} = {8CF74C87-534F-4017-A4ED-F2918025E31A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D044BB14-0B37-47E5-A579-8B30FCBA1F9F}
Expand Down
2 changes: 2 additions & 0 deletions src/UniGetUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.Windows.AppLifecycle;
using Microsoft.Windows.AppNotifications;
using UniGetUI.Controls.OperationWidgets;
using UniGetUI.Interface.Telemetry;
using UniGetUI.PackageEngine.Interfaces;
using UniGetUI.PackageEngine.Managers.PowerShellManager;
using AbstractOperation = UniGetUI.PackageOperations.AbstractOperation;
Expand Down Expand Up @@ -291,6 +292,7 @@ private async Task LoadComponentsAsync()

// Load package managers
await Task.Run(() => PEInterface.Initialize());
TelemetryHandler.Initialize();

Logger.Info("LoadComponentsAsync finished executing. All managers loaded. Proceeding to interface.");
MainWindow.SwitchToInterface();
Expand Down
2 changes: 2 additions & 0 deletions src/UniGetUI/AppOperationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UniGetUI.Core.Logging;
using UniGetUI.Core.Tools;
using UniGetUI.Interface;
using UniGetUI.Interface.Telemetry;
using UniGetUI.PackageEngine.Interfaces;
using UniGetUI.PackageEngine.Managers.CargoManager;
using UniGetUI.PackageEngine.Managers.PowerShellManager;
Expand Down Expand Up @@ -112,6 +113,7 @@ public static void Remove(AbstractOperation op)
var options = await InstallationOptions.FromPackageAsync(package, elevated, interactive, no_integrity);
var op = new InstallPackageOperation(package, options, ignoreParallel, req);
Add(op);
op.OperationSucceeded += (_, _) => TelemetryHandler.PackageInstalled(package);
return op;
}

Expand Down
1 change: 1 addition & 0 deletions src/UniGetUI/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private static void Main(string[] args)
try
{
CoreData.IsDaemon = args.Contains("--daemon");
CoreData.WasDaemon = CoreData.IsDaemon;

if (args.Contains("--uninstall-unigetui") || args.Contains("--uninstall-wingetui"))
{
Expand Down
20 changes: 17 additions & 3 deletions src/UniGetUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,23 @@
<widgets:TranslatedTextBlock x:Name="AppTitle" Text="WingetUI" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" FontSize="12"/>
</StackPanel>
</Border>
<InfoBar Name="UpdatesBanner" x:FieldModifier="public" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" IsOpen="False" Visibility="{x:Bind UpdatesBanner.IsOpen, Mode=OneWay}" Margin="0,0,0,4" CornerRadius="0" BorderThickness="0,1,0,1"/>
<InfoBar Name="ErrorBanner" x:FieldModifier="public" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" IsOpen="False" Visibility="{x:Bind ErrorBanner.IsOpen, Mode=OneWay}" Margin="0,0,0,4" Severity="Error" CornerRadius="0" BorderThickness="0,1,0,1"/>
<InfoBar Name="WinGetWarningBanner" x:FieldModifier="public" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" IsOpen="False" Visibility="{x:Bind WinGetWarningBanner.IsOpen, Mode=OneWay}" Margin="0,0,0,4" Severity="Warning" CornerRadius="0" BorderThickness="0,1,0,1"/>
<StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Spacing="0" Padding="0" Margin="0,-4,0,0">
<InfoBar
Name="UpdatesBanner" x:FieldModifier="public" IsOpen="False"
Visibility="{x:Bind UpdatesBanner.IsOpen, Mode=OneWay}" Margin="0,0,0,4"
CornerRadius="0" BorderThickness="0,1,0,1"/>
<InfoBar
Name="ErrorBanner" x:FieldModifier="public" IsOpen="False"
Visibility="{x:Bind ErrorBanner.IsOpen, Mode=OneWay}" Margin="0,0,0,4"
Severity="Error" CornerRadius="0" BorderThickness="0,1,0,1"/>
<InfoBar
Name="WinGetWarningBanner" x:FieldModifier="public" IsOpen="False"
Visibility="{x:Bind WinGetWarningBanner.IsOpen, Mode=OneWay}" Margin="0,0,0,4"
Severity="Warning" CornerRadius="0" BorderThickness="0,1,0,1"/>
<InfoBar
Name="TelemetryWarner" x:FieldModifier="public" IsOpen="False"
Margin="0,0,0,4" Severity="Informational" CornerRadius="0" BorderThickness="0,1,0,1"/>
</StackPanel>
</Grid>
<Grid Grid.Row="0" Grid.Column="0" x:Name="LoadingWindow" Visibility="Visible"
Background="{StaticResource ProgressBarBorderThemeBrush}">
Expand Down
Loading

0 comments on commit 0e8a527

Please sign in to comment.