-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMauiProgram.cs
63 lines (53 loc) · 1.92 KB
/
MauiProgram.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using BlazorLibrary.Data;
using MudBlazor.Services;
using NavigationManagerUtils;
using BlazorLibrary.Management;
using Microsoft.Extensions.Logging;
using BlazorLibrary.Models.Application;
namespace BlazorLibrary
{
public static class MauiProgram
{
public static ApplicationSettings Settings { get; set; } = new();
public static MauiApp CreateMauiApp()
{
MauiAppBuilder builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
#if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools();
builder.Logging.AddDebug();
#endif
builder.Services.AddMauiBlazorWebView();
builder.Services.AddMudServices();
AddCustomManagers(builder);
SetupLibrary();
return builder.Build();
}
private static void AddCustomManagers(MauiAppBuilder builder)
{
builder.Services.AddSingleton<SqliteDatabaseManager>();
builder.Services.AddSingleton<CsvManager>();
builder.Services.AddTransient<NavManUtils>();
builder.Services.AddSingleton<RawgNetManager>();
}
public static void SetupLibrary()
{
string SettingsAsJson = File.ReadAllText(Path.Combine(Manager.GetExecutionDirectory(), "ApplicationSettingsFile.json"));
Settings = Manager.JsonToObject<ApplicationSettings>(SettingsAsJson);
if (Settings is not null)
{
if (!Manager.IsInternetAvailable() || Settings.RawgApikey.Length < 10)
{
Settings.UsePriceScraper = false;
Settings.UseRawg = false;
}
SqliteDatabaseManager.SetupDatabase();
}
}
}
}