UI - Unload current page when closing screen

UI - Restore last page when opening via double click on tray icon
Windows - Fixed settings tray menu item opening release tab
This commit is contained in:
Robert committed 2023-08-26 22:39:01 +02:00
1 parent f3a4ccea8b
commit 811917c1c9
14 files changed
+104 -20

No files matched your search

@@ -59,4 +59,9 @@ public interface IRouter
/// <typeparam name="TScreen">The type of the root screen. It must be a class.</typeparam>
/// <typeparam name="TParam">The type of the parameters for the root screen. It must have a parameterless constructor.</typeparam>
void SetRoot<TScreen, TParam>(RoutableScreen<TScreen, TParam> root) where TScreen : class where TParam : new();
/// <summary>
/// Clears the route used by the previous window, so that it is not restored when the main window opens.
/// </summary>
void ClearPreviousWindowRoute();
}
@@ -35,11 +35,12 @@ internal class Navigation
public async Task Navigate(NavigationArguments args)
{
_logger.Information("Navigating to {Path}", _resolution.Path);
if (_options.EnableLogging)
_logger.Information("Navigating to {Path}", _resolution.Path);
_cts = new CancellationTokenSource();
await NavigateResolution(_resolution, args, _root);
if (!Cancelled)
if (!Cancelled && _options.EnableLogging)
_logger.Information("Navigated to {Path}", _resolution.Path);
}
@@ -48,7 +49,8 @@ internal class Navigation
if (Cancelled || Completed)
return;
_logger.Information("Cancelled navigation to {Path}", _resolution.Path);
if (_options.EnableLogging)
_logger.Information("Cancelled navigation to {Path}", _resolution.Path);
_cts.Cancel();
}
+36 -4
View File
@@ -3,27 +3,34 @@ using System.Collections.Generic;
using System.Reactive.Subjects;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.UI.Shared.Services.MainWindow;
using Avalonia.Threading;
using Serilog;
namespace Artemis.UI.Shared.Routing;
internal class Router : CorePropertyChanged, IRouter
internal class Router : CorePropertyChanged, IRouter, IDisposable
{
private readonly Stack<string> _backStack = new();
private readonly BehaviorSubject<string?> _currentRouteSubject;
private readonly Stack<string> _forwardStack = new();
private readonly Func<IRoutableScreen, RouteResolution, RouterNavigationOptions, Navigation> _getNavigation;
private readonly ILogger _logger;
private readonly IMainWindowService _mainWindowService;
private Navigation? _currentNavigation;
private IRoutableScreen? _root;
private string? _previousWindowRoute;
public Router(ILogger logger, Func<IRoutableScreen, RouteResolution, RouterNavigationOptions, Navigation> getNavigation)
public Router(ILogger logger, IMainWindowService mainWindowService, Func<IRoutableScreen, RouteResolution, RouterNavigationOptions, Navigation> getNavigation)
{
_logger = logger;
_mainWindowService = mainWindowService;
_getNavigation = getNavigation;
_currentRouteSubject = new BehaviorSubject<string?>(null);
mainWindowService.MainWindowOpened += MainWindowServiceOnMainWindowOpened;
mainWindowService.MainWindowClosed += MainWindowServiceOnMainWindowClosed;
}
private RouteResolution Resolve(string path)
@@ -128,7 +135,7 @@ internal class Router : CorePropertyChanged, IRouter
await Navigate(path, new RouterNavigationOptions {AddToHistory = false});
if (previousPath != null)
_forwardStack.Push(previousPath);
return true;
}
@@ -142,7 +149,7 @@ internal class Router : CorePropertyChanged, IRouter
await Navigate(path, new RouterNavigationOptions {AddToHistory = false});
if (previousPath != null)
_backStack.Push(previousPath);
return true;
}
@@ -164,4 +171,29 @@ internal class Router : CorePropertyChanged, IRouter
{
_root = root;
}
/// <inheritdoc />
public void ClearPreviousWindowRoute()
{
_previousWindowRoute = null;
}
public void Dispose()
{
_currentRouteSubject.Dispose();
_mainWindowService.MainWindowOpened -= MainWindowServiceOnMainWindowOpened;
_mainWindowService.MainWindowClosed -= MainWindowServiceOnMainWindowClosed;
}
private void MainWindowServiceOnMainWindowOpened(object? sender, EventArgs e)
{
if (_previousWindowRoute != null && _currentRouteSubject.Value == "blank")
Dispatcher.UIThread.InvokeAsync(async () => await Navigate(_previousWindowRoute, new RouterNavigationOptions {AddToHistory = false, EnableLogging = false}));
}
private void MainWindowServiceOnMainWindowClosed(object? sender, EventArgs e)
{
_previousWindowRoute = _currentRouteSubject.Value;
Dispatcher.UIThread.InvokeAsync(async () => await Navigate("blank", new RouterNavigationOptions {AddToHistory = false, EnableLogging = false}));
}
}
@@ -20,4 +20,10 @@ public class RouterNavigationOptions
/// </summary>
/// <example>If set to true, a route change from <c>page/subpage1/subpage2</c> to <c>page/subpage1</c> will be ignored.</example>
public bool IgnoreOnPartialMatch { get; set; } = false;
/// <summary>
/// Gets or sets a boolean value indicating whether logging should be enabled.
/// <remarks>Errors and warnings are always logged.</remarks>
/// </summary>
public bool EnableLogging { get; set; } = true;
}