Loading app settings
and putting app name and version number in the app class on startup
This commit is contained in:
parent
2fcb6e1fae
commit
65276d4984
8 changed files with 33 additions and 9 deletions
|
@ -1,5 +1,9 @@
|
|||
namespace Neighbourhood.omg.lol {
|
||||
public partial class App : Application {
|
||||
|
||||
public static string Name { get; set; }
|
||||
public static string Version { get; set; }
|
||||
|
||||
public App(NavigatorService navigatorService) {
|
||||
InitializeComponent();
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
@using System.Reflection
|
||||
@inject CustomAuthenticationStateProvider AuthStateProvider;
|
||||
@inject CustomAuthenticationStateProvider AuthStateProvider;
|
||||
@inject State State;
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
|
@ -45,7 +44,7 @@
|
|||
</a>
|
||||
<a class="row medium-opacity">
|
||||
<i class="fa-solid fa-circle-info tiny"></i>
|
||||
<small>@assembly.Name - @assembly.Version?.ToString()</small>
|
||||
<small>@App.Name - @App.Version</small>
|
||||
</a>
|
||||
</menu>
|
||||
</button>
|
||||
|
@ -81,7 +80,6 @@
|
|||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
AssemblyName assembly = Assembly.GetExecutingAssembly().GetName();
|
||||
public void changeAddress(AddressResponseData address) {
|
||||
State.SelectedAddress = address;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public partial class LoginWebViewPage : ContentPage
|
|||
if ( client_id != null
|
||||
&& client_secret != null
|
||||
&& redirect_uri != null) {
|
||||
//this.loginwebview.UserAgent = new System.Net.Http.Headers.ProductInfoHeaderValue(App.Name, App.Version).ToString();
|
||||
this.loginwebview.Source = $"https://home.omg.lol/oauth/authorize?client_id={client_id}&scope=everything&redirect_uri={redirect_uri}&response_type=code";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Components.Authorization;
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Neighbourhood.omg.lol.Models;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Neighbourhood.omg.lol {
|
||||
public static class MauiProgram {
|
||||
|
@ -22,8 +23,16 @@ namespace Neighbourhood.omg.lol {
|
|||
builder.Services.AddSingleton<State>();
|
||||
builder.Services.AddSingleton<NavigatorService>();
|
||||
|
||||
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
|
||||
builder.Services.AddSingleton<IConfiguration>(configurationBuilder.AddUserSecrets<App>().Build());
|
||||
//ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
|
||||
//builder.Services.AddSingleton<IConfiguration>(configurationBuilder.AddUserSecrets<App>().Build());
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var details = assembly.GetName();
|
||||
App.Name = details.Name!;
|
||||
App.Version = details.Version!.ToString();
|
||||
var appSettings = $"{App.Name}.appsettings.json";
|
||||
using var stream = assembly.GetManifestResourceStream(appSettings);
|
||||
var config = new ConfigurationBuilder().AddJsonStream(stream).Build();
|
||||
builder.Configuration.AddConfiguration(config);
|
||||
|
||||
builder.Services.AddAuthorizationCore();
|
||||
builder.Services.AddScoped<CustomAuthenticationStateProvider>();
|
||||
|
|
|
@ -90,6 +90,10 @@
|
|||
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<MauiFont Remove="Resources\Fonts\fa-brands-400.ttf" />
|
||||
<MauiFont Remove="Resources\Fonts\fa-brands-400.woff2" />
|
||||
|
@ -195,6 +199,10 @@
|
|||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Markdig" Version="0.37.0" />
|
||||
|
|
|
@ -19,8 +19,7 @@ namespace Neighbourhood.omg.lol {
|
|||
public RestService(string? token = null) {
|
||||
_client = new HttpClient();
|
||||
_client.BaseAddress = new Uri(BaseUrl);
|
||||
AssemblyName name = Assembly.GetExecutingAssembly().GetName();
|
||||
_client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue(name.Name ?? "Neighbourhood.omg.lol", name.Version?.ToString()));
|
||||
_client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue(App.Name, App.Version));
|
||||
_serializerOptions = new JsonSerializerOptions {
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
|
||||
WriteIndented = true
|
||||
|
|
5
appsettings.json
Normal file
5
appsettings.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"client_id": "08656a9ade42b8ff16b868c4bb33379e",
|
||||
"client_secret": "529e47904ca8900a4fb187ecee2f6221",
|
||||
"redirect_uri": "https://auth.neighbourhood.omg.lol/"
|
||||
}
|
|
@ -461,7 +461,7 @@ article {
|
|||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
nav label {
|
||||
nav label:is(.checkbox, .radio, .switch) {
|
||||
white-space: break-spaces;
|
||||
flex: 1 1 100%;
|
||||
}
|
Loading…
Reference in a new issue