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 src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<WindowsSdkPackageVersion>10.0.26100.57</WindowsSdkPackageVersion>
<WindowsSdkPackageVersion>10.0.26100.56</WindowsSdkPackageVersion>
<SdkVersion>8.0.407</SdkVersion>
<Authors>Martí Climent and the contributors</Authors>
<PublisherName>Martí Climent</PublisherName>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using UniGetUI.Core.Logging;
using UniGetUI.Core.Tools;
using UniGetUI.Interface.Enums;
using UniGetUI.PackageEngine.Interfaces;
Expand Down Expand Up @@ -66,5 +67,46 @@ protected override Task WhenAddingPackage(IPackage package)
}
return Task.CompletedTask;
}

public (IPackage?, string?) GetPackageFromIdAndManager(string id, string managerName, string sourceName)
{
IPackageManager? manager = null;

foreach (var candidate in Managers)
{
if (candidate.Name == managerName || candidate.DisplayName == managerName)
{
manager = candidate;
break;
}
}

if (manager is null)
return (null, CoreTools.Translate("The package manager \"{0}\" was not found", managerName));

if (!manager.IsEnabled())
return (null, CoreTools.Translate("The package manager \"{0}\" is disabled", manager.DisplayName));

if (!manager.Status.Found)
return (null, CoreTools.Translate("There is an error with the configuration of the package manager \"{0}\"", manager.DisplayName));

var results = manager.FindPackages(id);
var candidates = results.Where(p => p.Id == id).ToArray();

if (candidates.Length == 0)
return (null, CoreTools.Translate("The package \"{0}\" was not found on the package manager \"{1}\"", id, manager.DisplayName));

IPackage package = candidates[0];

// Get package from best source
if (candidates.Length >= 1 && manager.Capabilities.SupportsCustomSources)
foreach (var candidate in candidates)
{
if (candidate.Source.Name == sourceName)
package = candidate;
}

return (package, null);
}
}
}
628 changes: 628 additions & 0 deletions src/UniGetUI/App.xaml

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions src/UniGetUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using UniGetUI.Interface.Telemetry;
using UniGetUI.PackageEngine.Interfaces;
using LaunchActivatedEventArgs = Microsoft.UI.Xaml.LaunchActivatedEventArgs;
using UniGetUI.Pages.DialogPages;
using UniGetUI.Interface.Enums;

namespace UniGetUI
{
Expand Down Expand Up @@ -227,23 +229,22 @@ private async Task LoadComponentsAsync()

BackgroundApi.OnShowSharedPackage += (_, package) => MainWindow.DispatcherQueue.TryEnqueue(() =>
{
MainWindow?.NavigationPage?.DiscoverPage.ShowSharedPackage_ThreadSafe(package.Key, package.Value);
MainWindow?.Activate();
DialogHelper.ShowSharedPackage_ThreadSafe(package.Key, package.Value);
});

BackgroundApi.OnUpgradeAll += (_, _) => MainWindow.DispatcherQueue.TryEnqueue(() =>
{
MainWindow?.NavigationPage?.UpdatesPage.UpdateAll();
Operations.UpdateAll();
});

BackgroundApi.OnUpgradeAllForManager += (_, manager) => MainWindow.DispatcherQueue.TryEnqueue(() =>
BackgroundApi.OnUpgradeAllForManager += (_, managerName) => MainWindow.DispatcherQueue.TryEnqueue(async () =>
{
MainWindow?.NavigationPage?.UpdatesPage.UpdateAllPackagesForManager(manager);
Operations.UpdateAllForManager(managerName);
});

BackgroundApi.OnUpgradePackage += (_, package) => MainWindow.DispatcherQueue.TryEnqueue(() =>
BackgroundApi.OnUpgradePackage += (_, packageId) => MainWindow.DispatcherQueue.TryEnqueue(() =>
{
MainWindow?.NavigationPage?.UpdatesPage.UpdatePackageForId(package);
Operations.UpdateForId(packageId);
});

_ = BackgroundApi.Start();
Expand Down
34 changes: 34 additions & 0 deletions src/UniGetUI/AppOperationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using UniGetUI.PackageEngine.PackageClasses;
using UniGetUI.PackageOperations;
using UniGetUI.Pages.DialogPages;
using UniGetUI.Interface.Enums;
using UniGetUI.PackageEngine;

namespace UniGetUI;

Expand Down Expand Up @@ -163,6 +165,38 @@ public static void Update(IReadOnlyList<IPackage> packages, bool? elevated = nul
}
}

public static async void UpdateAll()
{
foreach (IPackage package in PEInterface.UpgradablePackagesLoader.Packages)
if (package.Tag is not PackageTag.BeingProcessed and not PackageTag.OnQueue)
await Update(package);
}

public static async void UpdateAllForManager(string managerName)
{
foreach (IPackage package in PEInterface.UpgradablePackagesLoader.Packages)
{
if (package.Tag is not PackageTag.OnQueue and not PackageTag.BeingProcessed
&& package.Manager.Name == managerName || package.Manager.DisplayName == managerName)
await Update(package);
}
}

public static async void UpdateForId(string packageId)
{
foreach (IPackage package in PEInterface.UpgradablePackagesLoader.Packages)
{
if (package.Id == packageId)
{
await Update(package);
Logger.Info($"[WIDGETS] Updating package with id {packageId}");
return;
}
}

Logger.Warn($"[WIDGETS] No package with id={packageId} was found");
}

/*
* PACKAGE UNINSTALL
*/
Expand Down
33 changes: 33 additions & 0 deletions src/UniGetUI/Controls/LocalIcon.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
Expand Down Expand Up @@ -25,6 +26,38 @@ public LocalIcon(IconType icon) : this()
}
}

public static class IconBuilder
{
private static FontFamily customFont = null!;
private static FontFamily symbolFont = null!;

public static IconType SetIcon(this TextBlock block, IconType icon)
{
customFont ??= (FontFamily)Application.Current.Resources["SymbolFont"];
block.Text = $"{(char)icon}";
block.FontFamily = customFont;
return icon;
}

public static IconType GetIcon(this TextBlock block)
{
return IconType.Help;
}

public static string SetGlyph(this TextBlock block, string glyph)
{
symbolFont ??= new FontFamily("Segoe Fluent Icons");
block.Text = glyph;
block.FontFamily = symbolFont;
return glyph;
}

public static string GetGlyph(this TextBlock block)
{
return block.Text;
}
}

public partial class LocalIconSource : FontIconSource
{
public static FontFamily font = (FontFamily)Application.Current.Resources["SymbolFont"];
Expand Down
24 changes: 24 additions & 0 deletions src/UniGetUI/Controls/MenuForPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,28 @@ public BetterMenuItem()
Style = menuStyle;
}
}

public partial class BetterToggleMenuItem : ToggleMenuFlyoutItem
{
private readonly Style menuStyle = (Style)Application.Current.Resources["BetterToggleMenuItem"];

public IconType IconName
{
set
{
var icon = new LocalIcon(value) { FontSize = 24 };
Icon = icon;
}
}

public new string Text
{
set => base.Text = CoreTools.Translate(value);
}

public BetterToggleMenuItem()
{
Style = menuStyle;
}
}
}
9 changes: 7 additions & 2 deletions src/UniGetUI/Controls/ObservablePackageCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UniGetUI.Core.Classes;
using UniGetUI.Interface;
using UniGetUI.PackageEngine.Interfaces;

namespace UniGetUI.PackageEngine.PackageClasses
Expand All @@ -17,26 +18,30 @@ public enum Sorter
NewVersion,
Source,
}
public Sorter CurrentSorter { get; private set; }

public ObservablePackageCollection()
{
CurrentSorter = Sorter.Name;
SortingSelector = x => x.Package.Name;
}

/// <summary>
/// Add a package to the collection
/// </summary>
public void Add(IPackage p)
public void Add(IPackage p, AbstractPackagesPage page)
{
base.Add(new PackageWrapper(p));
base.Add(new PackageWrapper(p, page));
}

/// <summary>
/// Sets the property with which to filter the package and sorts the collection
/// </summary>
/// <param name="field">The field with which to sort the collection</param>
///
public void SetSorter(Sorter field)
{
CurrentSorter = field;
switch (field)
{
case Sorter.Checked:
Expand Down
15 changes: 13 additions & 2 deletions src/UniGetUI/Controls/PackageWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.UI.Xaml.Media.Imaging;
using UniGetUI.Core.Classes;
using UniGetUI.Core.Tools;
using UniGetUI.Interface;
using UniGetUI.Interface.Enums;
using UniGetUI.PackageEngine.Interfaces;

Expand Down Expand Up @@ -32,6 +33,7 @@ public bool IsChecked
public bool AlternateIdIconVisible;
public bool ShowCustomPackageIcon;
public bool ShowDefaultPackageIcon = true;
public string VersionComboString;
public IconType MainIconId = IconType.Id;
public IconType AlternateIconId = IconType.Id;
public ImageSource? MainIconSource;
Expand All @@ -57,13 +59,22 @@ public Uri? PackageIcon
public IPackage Package { get; private set; }
public PackageWrapper Self { get; private set; }

public PackageWrapper(IPackage package)
private readonly AbstractPackagesPage _page;

public PackageWrapper(IPackage package, AbstractPackagesPage page)
{
Package = package;
Self = this;
_page = page;
WhenTagHasChanged();
Package.PropertyChanged += Package_PropertyChanged;
UpdatePackageIcon();
VersionComboString = package.IsUpgradable ? $"{package.VersionString} -> {package.NewVersionString}" : package.VersionString;
}

public async void RightClick()
{
await _page.ShowContextMenu(this);
}

public void Package_PropertyChanged(object? sender, PropertyChangedEventArgs e)
Expand Down Expand Up @@ -167,7 +178,7 @@ public void UpdatePackageIcon()
MainIconSource = new BitmapImage
{
UriSource = icon,
DecodePixelWidth = 24,
DecodePixelWidth = 64,
DecodePixelType = DecodePixelType.Logical,
};
ShowCustomPackageIcon = true;
Expand Down
9 changes: 4 additions & 5 deletions src/UniGetUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void HandleNotificationActivation(AppNotificationActivatedEventArgs args)

if (action == NotificationArguments.UpdateAllPackages)
{
NavigationPage.UpdatesPage.UpdateAll();
MainApp.Operations.UpdateAll();
}
else if (action == NotificationArguments.ShowOnUpdatesTab)
{
Expand Down Expand Up @@ -360,11 +360,11 @@ private void HandleDeepLink(string link)
if (Id != "" && CombinedManagerName != "" && ManagerName == "" && SourceName == "")
{
Logger.Warn($"URI {link} follows old scheme");
NavigationPage.DiscoverPage.ShowSharedPackage_ThreadSafe(Id, CombinedManagerName);
DialogHelper.ShowSharedPackage_ThreadSafe(Id, CombinedManagerName);
}
else if (Id != "" && ManagerName != "" && SourceName != "")
{
NavigationPage.DiscoverPage.ShowSharedPackage_ThreadSafe(Id, ManagerName, SourceName);
DialogHelper.ShowSharedPackage_ThreadSafe(Id, ManagerName, SourceName);
}
else
{
Expand Down Expand Up @@ -437,8 +437,7 @@ public void ProcessCommandLineParameters()
{
// Handle potential JSON files
Logger.ImportantInfo("Begin attempt to open the package bundle " + param);
NavigationPage.NavigateTo(PageType.Bundles);
_ = NavigationPage.BundlesPage.OpenFromFile(param);
NavigationPage.LoadBundleFile(param);
}
else if (param.EndsWith("UniGetUI.exe") || param.EndsWith("UniGetUI.dll"))
{
Expand Down
Loading
Loading