-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtensions.cs
50 lines (46 loc) · 1.65 KB
/
Extensions.cs
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
using System.Runtime.InteropServices;
using Microsoft.Extensions.DependencyInjection;
using Celestial.Providers;
namespace Celestial;
public static class Extensions
{
public static IServiceCollection AddProviders(this IServiceCollection services)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
string? currentDesktop = Environment.GetEnvironmentVariable("XDG_CURRENT_DESKTOP");
if (currentDesktop != null)
{
if (currentDesktop.Contains("GNOME", StringComparison.OrdinalIgnoreCase))
{
services.AddSingleton<IProvider, Gnome>();
}
else if (currentDesktop.Contains("Cinnamon", StringComparison.OrdinalIgnoreCase))
{
services.AddSingleton<IProvider, Cinnamon>();
}
else
{
throw new InvalidOperationException($@"Unsupported desktop environment ""{currentDesktop}""");
}
}
else
{
throw new InvalidOperationException("Unable to determine desktop environment, XDG_CURRENT_DESKTOP variable is not set");
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
services.AddSingleton<IProvider, Windows>();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
services.AddSingleton<IProvider, MacOS>();
}
else
{
throw new InvalidOperationException("Operating system not supported");
}
return services;
}
}