-
-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3237 from marticliment/telemetry
- Loading branch information
Showing
18 changed files
with
349 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
77 | ||
78 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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])"; | ||
|
||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 14 additions & 5 deletions
19
src/UniGetUI.Interface.Enums/UniGetUI.Interface.Enums.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/UniGetUI.Interface.Telemetry/UniGetUI.Interface.Telemetry.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.