Merge pull request #4004 from sbwalker/dev

optimize to remove IsInstalled API call on every Web UI request (MAUI clients still require this logic)
This commit is contained in:
Shaun Walker 2024-03-16 16:24:38 -04:00 committed by GitHub
commit db82d7a6b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,15 +8,13 @@
@if (_initialized) @if (_initialized)
{ {
@if (!_installation.Success) @if (!_installed)
{ {
<Installer /> <Installer />
} }
else else
{ {
@if (string.IsNullOrEmpty(_installation.Message)) if (RenderMode == RenderModes.Static)
{
if (PageState?.RenderMode == RenderModes.Static)
{ {
<CascadingValue Value="@_pageState"> <CascadingValue Value="@_pageState">
<SiteRouter RenderMode="@RenderMode" Runtime="@Runtime" OnStateChange="@ChangeState" /> <SiteRouter RenderMode="@RenderMode" Runtime="@Runtime" OnStateChange="@ChangeState" />
@ -31,13 +29,6 @@
</div> </div>
} }
} }
else
{
<div class="app-alert">
@_installation.Message
</div>
}
}
} }
@code { @code {
@ -63,28 +54,36 @@
HttpContext HttpContext { get; set; } HttpContext HttpContext { get; set; }
private bool _initialized = false; private bool _initialized = false;
private bool _installed = false;
private string _display = "display: none;"; private string _display = "display: none;";
private Installation _installation = new Installation { Success = false, Message = "" };
private PageState _pageState { get; set; } private PageState _pageState { get; set; }
protected override async Task OnParametersSetAsync() protected override async Task OnParametersSetAsync()
{ {
if (PageState != null)
{
_pageState = PageState;
}
SiteState.AntiForgeryToken = AntiForgeryToken; SiteState.AntiForgeryToken = AntiForgeryToken;
SiteState.AuthorizationToken = AuthorizationToken; SiteState.AuthorizationToken = AuthorizationToken;
SiteState.RemoteIPAddress = (_pageState != null) ? _pageState.RemoteIPAddress : ""; SiteState.RemoteIPAddress = (_pageState != null) ? _pageState.RemoteIPAddress : "";
SiteState.Platform = Platform; SiteState.Platform = Platform;
SiteState.IsPrerendering = (HttpContext != null) ? true : false; SiteState.IsPrerendering = (HttpContext != null) ? true : false;
_installation = await InstallationService.IsInstalled(); if (Runtime == Runtimes.Hybrid)
if (_installation.Alias != null)
{ {
SiteState.Alias = _installation.Alias; var installation = await InstallationService.IsInstalled();
_installed = installation.Success;
if (installation.Alias != null)
{
SiteState.Alias = installation.Alias;
}
}
else
{
if (PageState != null)
{
_pageState = PageState;
SiteState.Alias = PageState.Alias;
_installed = true;
}
} }
_initialized = true; _initialized = true;
} }