-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
100 lines (86 loc) · 4.27 KB
/
Program.cs
File metadata and controls
100 lines (86 loc) · 4.27 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
95
96
97
98
99
100
using CheapAvaloniaBlazor.Hosting;
using CheapAvaloniaBlazor.Extensions;
using CheapShotcutRandomizer.Services;
using CheapShotcutRandomizer.Services.Queue;
using CheapShotcutRandomizer.Services.Utilities;
using CheapShotcutRandomizer.Data;
using CheapShotcutRandomizer.Data.Repositories;
using CheapHelpers.Services.DataExchange.Xml;
using CheapHelpers.MediaProcessing.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.EntityFrameworkCore;
using System.Runtime.InteropServices;
namespace CheapShotcutRandomizer;
class Program
{
[STAThread]
public static void Main(string[] args)
{
var builder = new CheapAvaloniaBlazor.Hosting.HostBuilder()
.WithTitle("Cheap Shotcut Randomizer")
.WithSize(1000, 800)
.ConfigureOptions(options =>
{
options.EnableDevTools = false;
options.EnableContextMenu = false;
})
.AddMudBlazor(config =>
{
config.SnackbarConfiguration.PositionClass = MudBlazor.Defaults.Classes.Position.BottomRight;
config.SnackbarConfiguration.VisibleStateDuration = 2000; // 2 seconds instead of default 5
config.SnackbarConfiguration.ShowTransitionDuration = 200;
config.SnackbarConfiguration.HideTransitionDuration = 200;
});
// Register services
builder.Services.AddSingleton<SvpDetectionService>();
builder.Services.AddSingleton<ExecutableDetectionService>();
builder.Services.AddSingleton<SettingsService>();
builder.Services.AddSingleton<ProjectStateService>(); // Singleton to persist across page navigation
builder.Services.AddScoped<IXmlService, XmlService>();
builder.Services.AddScoped<ShotcutService>();
builder.Services.AddScoped<FileSearchService>();
// Dependency management services
builder.Services.AddSingleton<DependencyChecker>();
builder.Services.AddSingleton<DependencyInstaller>();
// Video rendering services
// FFmpegRenderService is Singleton to ensure FFMpegCore is configured once on startup
builder.Services.AddSingleton<FFmpegRenderService>();
builder.Services.AddScoped<MeltRenderService>();
builder.Services.AddSingleton<HardwareDetectionService>();
// Utility services
builder.Services.AddScoped<CheapShotcutRandomizer.Services.Utilities.VideoValidator>();
builder.Services.AddScoped<CheapShotcutRandomizer.Services.Utilities.FFmpegErrorHandler>();
// Database for render queue
builder.Services.AddDbContext<RenderJobDbContext>(options =>
options.UseSqlite("Data Source=renderjobs.db"));
// Repositories
builder.Services.AddScoped<IRenderJobRepository, RenderJobRepository>();
// Queue infrastructure
builder.Services.AddSingleton<IBackgroundTaskQueue>(_ =>
new BackgroundTaskQueue(capacity: 100));
// Render queue service (singleton for background service)
builder.Services.AddSingleton<RenderQueueService>(serviceProvider =>
new RenderQueueService(
serviceProvider,
serviceProvider.GetRequiredService<IBackgroundTaskQueue>(),
maxConcurrentRenders: 1 // Configure: 1 for video rendering (CPU/GPU intensive)
));
// Register as both IRenderQueueService and IHostedService
builder.Services.AddSingleton<IRenderQueueService>(sp =>
sp.GetRequiredService<RenderQueueService>());
builder.Services.AddHostedService(sp =>
sp.GetRequiredService<RenderQueueService>());
// Initialization hosted services (run after app starts)
builder.Services.AddHostedService<FFmpegInitializationService>(); // Initialize FFmpeg first
builder.Services.AddHostedService<DatabaseInitializationService>();
// Configure graceful shutdown
builder.Services.Configure<HostOptions>(options =>
{
options.ShutdownTimeout = TimeSpan.FromSeconds(30);
});
// Run the app - all Avalonia complexity handled by the package
// Note: DebugLogger is initialized lazily on first use via SettingsService
builder.RunApp(args);
}
}