Skip to content

Commit 310d948

Browse files
committed
fix(Updater): User agent missing to check for update
Currently the update ... are broken since 5.10
1 parent 5970c4b commit 310d948

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

SoundSwitch/Framework/Updater/UpdateChecker.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System;
1616
using System.Linq;
1717
using System.Net.Http;
18+
using System.Net.Http.Headers;
1819
using System.Net.Http.Json;
1920
using System.Text.RegularExpressions;
2021
using System.Threading;
@@ -34,6 +35,8 @@ public class UpdateChecker
3435

3536
private readonly Uri _releaseUrl;
3637
public EventHandler<NewReleaseEvent> UpdateAvailable;
38+
private static readonly ProductInfoHeaderValue ProductValue;
39+
private static readonly ProductInfoHeaderValue CommentValue;
3740
public bool Beta { get; set; }
3841

3942
public UpdateChecker(Uri releaseUrl) : this(releaseUrl, false)
@@ -46,6 +49,12 @@ public UpdateChecker(Uri releaseUrl, bool checkBeta)
4649
Beta = checkBeta;
4750
}
4851

52+
static UpdateChecker()
53+
{
54+
ProductValue = new ProductInfoHeaderValue(Application.ProductName, Application.ProductVersion);
55+
CommentValue = new ProductInfoHeaderValue("(+https://soundwitch.aaflalo.me)");
56+
}
57+
4958
private bool ProcessRelease(GitHubRelease serverRelease)
5059
{
5160
Log.Information("Checking version {version} ", serverRelease);
@@ -66,7 +75,6 @@ private bool ProcessRelease(GitHubRelease serverRelease)
6675
return false;
6776
}
6877

69-
7078

7179
var changelog = Regex.Split(serverRelease.body, "\r\n|\r|\n");
7280
var release = new Release(version, installer, serverRelease.name);
@@ -82,13 +90,16 @@ private bool ProcessRelease(GitHubRelease serverRelease)
8290

8391
return false;
8492
}
85-
93+
8694
/// <summary>
8795
/// Check for update
8896
/// </summary>
8997
public async Task CheckForUpdate(CancellationToken token)
9098
{
9199
using var httpClient = new HttpClient(new SentryHttpMessageHandler());
100+
httpClient.DefaultRequestHeaders.UserAgent.Add(ProductValue);
101+
httpClient.DefaultRequestHeaders.UserAgent.Add(CommentValue);
102+
httpClient.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
92103
var releases = await httpClient.GetFromJsonAsync<GitHubRelease[]>(_releaseUrl, token);
93104
foreach (var release in releases ?? Array.Empty<GitHubRelease>())
94105
{

SoundSwitch/Program.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private static void Main()
4848
{
4949
Dsn = "https://[email protected]/5755327",
5050
Environment = AssemblyUtils.GetReleaseState().ToString(),
51-
Release = Application.ProductVersion,
51+
Release = $"{Application.ProductName}@{Application.ProductVersion}",
5252
};
5353
var contribOptions = new ContribSentryOptions(true, true, true)
5454
{
@@ -125,20 +125,20 @@ private static void Main()
125125
try
126126
{
127127
#endif
128-
MMNotificationClient.Instance.Register();
128+
MMNotificationClient.Instance.Register();
129129

130130

131-
using var ctx = new WindowsFormsSynchronizationContext();
131+
using var ctx = new WindowsFormsSynchronizationContext();
132132

133-
SynchronizationContext.SetSynchronizationContext(ctx);
134-
try
135-
{
136-
Application.Run(new SoundSwitchApplicationContext());
137-
}
138-
finally
139-
{
140-
SynchronizationContext.SetSynchronizationContext(null);
141-
}
133+
SynchronizationContext.SetSynchronizationContext(ctx);
134+
try
135+
{
136+
Application.Run(new SoundSwitchApplicationContext());
137+
}
138+
finally
139+
{
140+
SynchronizationContext.SetSynchronizationContext(null);
141+
}
142142

143143

144144
#if !DEBUG

0 commit comments

Comments
 (0)