Skip to content

Commit

Permalink
Miscellaneous fixes for .NET 8 (#767)
Browse files Browse the repository at this point in the history
* Use Microsoft.AspNetCore.WebUtilities

* Add NoDisplay=true to the XDG Desktop Entry
  • Loading branch information
erri120 authored Nov 13, 2023
1 parent f699d8e commit d2908c1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</ItemGroup>
<ItemGroup>
<!-- Microsoft -->
<PackageVersion Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.0-rc.2.23480.2" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="7.0.13" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
Expand Down Expand Up @@ -100,4 +101,4 @@
<PackageVersion Include="Splat.Microsoft.Extensions.Logging" Version="14.6.37" />
<PackageVersion Include="Vogen" Version="3.0.20" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="System.Linq.Async" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" />
</ItemGroup>

<ItemGroup>
Expand Down
29 changes: 3 additions & 26 deletions src/Networking/NexusMods.Networking.NexusWebApi.NMA/OAuth.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reactive.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using Microsoft.AspNetCore.WebUtilities;

Check warning on line 5 in src/Networking/NexusMods.Networking.NexusWebApi.NMA/OAuth.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using Microsoft.Extensions.Logging;
using NexusMods.Common;
using NexusMods.Common.OSInterop;

Check warning on line 8 in src/Networking/NexusMods.Networking.NexusWebApi.NMA/OAuth.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
Expand Down Expand Up @@ -132,8 +132,7 @@ private IInterprocessJob CreateJob(Uri url)

internal static Uri GenerateAuthorizeUrl(string challenge, string state)
{
// TODO: switch to Microsoft.AspNetCore.WebUtilities when .NET 8 is available
var request = new Dictionary<string, string>
var request = new Dictionary<string, string?>
{
{ "response_type", "code" },
{ "scope", "openid profile email" },
Expand All @@ -144,28 +143,6 @@ internal static Uri GenerateAuthorizeUrl(string challenge, string state)
{ "state", state },

Check notice on line 143 in src/Networking/NexusMods.Networking.NexusWebApi.NMA/OAuth.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use preferred style for trailing comma before new line in multiline lists

Remove trailing comma to conform to code style
};

return new Uri($"{OAuthUrl}/authorize{CreateQueryString(request)}");
}

private static string CreateQueryString(Dictionary<string, string> parameters)
{
var builder = new StringBuilder();
var first = true;
foreach (var pair in parameters)
{
var (key, value) = pair;

builder.Append(first ? '?' : '&');
builder.Append(UrlEncoder.Default.Encode(key));
builder.Append('=');
if (!string.IsNullOrEmpty(value))
{
builder.Append(UrlEncoder.Default.Encode(value));
}

first = false;
}

return builder.ToString();
return new Uri(QueryHelpers.AddQueryString($"{OAuthUrl}/authorize", request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public ProtocolRegistrationLinux(IProcessFactory processFactory, IFileSystem fil
sb.AppendLine($"Path={workingDirectory}");
sb.AppendLine($"Exec={commandLine}");
sb.AppendLine($"MimeType=x-scheme-handler/{protocol}");
sb.AppendLine("NoDisplay=true");

await desktopEntryFile.WriteAllTextAsync(sb.ToString());

Expand Down

0 comments on commit d2908c1

Please sign in to comment.