fix: Check if navigating back is possible to update state

(cherry picked from commit 5611dffabc)
This commit is contained in:
eriklimakc 2024-07-25 19:00:03 +01:00 коммит произвёл Mergify
Родитель 3b862403c4
Коммит 555ddb401a
3 изменённых файлов: 9 добавлений и 5 удалений

Просмотреть файл

@ -16,15 +16,14 @@ internal class AppHostingEnvironment : HostingEnvironment, IAppHostEnvironment,
public Assembly? HostAssembly { get; init; }
#if __WASM__
public async Task UpdateAddressBar(Uri applicationUri)
public async Task UpdateAddressBar(Uri applicationUri, bool canGoBack)
{
CoreApplication.MainView?.DispatcherQueue.TryEnqueue(() =>
{
var state = 1;
if (PlatformHelper.IsWebAssembly)
{
var currentView = SystemNavigationManager.GetForCurrentView();
state = currentView?.AppViewBackButtonVisibility == AppViewBackButtonVisibility.Visible ? 1 : 0;
state = canGoBack ? 1 : 0;
}
var href = Imports.GetLocation();

Просмотреть файл

@ -12,8 +12,11 @@ public interface IHasAddressBar
/// <param name="applicationUri">
/// The URI to update the address bar with.
/// </param>
/// <param name="canGoBack">
/// Whether it is possible to navigate back or not.
/// </param>
/// <returns>
/// A task that completes when the address bar has been updated.
/// </returns>
Task UpdateAddressBar(Uri applicationUri);
Task UpdateAddressBar(Uri applicationUri, bool canGoBack);
}

Просмотреть файл

@ -72,12 +72,14 @@ internal class BrowserAddressBarService : IHostedService
return;
}
var canGoBack = rootRegion.Navigator() is { } navigator && await navigator.CanGoBack();
var url = new UriBuilder
{
Query = route.Query(),
Path = route.FullPath()?.Replace("+", "/")
};
await _addressbarHost!.UpdateAddressBar(url.Uri);
await _addressbarHost!.UpdateAddressBar(url.Uri, canGoBack);
}
catch (Exception ex)
{