forked from amkovkov/GranuSightSoftware2
108 lines
3.4 KiB
C#
108 lines
3.4 KiB
C#
using System.CommandLine;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging.Console;
|
|
|
|
using Avalonia;
|
|
using Avalonia.OpenGL.Egl;
|
|
|
|
using GSS2.Core;
|
|
using GSS2.Core.Logging;
|
|
using GSS2.Core.Analysis.AmineContent.Database;
|
|
|
|
using ConsoleFormatter = GSS2.Core.Logging.ConsoleFormatter;
|
|
|
|
namespace GSS2.Test;
|
|
|
|
public partial class Program
|
|
{
|
|
public static IHost ApplicationHost { get; } = BuildHostApp();
|
|
public static bool IsFullscreen = false;
|
|
|
|
private static void Ui(ParseResult parseResult)
|
|
{
|
|
var builder = BuildAvaloniaApp();
|
|
var renderingMode = parseResult.GetValue(_renderingMode);
|
|
var hideConsole = parseResult.GetValue(_hideConsole);
|
|
var fullscreen = parseResult.GetValue(_fullscreen);
|
|
IsFullscreen = fullscreen;
|
|
|
|
if (hideConsole)
|
|
SilenceConsole();
|
|
|
|
switch (renderingMode)
|
|
{
|
|
case RenderingMode.X11:
|
|
builder.StartWithClassicDesktopLifetime(_args ?? []);
|
|
break;
|
|
case RenderingMode.DRM:
|
|
builder.StartLinuxDrm(_args ?? [], "/dev/dri/card1", 1.0);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private static void SilenceConsole()
|
|
{
|
|
new Thread(() =>
|
|
{
|
|
Console.CursorVisible = false;
|
|
while (true)
|
|
Console.ReadKey(true);
|
|
})
|
|
{ IsBackground = true }.Start();
|
|
}
|
|
|
|
private static IHost BuildHostApp()
|
|
{
|
|
var builder = Host.CreateApplicationBuilder();
|
|
|
|
builder.Logging.ClearProviders();
|
|
builder.Logging.AddConsole(options => options.FormatterName = nameof(ConsoleFormatter));
|
|
builder.Logging.AddConsoleFormatter<ConsoleFormatter, ConsoleFormatterOptions>();
|
|
builder.Logging.AddProvider(new FileLoggerProvider("full.log", true));
|
|
builder.Logging.AddProvider(new FileLoggerProvider("last_run.log", false));
|
|
builder.Services.AddSingleton<LibCameraLogSink>();
|
|
|
|
builder.Services.AddAmineContentCalibrationContext(builder.Configuration);
|
|
builder.Services.AddAmineContentResultsContext(builder.Configuration);
|
|
|
|
builder.Services.AddLightsService("Hardware:Lights");
|
|
builder.Services.AddTemperatureHumidityService("Hardware:TemperatureHumidity");
|
|
builder.Services.AddIlluminatorService("Hardware:Illuminator");
|
|
builder.Services.AddCameraService("Hardware:Camera", true);
|
|
builder.Services.AddComputeResourcesService();
|
|
|
|
builder.Services.AddViewsAndModels();
|
|
|
|
var host = builder.Build();
|
|
host.Services.GetRequiredService<LibCameraLogSink>();
|
|
|
|
using (var scope = host.Services.CreateScope())
|
|
{
|
|
var context = scope.ServiceProvider.GetRequiredService<AmineContentCalibrationContext>();
|
|
context.Database.Migrate();
|
|
}
|
|
using (var scope = host.Services.CreateScope())
|
|
{
|
|
var context = scope.ServiceProvider.GetRequiredService<AmineContentResultsContext>();
|
|
context.Database.Migrate();
|
|
}
|
|
|
|
return host;
|
|
}
|
|
|
|
private static AppBuilder BuildAvaloniaApp()
|
|
=> AppBuilder.Configure<App>()
|
|
.UsePlatformDetect()
|
|
.UseSkia()
|
|
.LogToTrace()
|
|
.With(new X11PlatformOptions
|
|
{
|
|
RenderingMode = [X11RenderingMode.Egl]
|
|
})
|
|
.With(new EglDisplayOptions
|
|
{
|
|
SupportsContextSharing = true
|
|
});
|
|
}
|