-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
117 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/AstroPanda.Blazor.Toolkit/Components/VersionLabel.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
@namespace AstroPanda.Blazor.Toolkit | ||
|
||
@using AstroPanda.Blazor.Toolkit.Options | ||
@using System.Reflection | ||
@using System.Net.Http.Json | ||
|
||
@if (!string.IsNullOrWhiteSpace(_version)) | ||
{ | ||
<div class="version-label"> | ||
<MudText Style="@Style" Class="@Class" Typo="Typo.caption"> | ||
v. @_version | ||
</MudText> | ||
</div> | ||
} | ||
|
||
@code { | ||
[Inject] | ||
private NavigationManager _navManager { get; set; } | ||
|
||
[Parameter] | ||
public string ManifestPath { get; set; } = "/manifest.json"; | ||
|
||
[Parameter] | ||
public VersionFetch VersionFetchType { get; set; } = VersionFetch.Remote; | ||
|
||
[Parameter] | ||
public string Style { get; set; } = "position: absolute; bottom: 10px; right: 15px; text-transform:none;"; | ||
|
||
[Parameter] | ||
public string Class { get; set; } = string.Empty; | ||
|
||
private string _version { get; set; } = string.Empty; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
switch(VersionFetchType) | ||
{ | ||
case VersionFetch.Remote: | ||
var _http = new HttpClient() | ||
{ | ||
BaseAddress = new Uri(_navManager.BaseUri) | ||
}; | ||
|
||
var config = await _http.GetFromJsonAsync<Manifest>(ManifestPath); | ||
|
||
if (config is null) | ||
break; | ||
|
||
if (config.Version is not null) | ||
_version = config.Version; | ||
else if (config.VersionName is not null) | ||
_version = config.VersionName.Substring(0, 8); | ||
break; | ||
case VersionFetch.ExecutingAssembly: | ||
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version; | ||
_version = assemblyVersion is null ? "0.0.0" : assemblyVersion.ToString(); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
base.OnInitialized(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace AstroPanda.Blazor.Toolkit; | ||
|
||
public class Manifest | ||
{ | ||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("short_name")] | ||
public string ShortName { get; set; } | ||
|
||
[JsonPropertyName("version")] | ||
public string Version { get; set; } | ||
|
||
[JsonPropertyName("version_name")] | ||
public string VersionName { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace AstroPanda.Blazor.Toolkit.Options; | ||
public enum VersionFetch | ||
{ | ||
Remote, | ||
|
||
ExecutingAssembly | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace AstroPanda.Blazor.Toolkit.Options; | ||
internal class VersionOptions | ||
{ | ||
public const string ClientName = "Version"; | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
<MudNavMenu> | ||
@using AstroPanda.Blazor.Toolkit | ||
@using AstroPanda.Blazor.Toolkit.Options | ||
<MudNavMenu Style="height: 100%;"> | ||
<MudNavLink Href="" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Home">Home</MudNavLink> | ||
<MudNavLink Href="counter" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Add">Counter</MudNavLink> | ||
<MudNavLink Href="weather" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.List">Weather</MudNavLink> | ||
|
||
|
||
<VersionLabel VersionFetchType="VersionFetch.ExecutingAssembly"/> | ||
</MudNavMenu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<MudNavMenu> | ||
@using AstroPanda.Blazor.Toolkit | ||
<MudNavMenu Style="height: 100%;"> | ||
<MudNavLink Href="" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Home">Home</MudNavLink> | ||
<MudNavLink Href="counter" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Add">Counter</MudNavLink> | ||
<MudNavLink Href="weather" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.List">Weather</MudNavLink> | ||
|
||
<VersionLabel ManifestPath="/manifest.webmanifest"/> | ||
</MudNavMenu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters