dont boot twice the app
This commit is contained in:
parent
4a68494162
commit
5d1649df80
3 changed files with 42 additions and 31 deletions
49
.vscode/settings.json
vendored
49
.vscode/settings.json
vendored
|
|
@ -2,30 +2,31 @@
|
||||||
"dotnet-test-explorer.testProjectPath": "test/**/*Tests.csproj",
|
"dotnet-test-explorer.testProjectPath": "test/**/*Tests.csproj",
|
||||||
|
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"appsettings",
|
"appsettings",
|
||||||
"asciidoctor",
|
"asciidoctor",
|
||||||
"ASPNETCORE",
|
"ASPNETCORE",
|
||||||
"Avalonia",
|
"Avalonia",
|
||||||
"Configurabilité",
|
"blogspot",
|
||||||
"Cratie",
|
"Configurabilité",
|
||||||
"DESTDIR",
|
"Cratie",
|
||||||
"dotnet",
|
"DESTDIR",
|
||||||
"DOTNET",
|
"dotnet",
|
||||||
"ecdsa",
|
"DOTNET",
|
||||||
"envsubst",
|
"ecdsa",
|
||||||
"Forgejo",
|
"envsubst",
|
||||||
"Hsts",
|
"Forgejo",
|
||||||
"Newtonsoft",
|
"Hsts",
|
||||||
"Npgsql",
|
"Newtonsoft",
|
||||||
"Oidc",
|
"Npgsql",
|
||||||
"PKCE",
|
"Oidc",
|
||||||
"postit",
|
"PKCE",
|
||||||
"pschneider",
|
"postit",
|
||||||
"SLNDIR",
|
"pschneider",
|
||||||
"validable",
|
"SLNDIR",
|
||||||
"www-data",
|
"validable",
|
||||||
"yavsc",
|
"www-data",
|
||||||
"Yavsc"
|
"yavsc",
|
||||||
|
"Yavsc"
|
||||||
],
|
],
|
||||||
"cSpell.reportUnknownWords": true,
|
"cSpell.reportUnknownWords": true,
|
||||||
"cSpell.language": "fr,en",
|
"cSpell.language": "fr,en",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
|
@ -15,6 +16,8 @@ namespace PostIt;
|
||||||
|
|
||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
|
private int _bootStarted;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DI container the platform entry points hand to ViewModels so
|
/// DI container the platform entry points hand to ViewModels so
|
||||||
/// they can resolve the canonical <see cref="Settings"/> singleton
|
/// they can resolve the canonical <see cref="Settings"/> singleton
|
||||||
|
|
@ -45,8 +48,6 @@ public partial class App : Application
|
||||||
{
|
{
|
||||||
var window = ServiceProvider.GetRequiredService<MainWindow>();
|
var window = ServiceProvider.GetRequiredService<MainWindow>();
|
||||||
desktop.MainWindow = window;
|
desktop.MainWindow = window;
|
||||||
var api = ServiceProvider!.GetRequiredService<YavscApiClient>();
|
|
||||||
desktop.MainWindow.Opened += async (_, _) => await BootAsync(this.ServiceProvider!, api);
|
|
||||||
View = window.MainView;
|
View = window.MainView;
|
||||||
this.ConfigureRootView(window.MainView);
|
this.ConfigureRootView(window.MainView);
|
||||||
|
|
||||||
|
|
@ -75,10 +76,8 @@ public partial class App : Application
|
||||||
|
|
||||||
private void ConfigureRootView(MainView rootView)
|
private void ConfigureRootView(MainView rootView)
|
||||||
{
|
{
|
||||||
var api = ServiceProvider!.GetRequiredService<YavscApiClient>();
|
// Déclencher le Boot une seule fois lors du chargement du contrôle à l'écran.
|
||||||
|
rootView.AttachedToVisualTree += async (_, _) => await BootOnceAsync();
|
||||||
// Déclencher le Boot lors du chargement du contrôle à l'écran
|
|
||||||
rootView.AttachedToVisualTree += async (_, _) => await BootAsync(this.ServiceProvider!, api);
|
|
||||||
|
|
||||||
var sessionStatus = ServiceProvider!.GetRequiredService<SessionStatusViewModel>();
|
var sessionStatus = ServiceProvider!.GetRequiredService<SessionStatusViewModel>();
|
||||||
sessionStatus.LogoutCompleted += () =>
|
sessionStatus.LogoutCompleted += () =>
|
||||||
|
|
@ -95,6 +94,17 @@ private void ConfigureRootView(MainView rootView)
|
||||||
rootView.SessionBanner.DataContext = sessionStatus;
|
rootView.SessionBanner.DataContext = sessionStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task BootOnceAsync()
|
||||||
|
{
|
||||||
|
if (Interlocked.Exchange(ref _bootStarted, 1) == 1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var api = ServiceProvider!.GetRequiredService<YavscApiClient>();
|
||||||
|
await BootAsync(this.ServiceProvider!, api);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test-only hook: bind a concrete <see cref="MainView"/> so
|
/// Test-only hook: bind a concrete <see cref="MainView"/> so
|
||||||
/// command-driven navigation paths (<see cref="PushPage"/>) can
|
/// command-driven navigation paths (<see cref="PushPage"/>) can
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace Yavsc.Api.Client;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class BlogApiClient
|
public sealed class BlogApiClient
|
||||||
{
|
{
|
||||||
private const string DefaultPathPrefix = "blog";
|
private const string DefaultPathPrefix = "blogspot";
|
||||||
|
|
||||||
private readonly IYavscApiClient _api;
|
private readonly IYavscApiClient _api;
|
||||||
private readonly Uri _baseAddress;
|
private readonly Uri _baseAddress;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue