-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (56 loc) · 2.32 KB
/
Copy pathProgram.cs
File metadata and controls
61 lines (56 loc) · 2.32 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
// Copyright (C) 2025 Martin Renner
// LGPL-3.0-or-later (see file COPYING and COPYING.LESSER)
using System.IO.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using SharpDeck.Extensions.Hosting;
using StreamDeckSimHub.Plugin.ActionEditor;
using StreamDeckSimHub.Plugin.Actions.GenericButton.Model;
using StreamDeckSimHub.Plugin.PropertyLogic;
using StreamDeckSimHub.Plugin.SimHub;
using StreamDeckSimHub.Plugin.Tools;
using StreamDeckSimHub.Plugin.Tools.AutoUpdate;
namespace StreamDeckSimHub.Plugin;
/// <summary>
/// Before the inclusion of WPF, this was the entry point into the plugin. Now it is just a static helper class
/// to initialize the Hosting environment.
/// </summary>
public abstract class Program
{
public static IHost CreateHost(bool devMode = false)
{
var hostBuilder = Host.CreateDefaultBuilder()
.ConfigureLogging((context, loggingBuilder) =>
{
loggingBuilder
.ClearProviders()
.AddNLog();
})
.ConfigureServices(ConfigureServices);
if (!devMode)
{
hostBuilder.UseStreamDeck();
}
var host = hostBuilder.Build();
return host;
}
static void ConfigureServices(HostBuilderContext context, IServiceCollection serviceCollection)
{
serviceCollection.Configure<ConnectionSettings>(context.Configuration.GetSection("SimHubConnection"));
serviceCollection.AddSingleton<PropertyParser>();
serviceCollection.AddSingleton<ISimHubConnection, SimHubConnection>();
serviceCollection.AddSingleton<ShakeItStructureFetcher>();
serviceCollection.AddSingleton<PropertyComparer>();
serviceCollection.AddSingleton<ImageUtils>();
serviceCollection.AddSingleton<ImageManager>();
serviceCollection.AddSingleton<IFileSystem>(new FileSystem());
serviceCollection.AddHostedService<PeriodicBackgroundService>();
serviceCollection.AddSingleton<ActionEditorManager>();
serviceCollection.AddSingleton<NCalcHandler>();
serviceCollection.AddSingleton<SettingsConverter>();
serviceCollection.AddSingleton<ItemScaler>();
serviceCollection.AddSingleton<AutoUpdater>();
}
}