Skip to content

Commit 0dddfab

Browse files
Support full trim publishing (#5053)
1 parent cc7c33e commit 0dddfab

13 files changed

Lines changed: 534 additions & 134 deletions

File tree

‎.github/workflows/dotnet-test.yml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,21 @@ jobs:
7777
env:
7878
GITHUB_TOKEN: ${{ github.token }}
7979
run: dotnet test UniGetUI.Windows.slnx --no-restore --verbosity q --nologo /p:Platform=x64 /p:UseSharedCompilation=false /m:1
80+
81+
- name: Report full-trim publish warnings
82+
working-directory: src
83+
shell: pwsh
84+
continue-on-error: true
85+
run: |
86+
dotnet build-server shutdown
87+
dotnet publish UniGetUI.Avalonia/UniGetUI.Avalonia.csproj `
88+
--no-restore `
89+
--configuration Release `
90+
--runtime win-x64 `
91+
--self-contained true `
92+
--output "${{ runner.temp }}\unigetui-full-trim-publish" `
93+
/p:Platform=x64 `
94+
/p:TrimMode=full `
95+
/p:TrimmerSingleWarn=false `
96+
/p:UseSharedCompilation=false `
97+
--verbosity minimal

‎src/UniGetUI.Avalonia/App.axaml.cs‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#if AVALONIA_DIAGNOSTICS_ENABLED
1212
using Avalonia.Diagnostics;
1313
#endif
14+
using UniGetUI.Avalonia.Assets.Styles;
1415
using UniGetUI.Avalonia.Infrastructure;
1516
using UniGetUI.Avalonia.Views;
1617
using UniGetUI.Avalonia.Views.DialogPages;
@@ -37,18 +38,9 @@ public override void Initialize()
3738
#endif
3839
}
3940

40-
// ResourceInclude is flagged with RequiresUnreferencedCode because, in general, it can load
41-
// resources from other assemblies that trimming might remove. Styles.WindowsMica.axaml is an
42-
// avares resource embedded in THIS assembly, so it is never trimmed — the warning is safe to
43-
// suppress here. (It can't be declared in XAML because the merge is conditional at runtime.)
44-
[UnconditionalSuppressMessage("Trimming", "IL2026",
45-
Justification = "Styles.WindowsMica.axaml is an avares resource in this assembly and is not trimmed.")]
4641
private void ApplyWindowsMicaStyling()
4742
{
48-
Resources.MergedDictionaries.Add(new ResourceInclude((Uri?)null)
49-
{
50-
Source = new Uri("avares://UniGetUI/Assets/Styles/Styles.WindowsMica.axaml")
51-
});
43+
Resources.MergedDictionaries.Add(new WindowsMicaStyles());
5244
// Give flyouts/menus/tooltips a native acrylic backdrop (DWM) so they blur + tint
5345
// from behind and adapt to the theme.
5446
MicaWindowHelper.EnableAcrylicPopups();

‎src/UniGetUI.Avalonia/Assets/Styles/Styles.WindowsMica.axaml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<ResourceDictionary xmlns="https://github.com/avaloniaui"
2-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
x:Class="UniGetUI.Avalonia.Assets.Styles.WindowsMicaStyles">
34
<!--
45
Windows 11 Mica overrides. Merged into Application.Resources ONLY when Mica is
56
actually active (Windows 11 + "Transparency effects" on) — see App.Initialize().
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Avalonia.Controls;
2+
using Avalonia.Markup.Xaml;
3+
4+
namespace UniGetUI.Avalonia.Assets.Styles;
5+
6+
public partial class WindowsMicaStyles : ResourceDictionary
7+
{
8+
public WindowsMicaStyles()
9+
{
10+
AvaloniaXamlLoader.Load(this);
11+
}
12+
}

‎src/UniGetUI.Avalonia/Infrastructure/AppShortcutAumidStamper.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#if WINDOWS
22
using System;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.IO;
45
using System.Runtime.InteropServices;
56
using UniGetUI.Core.Logging;
@@ -61,6 +62,10 @@ public static void EnsureStamped()
6162
return File.Exists(commonPath) ? commonPath : null;
6263
}
6364

65+
[UnconditionalSuppressMessage(
66+
"Trimming",
67+
"IL2072",
68+
Justification = "ShellLink COM activation uses the shell-registered CLSID and COM interfaces declared below; it does not depend on app-owned constructors trimmed from this assembly.")]
6469
private static void StampIfMissing(string shortcutPath)
6570
{
6671
// ShellLink (CLSID 00021401-0000-0000-C000-000000000046) implements IPersistFile and

‎src/UniGetUI.Avalonia/Infrastructure/GitHubAuthService.cs‎

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using Octokit;
21
using UniGetUI.Core.Data;
32
using UniGetUI.Core.Logging;
43
using UniGetUI.Core.SecureSettings;
54
using UniGetUI.Core.Tools;
5+
using UniGetUI.Interface;
66
using CoreSettings = UniGetUI.Core.SettingsEngine.Settings;
77

88
namespace UniGetUI.Avalonia.Infrastructure;
@@ -15,25 +15,18 @@ internal sealed class GitHubAuthService
1515
private readonly string _gitHubClientId = Secrets.GetGitHubClientId();
1616
private readonly string _gitHubClientSecret = Secrets.GetGitHubClientSecret();
1717
private const string RedirectUri = "http://127.0.0.1:58642/";
18-
private readonly GitHubClient _client;
1918

2019
public static event EventHandler<EventArgs>? AuthStatusChanged;
2120

22-
public GitHubAuthService()
23-
{
24-
_client = new GitHubClient(new ProductHeaderValue("UniGetUI", CoreData.VersionName));
25-
}
21+
public GitHubAuthService() { }
2622

27-
public static GitHubClient? CreateGitHubClient()
23+
public static GitHubApiClient? CreateGitHubClient()
2824
{
2925
var token = SecureGHTokenManager.GetToken();
3026
if (string.IsNullOrEmpty(token))
3127
return null;
3228

33-
return new GitHubClient(new ProductHeaderValue("UniGetUI", CoreData.VersionName))
34-
{
35-
Credentials = new Credentials(token),
36-
};
29+
return new GitHubApiClient(token);
3730
}
3831

3932
private GHAuthApiRunner? _loginBackend;
@@ -53,13 +46,11 @@ public async Task<bool> SignInAsync()
5346

5447
Logger.Info("Initiating GitHub sign-in process using loopback redirect...");
5548

56-
var request = new OauthLoginRequest(_gitHubClientId)
57-
{
58-
Scopes = { "read:user", "gist" },
59-
RedirectUri = new Uri(RedirectUri),
60-
};
61-
62-
var oauthLoginUrl = _client.Oauth.GetGitHubLoginUrl(request);
49+
var oauthLoginUrl = GitHubApiClient.GetOAuthLoginUrl(
50+
_gitHubClientId,
51+
new Uri(RedirectUri),
52+
["read:user", "gist"]
53+
);
6354

6455
_codeFromApi = null;
6556
_loginWasCancelled = false;
@@ -141,11 +132,13 @@ private async Task<bool> CompleteSignInAsync(string code)
141132
{
142133
try
143134
{
144-
var tokenRequest = new OauthTokenRequest(_gitHubClientId, _gitHubClientSecret, code)
145-
{
146-
RedirectUri = new Uri(RedirectUri), // The same redirect_uri must be sent
147-
};
148-
var token = await _client.Oauth.CreateAccessToken(tokenRequest);
135+
using var client = new GitHubApiClient();
136+
var token = await client.CreateAccessTokenAsync(
137+
_gitHubClientId,
138+
_gitHubClientSecret,
139+
code,
140+
new Uri(RedirectUri)
141+
);
149142

150143
if (string.IsNullOrEmpty(token.AccessToken))
151144
{
@@ -157,11 +150,8 @@ private async Task<bool> CompleteSignInAsync(string code)
157150
Logger.Info("GitHub login successful. Storing access token.");
158151
SecureGHTokenManager.StoreToken(token.AccessToken);
159152

160-
var userClient = new GitHubClient(new ProductHeaderValue("UniGetUI"))
161-
{
162-
Credentials = new Credentials(token.AccessToken),
163-
};
164-
var user = await userClient.User.Current();
153+
using var userClient = new GitHubApiClient(token.AccessToken);
154+
var user = await userClient.GetCurrentUserAsync();
165155
if (user is not null)
166156
{
167157
CoreSettings.SetValue(CoreSettings.K.GitHubUserLogin, user.Login);

‎src/UniGetUI.Avalonia/Infrastructure/GitHubCloudBackupService.cs‎

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using Octokit;
2-
using UniGetUI.Core.Data;
31
using UniGetUI.Core.SecureSettings;
42
using UniGetUI.Core.Tools;
3+
using UniGetUI.Interface;
54

65
namespace UniGetUI.Avalonia.Infrastructure;
76

@@ -20,56 +19,48 @@ internal sealed class CloudBackupEntry
2019
public required string Display { get; init; }
2120
}
2221

23-
public static GitHubClient? CreateGitHubClient()
22+
public static GitHubApiClient? CreateGitHubClient()
2423
{
2524
string? token = SecureGHTokenManager.GetToken();
2625
if (string.IsNullOrWhiteSpace(token))
2726
return null;
2827

29-
return new GitHubClient(new ProductHeaderValue("UniGetUI", CoreData.VersionName))
30-
{
31-
Credentials = new Credentials(token),
32-
};
28+
return new GitHubApiClient(token);
3329
}
3430

3531
public static async Task<(string Login, string DisplayName)> GetCurrentUserAsync()
3632
{
37-
var client = CreateGitHubClient()
33+
using var client = CreateGitHubClient()
3834
?? throw new InvalidOperationException(CoreTools.Translate("Log in to enable cloud backup"));
3935

40-
var user = await client.User.Current();
36+
var user = await client.GetCurrentUserAsync();
4137
string login = user.Login ?? string.Empty;
4238
string displayName = string.IsNullOrWhiteSpace(user.Name) ? login : user.Name;
4339
return (login, displayName);
4440
}
4541

4642
public static async Task UploadPackageBundleAsync(string bundleContents)
4743
{
48-
var client = CreateGitHubClient()
44+
using var client = CreateGitHubClient()
4945
?? throw new InvalidOperationException(CoreTools.Translate("Log in to enable cloud backup"));
5046

51-
var user = await client.User.Current();
52-
var backupGist = await GetBackupGistAsync(client, user.Login, createIfMissing: true)
47+
var backupGist = await GetBackupGistAsync(client, createIfMissing: true)
5348
?? throw new InvalidOperationException(CoreTools.Translate("Backup Failed"));
5449

5550
string fileKey = BuildGistFileKey();
56-
var update = new GistUpdate { Description = GistDescription };
57-
58-
if (backupGist.Files.ContainsKey(fileKey))
59-
update.Files[fileKey] = new GistFileUpdate { Content = bundleContents };
60-
else
61-
update.Files.Add(fileKey, new GistFileUpdate { Content = bundleContents });
62-
63-
await client.Gist.Edit(backupGist.Id, update);
51+
await client.EditGistAsync(
52+
backupGist.Id,
53+
GistDescription,
54+
new Dictionary<string, string> { [fileKey] = bundleContents }
55+
);
6456
}
6557

6658
public static async Task<IReadOnlyList<CloudBackupEntry>> GetAvailableBackupsAsync()
6759
{
68-
var client = CreateGitHubClient()
60+
using var client = CreateGitHubClient()
6961
?? throw new InvalidOperationException(CoreTools.Translate("Log in to enable cloud backup"));
7062

71-
var user = await client.User.Current();
72-
var backupGist = await GetBackupGistAsync(client, user.Login, createIfMissing: false);
63+
var backupGist = await GetBackupGistAsync(client, createIfMissing: false);
7364
if (backupGist is null)
7465
return [];
7566

@@ -85,16 +76,15 @@ public static async Task<IReadOnlyList<CloudBackupEntry>> GetAvailableBackupsAsy
8576

8677
public static async Task<string> GetBackupContentsAsync(string backupKey)
8778
{
88-
var client = CreateGitHubClient()
79+
using var client = CreateGitHubClient()
8980
?? throw new InvalidOperationException(CoreTools.Translate("Log in to enable cloud backup"));
9081

91-
var user = await client.User.Current();
92-
var backupGist = await GetBackupGistAsync(client, user.Login, createIfMissing: false);
82+
var backupGist = await GetBackupGistAsync(client, createIfMissing: false);
9383

9484
if (backupGist is null)
9585
throw new KeyNotFoundException(CoreTools.Translate("Log in to enable cloud backup"));
9686

97-
var fullGist = await client.Gist.Get(backupGist.Id);
87+
var fullGist = await client.GetGistAsync(backupGist.Id);
9888
var file = fullGist.Files.FirstOrDefault(f =>
9989
f.Key.StartsWith(PackageBackupStartingKey, StringComparison.Ordinal)
10090
&& f.Key.EndsWith(backupKey, StringComparison.Ordinal));
@@ -105,18 +95,23 @@ public static async Task<string> GetBackupContentsAsync(string backupKey)
10595
return file.Value.Content;
10696
}
10797

108-
private static async Task<Gist?> GetBackupGistAsync(GitHubClient client, string userLogin, bool createIfMissing)
98+
private static async Task<GitHubGist?> GetBackupGistAsync(
99+
GitHubApiClient client,
100+
bool createIfMissing
101+
)
109102
{
110-
var candidates = await client.Gist.GetAllForUser(userLogin);
103+
var candidates = await client.GetCurrentUserGistsAsync();
111104
var backupGist = candidates.FirstOrDefault(g =>
112105
g.Description?.EndsWith(GistDescriptionEndingKey, StringComparison.Ordinal) == true);
113106

114107
if (backupGist is not null || !createIfMissing)
115108
return backupGist;
116109

117-
var newGist = new NewGist { Description = GistDescription, Public = false };
118-
newGist.Files.Add("- UniGetUI Package Backups", ReadMeContents);
119-
return await client.Gist.Create(newGist);
110+
return await client.CreateGistAsync(
111+
GistDescription,
112+
isPublic: false,
113+
new Dictionary<string, string> { ["- UniGetUI Package Backups"] = ReadMeContents }
114+
);
120115
}
121116

122117
private static string BuildGistFileKey()

‎src/UniGetUI.Avalonia/UniGetUI.Avalonia.csproj‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
2323
<ApplicationManifest Condition="$([MSBuild]::IsOSPlatform('Windows'))">app.manifest</ApplicationManifest>
2424
<PublishTrimmed>true</PublishTrimmed>
25-
<TrimMode>partial</TrimMode>
25+
<TrimMode>full</TrimMode>
2626
<PublishSingleFile>false</PublishSingleFile>
2727
<IncludeAvaloniaPublishSymbols>false</IncludeAvaloniaPublishSymbols>
2828
</PropertyGroup>
2929

3030
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
31-
<NoWarn>$(NoWarn);MVVMTK0045</NoWarn>
31+
<!-- Parameterized windows/base views are directly constructed in code, not through the runtime XAML loader. -->
32+
<NoWarn>$(NoWarn);MVVMTK0045;AVLN3001</NoWarn>
3233
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
3334
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == '' and '$(Platform)' == 'arm64'">win-arm64</RuntimeIdentifier>
3435
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == '' and ('$(Platform)' == 'x64' or '$(Platform)' == 'x86')">win-$(Platform)</RuntimeIdentifier>
@@ -147,7 +148,6 @@
147148
<PackageReference Include="Devolutions.AvaloniaTheme.Linux" Version="2026.3.11" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
148149
<PackageReference Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.0-beta3" Condition="'$(EnableAvaloniaDiagnostics)' == 'true'" />
149150
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.*" />
150-
<PackageReference Include="Octokit" Version="14.0.0" />
151151
<PackageReference Include="Avalonia.Controls.WebView" Version="12.0.0" />
152152
<PackageReference Include="Tmds.DBus.Protocol" Version="0.92.0" />
153153
<PackageReference Include="Devolutions.UniGetUI.Elevator" Version="2.6.1.3" GeneratePathProperty="true" ExcludeAssets="build;buildTransitive;native" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />

‎src/UniGetUI.Avalonia/ViewModels/Controls/UserAvatarViewModel.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using Avalonia.Media.Imaging;
22
using Avalonia.Threading;
33
using CommunityToolkit.Mvvm.Input;
4-
using Octokit;
54
using UniGetUI.Avalonia.Infrastructure;
65
using UniGetUI.Core.Logging;
76
using UniGetUI.Core.Tools;
7+
using UniGetUI.Interface;
88
using MvvmRelayCommand = CommunityToolkit.Mvvm.Input.RelayCommand;
99

1010
namespace UniGetUI.Avalonia.ViewModels.Controls;
@@ -57,10 +57,10 @@ private async Task RefreshAsync()
5757
{
5858
try
5959
{
60-
var client = GitHubAuthService.CreateGitHubClient();
60+
using var client = GitHubAuthService.CreateGitHubClient();
6161
if (client is not null)
6262
{
63-
User user = await client.User.Current();
63+
GitHubUser user = await client.GetCurrentUserAsync();
6464
displayName = string.IsNullOrEmpty(user.Name)
6565
? $"@{user.Login}"
6666
: $"{user.Name} (@{user.Login})";

‎src/UniGetUI.Avalonia/ViewModels/Pages/SettingsPages/BackupViewModel.cs‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,24 @@ private void GenerateLoginState()
156156

157157
private async Task GenerateLogoutState()
158158
{
159-
var client = GitHubAuthService.CreateGitHubClient()
159+
using var client = GitHubAuthService.CreateGitHubClient()
160160
?? throw new InvalidOperationException("Authenticated but cannot create GitHub client.");
161-
var user = await client.User.Current();
161+
var user = await client.GetCurrentUserAsync();
162162

163163
IsLoggedIn = true;
164-
GitHubUserTitle = CoreTools.Translate("You are logged in as {0} (@{1})", user.Name, user.Login);
164+
string displayName = string.IsNullOrWhiteSpace(user.Name) ? user.Login : user.Name;
165+
GitHubUserTitle = CoreTools.Translate("You are logged in as {0} (@{1})", displayName, user.Login);
165166
GitHubUserSubtitle = CoreTools.Translate("Nice! Backups will be uploaded to a private gist on your account");
166167

167168
try
168169
{
169170
using var http = new HttpClient(CoreTools.GenericHttpClientParameters);
170-
var bytes = await http.GetByteArrayAsync(user.AvatarUrl);
171-
using var ms = new MemoryStream(bytes);
172-
GitHubAvatarBitmap = new Bitmap(ms);
171+
if (!string.IsNullOrWhiteSpace(user.AvatarUrl))
172+
{
173+
var bytes = await http.GetByteArrayAsync(user.AvatarUrl);
174+
using var ms = new MemoryStream(bytes);
175+
GitHubAvatarBitmap = new Bitmap(ms);
176+
}
173177
}
174178
catch (Exception ex)
175179
{

0 commit comments

Comments
 (0)