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; } public Assembly? HostAssembly { get; init; }
#if __WASM__ #if __WASM__
public async Task UpdateAddressBar(Uri applicationUri) public async Task UpdateAddressBar(Uri applicationUri, bool canGoBack)
{ {
CoreApplication.MainView?.DispatcherQueue.TryEnqueue(() => CoreApplication.MainView?.DispatcherQueue.TryEnqueue(() =>
{ {
var state = 1; var state = 1;
if (PlatformHelper.IsWebAssembly) if (PlatformHelper.IsWebAssembly)
{ {
var currentView = SystemNavigationManager.GetForCurrentView(); state = canGoBack ? 1 : 0;
state = currentView?.AppViewBackButtonVisibility == AppViewBackButtonVisibility.Visible ? 1 : 0;
} }
var href = Imports.GetLocation(); var href = Imports.GetLocation();

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

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

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

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