Repository navigation
Expand file tree
/
Copy pathMauiProgram.cs
More file actions
94 lines (84 loc) · 3.86 KB
/
Copy pathMauiProgram.cs
File metadata and controls
94 lines (84 loc) · 3.86 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using BabyBuddyHelper.Core.Interfaces.Baby;
using BabyBuddyHelper.Core.Interfaces.Cub;
using BabyBuddyHelper.Core.Interfaces.TaskList;
using BabyBuddyHelper.Core.Interfaces.Vaccine;
using BabyBuddyHelper.Core.Interfaces;
using BabyBuddyHelper.Core.Persistence;
using BabyBuddyHelper.Core.Services.Baby;
using BabyBuddyHelper.Core.Services.Cub;
using BabyBuddyHelper.Core.Services.TaskList;
using BabyBuddyHelper.Core.Services.Vaccine;
using BabyBuddyHelper.Core.Storage;
using BabyBuddyHelper.Remote;
using CommunityToolkit.Maui;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using SkiaSharp.Views.Maui.Controls.Hosting;
using Syncfusion.Maui.Core.Hosting;
using System.Diagnostics;
namespace BabyBuddyHelper
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
RegisterSyncfusionLicense();
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.UseSkiaSharp()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
})
.ConfigureSyncfusionCore()
.Services.AddSingleton<ITaskListService, TaskListService>()
.AddSingleton<IBabyProfileService, BabyProfileService>()
.AddSingleton<IBabyFilterService, BabyFilterService>()
.AddSingleton<IVaccineCatalog, VaccineCatalog>()
.AddSingleton<IVaccineService, VaccineService>()
.AddSingleton<ITrackerDbService, EfTrackerDbService>()
.AddSingleton<IApiKeyStore, SecureApiKeyStore>()
.AddSingleton<ICubChatClient, ClaudeCubChatClient>() //The only place that references Remote/ (ADR-017)
.AddSingleton<CubReplyService>()
.AddSingleton<ICubPersonalityStore, PreferencesCubPersonalityStore>()
.AddDbContextFactory<TrackerContext>(options =>
options.UseSqlite($"Data Source={Path.Combine(FileSystem.AppDataDirectory, "babybuddy.db3")}"));
#if WINDOWS
WinUI.ShellTabBarFooter.Register();
#endif
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
//The license is compiled into BuildSecrets by the GenerateBuildSecrets target in the .csproj, so it travels
//with the app on every platform. Nothing is read from disk at runtime, and the key is never logged.
private static void RegisterSyncfusionLicense()
{
try //tryCatch prevents app from crashing if the license is missing or invalid
{
if (string.IsNullOrWhiteSpace(BuildSecrets.SyncfusionLicense))
{
Debug.WriteLine("Syncfusion license missing at build time. Running unlicensed.");
return;
}
Syncfusion.Licensing.SyncfusionLicenseProvider
.RegisterLicense(BuildSecrets.SyncfusionLicense);
//RegisterLicense only stores the key; Syncfusion checks it when the first control loads.
//Keys are valid for one major version, so a package upgrade can silently invalidate it (#118).
bool isValid = Syncfusion.Licensing.SyncfusionLicenseProvider
.ValidateLicense([Syncfusion.Licensing.Platform.MAUI], out string message);
Debug.WriteLine(isValid
? "Syncfusion license registered and valid."
: $"Syncfusion license rejected: {message}");
}
catch (Exception ex)
{
Debug.WriteLine($"Error registering Syncfusion license: {ex.Message}");
}
}
}
}