This commit is contained in:
parent
344c38704b
commit
ddff760c41
5 changed files with 45 additions and 26 deletions
|
|
@ -9,6 +9,7 @@ using PostIt.Services;
|
|||
using PostIt.ViewModels;
|
||||
using PostIt.Views;
|
||||
using PostIt.Views.Blogs;
|
||||
using PostIt.Helpers;
|
||||
|
||||
namespace PostIt.Tests;
|
||||
|
||||
|
|
@ -117,7 +118,10 @@ public class MainPageButtonsTests
|
|||
var app = (PostIt.App)Application.Current!;
|
||||
|
||||
app.AttachMainWindow(window);
|
||||
|
||||
window.NavRoot.PushAsync(page).GetAwaiter().GetResult();
|
||||
var mainWindow = new Window { Content = window };
|
||||
mainWindow.Show();
|
||||
return (window, page);
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +151,7 @@ public class MainPageButtonsTests
|
|||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void Acl_button_click_pushes_a_page_onto_nav_stack()
|
||||
public async Task Acl_button_click_pushes_a_page_onto_nav_stack()
|
||||
{
|
||||
// Arrange: a VM whose SelectedPost is non-null so
|
||||
// CanManageAcl evaluates to true and the button is
|
||||
|
|
@ -180,7 +184,7 @@ public class MainPageButtonsTests
|
|||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void Circles_button_click_pushes_a_page_onto_nav_stack()
|
||||
public async Task Circles_button_click_pushes_a_page_onto_nav_stack()
|
||||
{
|
||||
// Arrange: OpenCircles has no CanExecute guard today —
|
||||
// any click should fire it and push the page.
|
||||
|
|
|
|||
|
|
@ -64,9 +64,7 @@ public class MainPageSaveTests
|
|||
const string typed = "Mon premier billet";
|
||||
titleBox.Text = typed;
|
||||
|
||||
var saveButton = window.GetVisualDescendants()
|
||||
.OfType<Button>()
|
||||
.Single(b => b.Content as string == "Save");
|
||||
var saveButton = page.SaveButton;
|
||||
saveButton.Command!.Execute(null);
|
||||
|
||||
// The Save command is async (RelayCommand over Task) but
|
||||
|
|
|
|||
|
|
@ -46,35 +46,48 @@ public partial class App : Application
|
|||
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var window = ServiceProvider.GetRequiredService<MainWindow>();
|
||||
desktop.MainWindow = window;
|
||||
View = window.MainView;
|
||||
this.ConfigureRootView(window.MainView);
|
||||
|
||||
ApplyDarkMode(settings);
|
||||
InitializeClassicDesktopLifetime(settings, desktop);
|
||||
}
|
||||
else if (ApplicationLifetime is IActivityApplicationLifetime singleViewFactoryApplicationLifetime)
|
||||
{
|
||||
singleViewFactoryApplicationLifetime.MainViewFactory =
|
||||
() =>
|
||||
{
|
||||
View = ServiceProvider.GetRequiredService<MainView>();
|
||||
this.ConfigureRootView(View);
|
||||
ApplyDarkMode(settings);
|
||||
return View;
|
||||
};
|
||||
InitializeActivityLifetime(settings, singleViewFactoryApplicationLifetime);
|
||||
}
|
||||
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
|
||||
{
|
||||
singleViewPlatform.MainView = View = ServiceProvider.GetRequiredService<MainView>();
|
||||
ConfigureRootView(View);
|
||||
ApplyDarkMode(settings);
|
||||
InitializeSingleViewLifetime(settings, singleViewPlatform);
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
private void ConfigureRootView(MainView rootView)
|
||||
public void InitializeSingleViewLifetime(Settings settings, ISingleViewApplicationLifetime singleViewPlatform)
|
||||
{
|
||||
singleViewPlatform.MainView = View = ServiceProvider!.GetRequiredService<MainView>();
|
||||
ConfigureRootView(View);
|
||||
ApplyDarkMode(settings);
|
||||
}
|
||||
|
||||
public void InitializeActivityLifetime(Settings settings, IActivityApplicationLifetime singleViewFactoryApplicationLifetime)
|
||||
{
|
||||
singleViewFactoryApplicationLifetime.MainViewFactory =
|
||||
() =>
|
||||
{
|
||||
this.ConfigureRootView(ServiceProvider!.GetRequiredService<MainView>());
|
||||
ApplyDarkMode(settings);
|
||||
return View!;
|
||||
};
|
||||
}
|
||||
|
||||
public void InitializeClassicDesktopLifetime(Settings settings, IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var window = ServiceProvider!.GetRequiredService<MainWindow>();
|
||||
desktop.MainWindow = window;
|
||||
this.ConfigureRootView(window.MainView);
|
||||
|
||||
ApplyDarkMode(settings);
|
||||
}
|
||||
|
||||
public void ConfigureRootView(MainView rootView)
|
||||
{
|
||||
// Déclencher le Boot une seule fois lors du chargement du contrôle à l'écran.
|
||||
rootView.AttachedToVisualTree += async (_, _) => await BootOnceAsync();
|
||||
|
|
@ -87,6 +100,7 @@ private void ConfigureRootView(MainView rootView)
|
|||
};
|
||||
|
||||
rootView.SessionBanner.DataContext = sessionStatus;
|
||||
this.View = rootView;
|
||||
}
|
||||
|
||||
private async Task BootOnceAsync()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace PostIt.Helpers;
|
|||
|
||||
public static class ViewModelBaseHelpers
|
||||
{
|
||||
public static async Task PushPageAsync(this App app, ViewModelBase vm)
|
||||
public static async Task<Page> PushPageAsync(this App app, ViewModelBase vm)
|
||||
{
|
||||
var window = app.View;
|
||||
if (window is null)
|
||||
|
|
@ -43,9 +43,11 @@ public static class ViewModelBaseHelpers
|
|||
var stack = window.NavRoot.NavigationStack;
|
||||
if (stack.Count > 0 && ReferenceEquals(stack[stack.Count - 1], page))
|
||||
{
|
||||
return;
|
||||
return page;
|
||||
}
|
||||
|
||||
await window.NavRoot.PushAsync(page);
|
||||
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,9 @@ public class HomePageViewModel : ViewModelBase
|
|||
|
||||
OpenActivities = new AsyncRelayCommand(OpenActivitiesAsync);
|
||||
OpenProviderRequests = new AsyncRelayCommand(OpenProviderRequestsAsync);
|
||||
OpenBlogs = new AsyncRelayCommand(App.PushBlogsPageAsync);
|
||||
}
|
||||
public IAsyncRelayCommand OpenBlogs { get; } = new AsyncRelayCommand(App.PushBlogsPageAsync);
|
||||
public IAsyncRelayCommand OpenBlogs { get; }
|
||||
public IAsyncRelayCommand OpenActivities { get; }
|
||||
public IAsyncRelayCommand OpenProviderRequests { get; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue