Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "10.0.103",
"rollForward": "latestPatch"
"rollForward": "latestFeature"
}
}
2 changes: 1 addition & 1 deletion src/UniGetUI.Avalonia/UniGetUI.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<PackageReference Include="Octokit" Version="14.0.0" />
<PackageReference Include="Avalonia.Controls.WebView" Version="12.0.0" />
<PackageReference Include="Tmds.DBus.Protocol" Version="0.92.0" />
<PackageReference Include="Devolutions.Pinget.Cli.Rust" Version="0.5.0" GeneratePathProperty="true" ExcludeAssets="build;buildTransitive;native" />
<PackageReference Include="Devolutions.Pinget.Cli.Rust" Version="0.6.0" GeneratePathProperty="true" ExcludeAssets="build;buildTransitive;native" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 2 additions & 4 deletions src/UniGetUI.Avalonia/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,11 @@ partial void OnGlobalSearchTextChanged(string value)

private void SubscribeToPageViewModel(AbstractPackagesPage? page)
{
if (_subscribedPageViewModel is not null)
_subscribedPageViewModel.PropertyChanged -= OnPageViewModelPropertyChanged;
_subscribedPageViewModel?.PropertyChanged -= OnPageViewModelPropertyChanged;

_subscribedPageViewModel = page?.ViewModel;

if (_subscribedPageViewModel is not null)
_subscribedPageViewModel.PropertyChanged += OnPageViewModelPropertyChanged;
_subscribedPageViewModel?.PropertyChanged += OnPageViewModelPropertyChanged;
}

private void OnPageViewModelPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
Expand Down
7 changes: 2 additions & 5 deletions src/UniGetUI.Avalonia/Views/Controls/InfoBar.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ public InfoBar()

private void OnDataContextChanged(object? sender, EventArgs e)
{
if (_vm is not null)
_vm.PropertyChanged -= OnViewModelPropertyChanged;
_vm?.PropertyChanged -= OnViewModelPropertyChanged;

_vm = DataContext as InfoBarViewModel;

_vm?.PropertyChanged += OnViewModelPropertyChanged;
if (_vm is not null)
{
_vm.PropertyChanged += OnViewModelPropertyChanged;
ApplySeverity(_vm.Severity);
}
}

private void OnViewModelPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ internal sealed partial class PingetCliHelper : IWinGetManagerHelper
private static readonly JsonSerializerOptions SerializationOptions = new()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
};
private static readonly PingetCliJsonContext SerializationContext = new(SerializationOptions);

Expand Down Expand Up @@ -55,7 +54,7 @@ public IReadOnlyList<Package> GetAvailableUpdates_UnSafe()
match.Id,
match.InstalledVersion,
match.AvailableVersion!,
GetSource(match.SourceName, match.Id),
GetSource(match),
Manager
);

Expand Down Expand Up @@ -87,7 +86,7 @@ public IReadOnlyList<Package> GetInstalledPackages_UnSafe()
match.Name,
match.Id,
match.InstalledVersion,
GetSource(match.SourceName, match.Id),
GetSource(match),
Manager
)
)
Expand Down Expand Up @@ -234,6 +233,32 @@ internal static T DeserializeJson<T>(string output)
: throw new InvalidOperationException("Pinget returned empty JSON output.");
}

internal static string? InferSourceName(ListMatch match)
{
if (!string.IsNullOrWhiteSpace(match.SourceName))
{
return match.SourceName;
}

if (match.Id.Contains("_Microsoft.Winget.Source_8wekyb3d8bbwe", StringComparison.OrdinalIgnoreCase))
{
return "winget";
}

if (!string.IsNullOrWhiteSpace(match.InstallLocation)
&& match.InstallLocation.Contains("\\Microsoft\\WinGet\\Packages\\", StringComparison.OrdinalIgnoreCase))
{
return "winget";
}

return null;
}

private IManagerSource GetSource(ListMatch match)
{
return GetSource(InferSourceName(match), match.Id);
}

private IManagerSource GetSource(string? sourceName, string packageId)
{
if (string.IsNullOrWhiteSpace(sourceName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ private IReadOnlyList<string> GetSourceNames(INativeTaskLogger logger)
{
try
{
string output = RunPinget(["source", "list", "--output", "json"], logger);
string output = RunPinget(["source", "export", "--output", "json"], logger);
using JsonDocument document = JsonDocument.Parse(output);
if (
!document.RootElement.TryGetProperty("sources", out JsonElement sources)
!document.RootElement.TryGetProperty("Sources", out JsonElement sources)
|| sources.ValueKind != JsonValueKind.Array
)
{
Expand All @@ -97,7 +97,7 @@ private IReadOnlyList<string> GetSourceNames(INativeTaskLogger logger)
return sources
.EnumerateArray()
.Select(source =>
source.TryGetProperty("name", out JsonElement name)
source.TryGetProperty("Name", out JsonElement name)
? name.GetString()
: null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Devolutions.Pinget.Core" Version="0.5.0" />
<PackageReference Include="Devolutions.Pinget.Core" Version="0.6.0" />
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
</ItemGroup>
</Project>
66 changes: 49 additions & 17 deletions src/UniGetUI.PackageEngine.Tests/WinGetManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,28 +300,28 @@ public void FindCandidateExecutableFilesReturnsEmptyWhenNoCliToolExists()
[Fact]
public void PingetCliHelperDeserializesListResponsesWithGeneratedContext()
{
// pinget 0.4.1+ emits snake_case keys.
// Pinget emits PascalCase keys.
const string json = """
{
"matches": [
"Matches": [
{
"name": "Contoso Tool",
"id": "Contoso.Tool",
"local_id": null,
"installed_version": "1.2.3",
"available_version": "2.0.0",
"source_name": "winget",
"publisher": null,
"scope": null,
"installer_category": null,
"install_location": null,
"package_family_names": [],
"product_codes": [],
"upgrade_codes": []
"Name": "Contoso Tool",
"Id": "Contoso.Tool",
"LocalId": null,
"InstalledVersion": "1.2.3",
"AvailableVersion": "2.0.0",
"SourceName": "winget",
"Publisher": null,
"Scope": null,
"InstallerCategory": null,
"InstallLocation": null,
"PackageFamilyNames": [],
"ProductCodes": [],
"UpgradeCodes": []
}
],
"warnings": [],
"truncated": false
"Warnings": [],
"Truncated": false
}
""";

Expand All @@ -335,6 +335,38 @@ public void PingetCliHelperDeserializesListResponsesWithGeneratedContext()
Assert.Equal("winget", match.SourceName);
}

[Fact]
public void PingetCliHelperInfersWingetSourceWhenInstalledSourceNameIsMissing()
{
const string json = """
{
"Matches": [
{
"Name": "Contoso Tool",
"Id": "ARP\\User\\X64\\Contoso.Tool_Microsoft.Winget.Source_8wekyb3d8bbwe",
"LocalId": null,
"InstalledVersion": "1.2.3",
"AvailableVersion": null,
"SourceName": null,
"Publisher": "Contoso",
"Scope": "User",
"InstallerCategory": "exe",
"InstallLocation": "C:\\Users\\example\\AppData\\Local\\Microsoft\\WinGet\\Packages\\Contoso.Tool_Microsoft.Winget.Source_8wekyb3d8bbwe",
"PackageFamilyNames": [],
"ProductCodes": [],
"UpgradeCodes": []
}
],
"Warnings": [],
"Truncated": false
}
""";

ListMatch match = Assert.Single(PingetCliHelper.DeserializeJson<ListResponse>(json).Matches);

Assert.Equal("winget", PingetCliHelper.InferSourceName(match));
}

[Fact]
public void GetCliToolPreferenceUsesEnvironmentBeforeSettings()
{
Expand Down
10 changes: 2 additions & 8 deletions src/UniGetUI/Controls/PackageItemContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ public PackageWrapper Wrapper
get => _wrapper;
set
{
if (_wrapper != null)
{
_wrapper.PropertyChanged -= Wrapper_PropertyChanged;
}
_wrapper?.PropertyChanged -= Wrapper_PropertyChanged;
_wrapper = value;
if (_wrapper != null)
{
_wrapper.PropertyChanged += Wrapper_PropertyChanged;
}
_wrapper?.PropertyChanged += Wrapper_PropertyChanged;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/UniGetUI/UniGetUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
<PackageReference Include="IdentityModel.OidcClient" Version="6.0.0" />
<PackageReference Include="Octokit" Version="14.0.0" />
<PackageReference Include="Devolutions.UniGetUI.Elevator" Version="2.6.1.3" GeneratePathProperty="true" ExcludeAssets="build;buildTransitive;native" />
<PackageReference Include="Devolutions.Pinget.Cli.Rust" Version="0.5.0" GeneratePathProperty="true" ExcludeAssets="build;buildTransitive;native" />
<PackageReference Include="Devolutions.Pinget.Cli.Rust" Version="0.6.0" GeneratePathProperty="true" ExcludeAssets="build;buildTransitive;native" />

<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
Expand Down
Loading