1
0
mirror of synced 2025-01-19 16:08:41 +01:00

47 lines
1.4 KiB
C#
Raw Normal View History

using System.Globalization;
2022-09-05 01:19:42 +08:00
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.JSInterop;
2022-09-05 01:19:42 +08:00
using MudBlazor.Services;
2023-10-16 10:38:27 +01:00
using TaikoWebUI.Settings;
2022-09-05 01:19:42 +08:00
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddSingleton(sp => new HttpClient
2022-09-05 01:19:42 +08:00
{
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
2022-09-05 01:19:42 +08:00
});
builder.Services.AddMudServices();
builder.Services.AddSingleton<IGameDataService, GameDataService>();
2022-09-05 01:19:42 +08:00
2023-10-16 10:38:27 +01:00
builder.Services.Configure<WebUiSettings>(builder.Configuration.GetSection(nameof(WebUiSettings)));
builder.Services.AddScoped<LoginService>();
builder.Services.AddLocalization();
builder.Services.AddSingleton<MudLocalizer, ResXMudLocalizer>();
2023-10-16 10:38:27 +01:00
var host = builder.Build();
var gameDataService = host.Services.GetRequiredService<IGameDataService>();
await gameDataService.InitializeAsync(builder.HostEnvironment.BaseAddress);
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;
await host.RunAsync();