-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
109 lines (93 loc) · 4.45 KB
/
Copy pathProgram.cs
File metadata and controls
109 lines (93 loc) · 4.45 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
101
102
103
104
105
106
107
108
109
using System;
using System.Windows;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using HTPC.Services;
namespace HTPC;
public class Program
{
[STAThread] // Mandatory for WPF/COM Interop
public static void Main(string[] args)
{
// 1. Build the Generic Host
var hostBuilder = Host.CreateDefaultBuilder(args)
// Configure Kestrel Web Server for Remote API
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.Configure(app =>
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
// Existing status check
endpoints.MapGet("/api/status", () => "HTPC Core API is online.");
// NEW: Remote Control Endpoints
// The framework automatically grabs our Singleton MpvPlaybackService from Dependency Injection
endpoints.MapGet("/api/pause", (MpvPlaybackService player) =>
{
player.Pause();
return "Video Paused";
});
endpoints.MapGet("/api/resume", (MpvPlaybackService player) =>
{
player.Resume();
return "Video Resumed";
});
endpoints.MapGet("/api/stop", (MpvPlaybackService player) =>
{
player.Stop();
return "Video Stopped";
});
});
});
// Bind Kestrel to port 5001 (accessible locally and on your network)
webBuilder.UseUrls("http://localhost:55001");
})
// Configure Dependency Injection
.ConfigureServices((context, services) =>
{
services.AddSingleton<App>();
services.AddSingleton<MpvPlaybackService>();
services.AddDbContext<HTPC.Core.Data.AppDbContext>();
services.AddSingleton<ServerManagerService>();
services.AddHttpClient();
services.AddSingleton<UpdateService>();
// NEW: Register the native HTTP connection factory
services.AddHttpClient();
services.AddSingleton<MediaLibraryService>();
services.AddTransient<HTPC.UI.Views.MoviesView>();
services.AddTransient<HTPC.UI.Views.DashboardView>();
services.AddTransient<HTPC.UI.Views.PlayerView>();
services.AddTransient<HTPC.UI.Views.SettingsView>();
services.AddSingleton<HTPC.UI.Windows.MainWindow>();
services.AddTransient<HTPC.UI.Views.GuideView>();
services.AddTransient<HTPC.UI.Views.ShowsView>();
services.AddTransient<HTPC.UI.Views.VideosView>();
services.AddTransient<HTPC.UI.Views.MultiviewSetupView>();
services.AddTransient<HTPC.UI.ViewModels.RecordingsViewModel>();
services.AddTransient<HTPC.UI.Views.RecordingsView>();
services.AddTransient<HTPC.UI.ViewModels.CollectionsViewModel>();
services.AddTransient<HTPC.UI.Views.CollectionsView>();
});
using var host = hostBuilder.Build();
// 2. Start the Background Host
host.Start();
// --- NEW: Force Database Initialization ---
using (var scope = host.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<HTPC.Core.Data.AppDbContext>();
db.Database.EnsureCreated();
}
// ------------------------------------------
// 3. Force initialization of our player service
var playerService = host.Services.GetRequiredService<MpvPlaybackService>();
// Start the WPF UI Thread and launch the SPA Shell
var wpfApp = host.Services.GetRequiredService<App>();
var mainWindow = host.Services.GetRequiredService<HTPC.UI.Windows.MainWindow>();
wpfApp.Run(mainWindow);
// 5. Clean up when the application exits
host.StopAsync().GetAwaiter().GetResult();
}
}