Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to how page navigation works #2961

Merged
merged 11 commits into from
Nov 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ public List<IPackage> Packages

readonly bool ALLOW_MULTIPLE_PACKAGE_VERSIONS;
readonly bool DISABLE_RELOAD;
private readonly bool PACKAGES_CHECKED_BY_DEFAULT;
protected string LOADER_IDENTIFIER;
private int LoadOperationIdentifier;
protected IEnumerable<IPackageManager> Managers { get; private set; }

public AbstractPackageLoader(IEnumerable<IPackageManager> managers, string identifier, bool AllowMultiplePackageVersions = false, bool DisableReload = false)
public AbstractPackageLoader(IEnumerable<IPackageManager> managers, string identifier, bool AllowMultiplePackageVersions = false, bool DisableReload = false, bool CheckedBydefault = false)
{
Managers = managers;
PackageReference = new ConcurrentDictionary<long, IPackage>();
IsLoaded = false;
IsLoading = false;
PACKAGES_CHECKED_BY_DEFAULT = CheckedBydefault;
DISABLE_RELOAD = DisableReload;
ALLOW_MULTIPLE_PACKAGE_VERSIONS = AllowMultiplePackageVersions;
LOADER_IDENTIFIER = identifier;
Expand Down Expand Up @@ -215,6 +217,7 @@ protected void AddPackage(IPackage package)
return;
}

package.IsChecked = PACKAGES_CHECKED_BY_DEFAULT;
PackageReference.TryAdd(HashPackage(package), package);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class DiscoverablePackagesLoader : AbstractPackageLoader
private string QUERY_TEXT = string.Empty;

public DiscoverablePackagesLoader(IEnumerable<IPackageManager> managers)
: base(managers, "DISCOVERABLE_PACKAGES", AllowMultiplePackageVersions: false)
: base(managers, "DISCOVERABLE_PACKAGES", AllowMultiplePackageVersions: false, CheckedBydefault: false)
{ }

public async Task ReloadPackages(string query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace UniGetUI.PackageEngine.PackageLoader
public class InstalledPackagesLoader : AbstractPackageLoader
{
public InstalledPackagesLoader(IEnumerable<IPackageManager> managers)
: base(managers, "INSTALLED_PACKAGES", AllowMultiplePackageVersions: true)
: base(managers, "INSTALLED_PACKAGES", AllowMultiplePackageVersions: true, CheckedBydefault: false)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace UniGetUI.PackageEngine.PackageLoader
public class PackageBundlesLoader : AbstractPackageLoader
{
public PackageBundlesLoader(IEnumerable<IPackageManager> managers)
: base(managers, "PACKAGE_BUNDLES", AllowMultiplePackageVersions: true, DisableReload: true)
: base(managers, "PACKAGE_BUNDLES", AllowMultiplePackageVersions: true, DisableReload: true, CheckedBydefault: false)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class UpgradablePackagesLoader : AbstractPackageLoader
private System.Timers.Timer? UpdatesTimer;

public UpgradablePackagesLoader(IEnumerable<IPackageManager> managers)
: base(managers, "DISCOVERABLE_PACKAGES", AllowMultiplePackageVersions: false)
: base(managers, "DISCOVERABLE_PACKAGES", AllowMultiplePackageVersions: false, CheckedBydefault: true)
{
FinishedLoading += (_, _) => StartAutoCheckTimeout();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public IPackageDetails Details
public PackageTag Tag
{
get => __tag;
set { __tag = value; OnPropertyChanged(nameof(Tag)); }
set { __tag = value; OnPropertyChanged(); }
}

public bool IsChecked
{
get => __is_checked;
set { __is_checked = value; OnPropertyChanged(nameof(IsChecked)); }
set { __is_checked = value; OnPropertyChanged(); }
}

private OverridenInstallationOptions _overriden_options;
Expand Down Expand Up @@ -124,9 +124,6 @@ public Package(
IsUpgradable = true;
NewVersion = new_version;
NewVersionAsFloat = CoreTools.GetVersionStringAsFloat(new_version);

// Packages in the updates tab are checked by default
IsChecked = true;
}

public long GetHash()
Expand Down
54 changes: 26 additions & 28 deletions src/UniGetUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class __tooltip_options

public bool RaiseExceptionAsFatal = true;

public SettingsInterface settings = null!;
public SettingsPage settings = null!;
public MainWindow MainWindow = null!;
public ThemeListener ThemeListener = null!;

Expand Down Expand Up @@ -239,40 +239,38 @@ private async Task LoadComponentsAsync()

// Bind the background api to the main interface

BackgroundApi.OnOpenWindow += (_, _) => MainWindow.DispatcherQueue.TryEnqueue(() =>
if (!Settings.Get("DisableApi"))
{
MainWindow.Activate();
});

BackgroundApi.OnOpenUpdatesPage += (_, _) => MainWindow.DispatcherQueue.TryEnqueue(() =>
{
MainWindow?.NavigationPage?.UpdatesNavButton.ForceClick();
MainWindow?.Activate();
});
BackgroundApi.OnOpenWindow += (_, _) => MainWindow.DispatcherQueue.TryEnqueue(() => MainWindow.Activate());

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

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

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

BackgroundApi.OnUpgradePackage += (_, package) => MainWindow.DispatcherQueue.TryEnqueue(() =>
{
MainWindow?.NavigationPage?.UpdatesPage.UpdatePackageForId(package);
});
BackgroundApi.OnUpgradeAllForManager += (_, manager) => MainWindow.DispatcherQueue.TryEnqueue(() =>
{
MainWindow?.NavigationPage?.UpdatesPage.UpdateAllPackagesForManager(manager);
});

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

if (!Settings.Get("DisableApi"))
{
_ = BackgroundApi.Start();
}

Expand Down
8 changes: 7 additions & 1 deletion src/UniGetUI/Controls/NavButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public string Glyph
set => IconBlock.Glyph = value;
}

public bool IsChecked
{
get => ToggleButton.IsChecked ?? false;
set => ToggleButton.IsChecked = value;
}

public event EventHandler<EventArgs>? Click;

public NavButton()
Expand All @@ -44,4 +50,4 @@ public void ForceClick()
Click?.Invoke(this, EventArgs.Empty);
}
}
}
}
16 changes: 8 additions & 8 deletions src/UniGetUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void HandleNotificationActivation(AppNotificationActivatedEventArgs args)
}
else if (action == NotificationArguments.ShowOnUpdatesTab)
{
NavigationPage.UpdatesNavButton.ForceClick();
NavigationPage.NavigateTo(PageType.Updates);
Activate();
}
else if (action == NotificationArguments.Show)
Expand Down Expand Up @@ -225,15 +225,15 @@ private void HandleDeepLink(string link)
}
else if (baseUrl.StartsWith("showDiscoverPage"))
{
NavigationPage.DiscoverNavButton.ForceClick();
NavigationPage.NavigateTo(PageType.Discover);
}
else if (baseUrl.StartsWith("showUpdatesPage"))
{
NavigationPage.UpdatesNavButton.ForceClick();
NavigationPage.NavigateTo(PageType.Updates);
}
else if (baseUrl.StartsWith("showInstalledPage"))
{
NavigationPage.InstalledNavButton.ForceClick();
NavigationPage.NavigateTo(PageType.Installed);
}
else
{
Expand Down Expand Up @@ -279,7 +279,7 @@ public void ProcessCommandLineParameters()
{
// Handle potential JSON files
Logger.ImportantInfo("Begin attempt to open the package bundle " + param);
NavigationPage.BundlesNavButton.ForceClick();
NavigationPage.NavigateTo(PageType.Bundles);
_ = NavigationPage.BundlesPage.OpenFromFile(param);
}
else if (param.EndsWith("UniGetUI.exe") || param.EndsWith("UniGetUI.dll"))
Expand Down Expand Up @@ -367,17 +367,17 @@ private void LoadTrayMenu()

DiscoverPackages.ExecuteRequested += (_, _) =>
{
NavigationPage.DiscoverNavButton.ForceClick();
NavigationPage.NavigateTo(PageType.Discover);
Activate();
};
AvailableUpdates.ExecuteRequested += (_, _) =>
{
NavigationPage.UpdatesNavButton.ForceClick();
NavigationPage.NavigateTo(PageType.Updates);
Activate();
};
InstalledPackages.ExecuteRequested += (_, _) =>
{
NavigationPage.InstalledNavButton.ForceClick();
NavigationPage.NavigateTo(PageType.Installed);
Activate();
};
AboutUniGetUI.Label = CoreTools.Translate("WingetUI Version {0}", CoreData.VersionName);
Expand Down
2 changes: 1 addition & 1 deletion src/UniGetUI/Pages/HelpPage.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Page
x:Class="UniGetUI.Interface.Dialogs.HelpDialog"
x:Class="UniGetUI.Interface.Dialogs.HelpPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down
4 changes: 2 additions & 2 deletions src/UniGetUI/Pages/HelpPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace UniGetUI.Interface.Dialogs
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class HelpDialog : Page
public sealed partial class HelpPage : Page
{
private bool Initialized;
public HelpDialog()
public HelpPage()
{
InitializeComponent();
_ = InitializeWebView();
Expand Down
43 changes: 17 additions & 26 deletions src/UniGetUI/Pages/LogPages/LogPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,34 @@ namespace UniGetUI.Interface.Pages
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public abstract partial class BaseLogPage : Page, IPageWithKeyboardShortcuts
public abstract partial class BaseLogPage : IKeyboardShortcutListener, IEnterLeaveListener
{
protected int LOG_LEVEL = 4;
private readonly bool LogLevelEnabled;

protected abstract void LoadLogLevels();
public abstract void LoadLog();
public abstract void LoadLog(bool isReload = false);

public BaseLogPage(bool log_level_enabled)
{
LogLevelEnabled = log_level_enabled;
InitializeComponent();
if (LogLevelEnabled)
{
LoadLogLevels();
}
else
{
LogLevelPane.Visibility = Visibility.Collapsed;
}
LoadLog();
LogLevelPane.Visibility = log_level_enabled ? Visibility.Visible : Visibility.Collapsed;
if (log_level_enabled) LoadLogLevels();
}

public void ReloadTriggered()
protected void SelectLogLevelByName(string name)
{
LoadLog();
LogLevelCombo.SelectedValue = name;
}

public void ReloadTriggered()
=> LoadLog(isReload: true);

public void SelectAllTriggered()
{
LogTextBox.SelectAll();
}
=> LogTextBox.SelectAll();

public void SearchTriggered()
{ }

public void SetText(string body)
{
}

// Dark theme colors
protected Color DARK_GREY = Color.FromArgb(255, 130, 130, 130);
protected Color DARK_LIGHT_GREY = Color.FromArgb(255, 190, 190, 190);
Expand Down Expand Up @@ -101,19 +89,22 @@ public async void ExportButton_Click(object sender, RoutedEventArgs e)
FileName = "explorer.exe",
Arguments = @$"/select, ""{file.Path}"""
});

}
}

public void ReloadButton_Click(object sender, RoutedEventArgs e)
{
LoadLog();
}
=> LoadLog();

private void LogLevelCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LOG_LEVEL = LogLevelCombo.SelectedIndex + 1;
LoadLog();
}

public void OnEnter()
=> LoadLog();

public void OnLeave()
=> LogTextBox.Blocks.Clear();
}
}
Loading
Loading