mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Workshop - Reworked installation management
This commit is contained in:
1 parent
d6f1ba9aad
commit
6b4ed48d05
28 files changed
+514
-197
No files matched your search
@@ -13,6 +13,11 @@ namespace Artemis.UI.Shared.Routing;
|
||||
/// <typeparam name="TParam">The type of parameters the screen expects. It must have a parameterless constructor.</typeparam>
|
||||
public abstract class RoutableScreen<TParam> : RoutableScreen, IRoutableScreen where TParam : new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the parameter source of the screen.
|
||||
/// </summary>
|
||||
protected ParameterSource ParameterSource { get; set; } = ParameterSource.Segment;
|
||||
|
||||
/// <summary>
|
||||
/// Called while navigating to this screen.
|
||||
/// </summary>
|
||||
@@ -26,15 +31,16 @@ public abstract class RoutableScreen<TParam> : RoutableScreen, IRoutableScreen w
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
async Task IRoutableScreen.InternalOnNavigating(NavigationArguments args, CancellationToken cancellationToken)
|
||||
{
|
||||
Func<object[], TParam> activator = GetParameterActivator();
|
||||
|
||||
if (args.SegmentParameters.Length != _parameterPropertyCount)
|
||||
throw new ArtemisRoutingException($"Did not retrieve the required amount of parameters, expects {_parameterPropertyCount}, got {args.SegmentParameters.Length}.");
|
||||
object[] routeParameters = ParameterSource == ParameterSource.Segment ? args.SegmentParameters : args.RouteParameters;
|
||||
if (routeParameters.Length != _parameterPropertyCount)
|
||||
throw new ArtemisRoutingException($"Did not retrieve the required amount of parameters, expects {_parameterPropertyCount}, got {routeParameters.Length}.");
|
||||
|
||||
TParam parameters = activator(args.SegmentParameters);
|
||||
TParam parameters = activator(routeParameters);
|
||||
await OnNavigating(args, cancellationToken);
|
||||
await OnNavigating(parameters, args, cancellationToken);
|
||||
}
|
||||
@@ -97,4 +103,20 @@ public abstract class RoutableScreen<TParam> : RoutableScreen, IRoutableScreen w
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enum representing the source of parameters in the RoutableScreen class.
|
||||
/// </summary>
|
||||
public enum ParameterSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the source where parameters are obtained from the segment of the route.
|
||||
/// </summary>
|
||||
Segment,
|
||||
|
||||
/// <summary>
|
||||
/// Represents the source where parameters are obtained from the entire route.
|
||||
/// </summary>
|
||||
Route
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
@@ -72,7 +73,13 @@ internal class Router : CorePropertyChanged, IRouter, IDisposable
|
||||
/// <inheritdoc />
|
||||
public async Task Navigate(string path, RouterNavigationOptions? options = null)
|
||||
{
|
||||
path = path.ToLower().Trim(' ', '/', '\\');
|
||||
if (path.StartsWith('/') && _currentRouteSubject.Value != null)
|
||||
path = _currentRouteSubject.Value + path;
|
||||
if (path.StartsWith("../") && _currentRouteSubject.Value != null)
|
||||
path = NavigateUp(_currentRouteSubject.Value, path);
|
||||
else
|
||||
path = path.ToLower().Trim(' ', '/', '\\');
|
||||
|
||||
options ??= new RouterNavigationOptions();
|
||||
|
||||
// Routing takes place on the UI thread with processing heavy tasks offloaded by the router itself
|
||||
@@ -216,6 +223,24 @@ internal class Router : CorePropertyChanged, IRouter, IDisposable
|
||||
|
||||
_logger.Debug("Router disposed, should that be? Stacktrace: \r\n{StackTrace}", Environment.StackTrace);
|
||||
}
|
||||
|
||||
|
||||
private string NavigateUp(string current, string path)
|
||||
{
|
||||
string[] pathParts = current.Split('/');
|
||||
string[] navigateParts = path.Split('/');
|
||||
int upCount = navigateParts.TakeWhile(part => part == "..").Count();
|
||||
|
||||
if (upCount >= pathParts.Length)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot navigate up beyond the root");
|
||||
}
|
||||
|
||||
IEnumerable<string> remainingCurrentPathParts = pathParts.Take(pathParts.Length - upCount);
|
||||
IEnumerable<string> remainingNavigatePathParts = navigateParts.Skip(upCount);
|
||||
|
||||
return string.Join("/", remainingCurrentPathParts.Concat(remainingNavigatePathParts));
|
||||
}
|
||||
|
||||
private void MainWindowServiceOnMainWindowOpened(object? sender, EventArgs e)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user