2024-01-21 18:13:13 +01:00
|
|
|
using System.Globalization;
|
2024-03-27 04:08:12 +01:00
|
|
|
using Blazored.LocalStorage;
|
2022-09-04 19:19:42 +02:00
|
|
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
2024-01-21 18:13:13 +01:00
|
|
|
using Microsoft.JSInterop;
|
2022-09-04 19:19:42 +02:00
|
|
|
using MudBlazor.Services;
|
2023-10-16 11:38:27 +02:00
|
|
|
using TaikoWebUI.Settings;
|
2024-03-13 15:44:59 +01:00
|
|
|
using TaikoWebUI.Utilities;
|
2022-09-04 19:19:42 +02:00
|
|
|
|
|
|
|
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
|
|
|
builder.RootComponents.Add<App>("#app");
|
|
|
|
builder.RootComponents.Add<HeadOutlet>("head::after");
|
|
|
|
|
2024-05-25 19:12:30 +02:00
|
|
|
// Create a temporary HttpClient to fetch the appsettings.json file
|
|
|
|
using var httpClient = new HttpClient();
|
|
|
|
httpClient.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress);
|
|
|
|
var configurationStream = await httpClient.GetStreamAsync("appsettings.json");
|
|
|
|
|
|
|
|
// Load the configuration from the stream
|
|
|
|
var configuration = new ConfigurationBuilder()
|
|
|
|
.AddJsonStream(configurationStream)
|
|
|
|
.Build();
|
|
|
|
|
2022-09-09 14:31:45 +02:00
|
|
|
builder.Services.AddSingleton(sp => new HttpClient
|
2022-09-04 19:19:42 +02:00
|
|
|
{
|
2022-09-22 16:14:55 +02:00
|
|
|
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
|
2022-09-04 19:19:42 +02:00
|
|
|
});
|
|
|
|
builder.Services.AddMudServices();
|
2022-09-09 14:31:45 +02:00
|
|
|
builder.Services.AddSingleton<IGameDataService, GameDataService>();
|
2022-09-04 19:19:42 +02:00
|
|
|
|
2024-05-25 19:12:30 +02:00
|
|
|
// Configure WebUiSettings using the loaded configuration
|
|
|
|
builder.Services.Configure<WebUiSettings>(configuration.GetSection(nameof(WebUiSettings)));
|
2023-10-16 11:38:27 +02:00
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
builder.Services.AddScoped<AuthService>();
|
2024-01-21 18:13:13 +01:00
|
|
|
builder.Services.AddLocalization();
|
|
|
|
builder.Services.AddSingleton<MudLocalizer, ResXMudLocalizer>();
|
2024-03-13 15:44:59 +01:00
|
|
|
builder.Services.AddSingleton<ScoreUtils>();
|
|
|
|
builder.Services.AddSingleton<StringUtil>();
|
2024-08-13 17:07:39 +02:00
|
|
|
builder.Services.AddSingleton<BreadcrumbsStateContainer>();
|
2024-03-27 04:08:12 +01:00
|
|
|
builder.Services.AddBlazoredLocalStorage();
|
|
|
|
|
2022-09-09 14:31:45 +02:00
|
|
|
var host = builder.Build();
|
|
|
|
|
|
|
|
var gameDataService = host.Services.GetRequiredService<IGameDataService>();
|
2022-09-22 16:14:55 +02:00
|
|
|
await gameDataService.InitializeAsync(builder.HostEnvironment.BaseAddress);
|
2022-09-09 14:31:45 +02:00
|
|
|
|
2024-01-21 18:13:13 +01:00
|
|
|
CultureInfo culture;
|
|
|
|
var js = host.Services.GetRequiredService<IJSRuntime>();
|
|
|
|
var result = await js.InvokeAsync<string?>("blazorCulture.get");
|
|
|
|
|
|
|
|
if (result is not null)
|
|
|
|
{
|
|
|
|
culture = new CultureInfo(result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
culture = new CultureInfo("en-US");
|
|
|
|
await js.InvokeVoidAsync("blazorCulture.set", "en-US");
|
|
|
|
}
|
|
|
|
|
|
|
|
CultureInfo.DefaultThreadCurrentCulture = culture;
|
|
|
|
CultureInfo.DefaultThreadCurrentUICulture = culture;
|
|
|
|
|
2024-05-25 19:12:30 +02:00
|
|
|
await host.RunAsync();
|