From 5d1649df80bae261fe7fe9279e909652db10525c Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 29 Aug 2026 02:41:59 +0100 Subject: [PATCH] dont boot twice the app --- .vscode/settings.json | 49 ++++++++++++++------------- src/PostIt/PostIt/App.axaml.cs | 22 ++++++++---- src/Yavsc.Api.Client/BlogApiClient.cs | 2 +- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6eb4faad..83a17ae3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,30 +2,31 @@ "dotnet-test-explorer.testProjectPath": "test/**/*Tests.csproj", "cSpell.words": [ - "appsettings", - "asciidoctor", - "ASPNETCORE", - "Avalonia", - "Configurabilité", - "Cratie", - "DESTDIR", - "dotnet", - "DOTNET", - "ecdsa", - "envsubst", - "Forgejo", - "Hsts", - "Newtonsoft", - "Npgsql", - "Oidc", - "PKCE", - "postit", - "pschneider", - "SLNDIR", - "validable", - "www-data", - "yavsc", - "Yavsc" + "appsettings", + "asciidoctor", + "ASPNETCORE", + "Avalonia", + "blogspot", + "Configurabilité", + "Cratie", + "DESTDIR", + "dotnet", + "DOTNET", + "ecdsa", + "envsubst", + "Forgejo", + "Hsts", + "Newtonsoft", + "Npgsql", + "Oidc", + "PKCE", + "postit", + "pschneider", + "SLNDIR", + "validable", + "www-data", + "yavsc", + "Yavsc" ], "cSpell.reportUnknownWords": true, "cSpell.language": "fr,en", diff --git a/src/PostIt/PostIt/App.axaml.cs b/src/PostIt/PostIt/App.axaml.cs index 7caf7bda..e3735c1e 100644 --- a/src/PostIt/PostIt/App.axaml.cs +++ b/src/PostIt/PostIt/App.axaml.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; @@ -15,6 +16,8 @@ namespace PostIt; public partial class App : Application { + private int _bootStarted; + /// /// DI container the platform entry points hand to ViewModels so /// they can resolve the canonical singleton @@ -45,8 +48,6 @@ public partial class App : Application { var window = ServiceProvider.GetRequiredService(); desktop.MainWindow = window; - var api = ServiceProvider!.GetRequiredService(); - desktop.MainWindow.Opened += async (_, _) => await BootAsync(this.ServiceProvider!, api); View = window.MainView; this.ConfigureRootView(window.MainView); @@ -75,10 +76,8 @@ public partial class App : Application private void ConfigureRootView(MainView rootView) { - var api = ServiceProvider!.GetRequiredService(); - - // Déclencher le Boot lors du chargement du contrôle à l'écran - rootView.AttachedToVisualTree += async (_, _) => await BootAsync(this.ServiceProvider!, api); + // Déclencher le Boot une seule fois lors du chargement du contrôle à l'écran. + rootView.AttachedToVisualTree += async (_, _) => await BootOnceAsync(); var sessionStatus = ServiceProvider!.GetRequiredService(); sessionStatus.LogoutCompleted += () => @@ -95,6 +94,17 @@ private void ConfigureRootView(MainView rootView) rootView.SessionBanner.DataContext = sessionStatus; } + private async Task BootOnceAsync() + { + if (Interlocked.Exchange(ref _bootStarted, 1) == 1) + { + return; + } + + var api = ServiceProvider!.GetRequiredService(); + await BootAsync(this.ServiceProvider!, api); + } + /// /// Test-only hook: bind a concrete so /// command-driven navigation paths () can diff --git a/src/Yavsc.Api.Client/BlogApiClient.cs b/src/Yavsc.Api.Client/BlogApiClient.cs index cbc82358..8284c5ed 100644 --- a/src/Yavsc.Api.Client/BlogApiClient.cs +++ b/src/Yavsc.Api.Client/BlogApiClient.cs @@ -33,7 +33,7 @@ namespace Yavsc.Api.Client; /// public sealed class BlogApiClient { - private const string DefaultPathPrefix = "blog"; + private const string DefaultPathPrefix = "blogspot"; private readonly IYavscApiClient _api; private readonly Uri _baseAddress;