Preparations for plugin/module development
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Moonlight.ApiServer;
|
||||
|
||||
public static class DevServer
|
||||
{
|
||||
public async static Task Run(string[] args)
|
||||
public async static Task Run(string[] args, Assembly[] pluginAssemblies)
|
||||
{
|
||||
Console.WriteLine("Preparing development server");
|
||||
await Program.Main(args);
|
||||
await Startup.Run(args, pluginAssemblies);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,16 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<IsPackable>true</IsPackable>
|
||||
<Version>2.1.0</Version>
|
||||
<Title>Moonlight.ApiServer</Title>
|
||||
<Authors>Moonlight Panel</Authors>
|
||||
<Description>A build of moonlight's api server as a nuget package to develop moonlight plugins/modules</Description>
|
||||
<Copyright>Moonlight Panel</Copyright>
|
||||
<PackageProjectUrl>https://github.com/Moonlight-Panel/Moonlight</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/Moonlight-Panel/Moonlight</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>moonlight</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
using System.Reflection;
|
||||
using MoonCore.Extended.Extensions;
|
||||
using MoonCore.Extensions;
|
||||
using MoonCore.Helpers;
|
||||
using MoonCore.PluginFramework.Extensions;
|
||||
using Moonlight.ApiServer;
|
||||
using Moonlight.ApiServer.Configuration;
|
||||
using Moonlight.ApiServer.Helpers;
|
||||
using Moonlight.ApiServer.Http.Middleware;
|
||||
using Moonlight.ApiServer.Interfaces.Auth;
|
||||
using Moonlight.ApiServer.Interfaces.OAuth2;
|
||||
using Moonlight.ApiServer.Interfaces.Startup;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
// Cry about it
|
||||
#pragma warning disable ASP0000
|
||||
|
||||
// Fancy start console output... yes very fancy :>
|
||||
var rainbow = new Crayon.Rainbow(0.5);
|
||||
foreach (var c in "Moonlight")
|
||||
{
|
||||
Console.Write(
|
||||
rainbow
|
||||
.Next()
|
||||
.Bold()
|
||||
.Text(c.ToString())
|
||||
);
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
// Storage i guess
|
||||
Directory.CreateDirectory(PathBuilder.Dir("storage"));
|
||||
|
||||
// TODO: Load plugin/module assemblies
|
||||
|
||||
// Configure startup logger
|
||||
var startupLoggerFactory = new LoggerFactory();
|
||||
|
||||
// TODO: Add direct extension method
|
||||
var providers = LoggerBuildHelper.BuildFromConfiguration(configuration =>
|
||||
{
|
||||
configuration.Console.Enable = true;
|
||||
configuration.Console.EnableAnsiMode = true;
|
||||
configuration.FileLogging.Enable = false;
|
||||
});
|
||||
|
||||
startupLoggerFactory.AddProviders(providers);
|
||||
|
||||
var startupLogger = startupLoggerFactory.CreateLogger("Startup");
|
||||
|
||||
// Configure startup interfaces
|
||||
var startupServiceCollection = new ServiceCollection();
|
||||
|
||||
startupServiceCollection.AddConfiguration(options =>
|
||||
{
|
||||
options.UsePath(PathBuilder.Dir("storage"));
|
||||
options.UseEnvironmentPrefix("MOONLIGHT");
|
||||
|
||||
options.AddConfiguration<AppConfiguration>("app");
|
||||
});
|
||||
|
||||
startupServiceCollection.AddLogging(loggingBuilder => { loggingBuilder.AddProviders(providers); });
|
||||
|
||||
startupServiceCollection.AddPlugins(configuration =>
|
||||
{
|
||||
// Configure startup interfaces
|
||||
configuration.AddInterface<IAppStartup>();
|
||||
configuration.AddInterface<IDatabaseStartup>();
|
||||
configuration.AddInterface<IEndpointStartup>();
|
||||
|
||||
// Configure assemblies to scan
|
||||
configuration.AddAssembly(typeof(Program).Assembly);
|
||||
});
|
||||
|
||||
|
||||
var startupServiceProvider = startupServiceCollection.BuildServiceProvider();
|
||||
var appStartupInterfaces = startupServiceProvider.GetRequiredService<IAppStartup[]>();
|
||||
|
||||
var config = startupServiceProvider.GetRequiredService<AppConfiguration>();
|
||||
ApplicationStateHelper.SetConfiguration(config);
|
||||
|
||||
// Start the actual app
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
await Startup.ConfigureLogging(builder);
|
||||
|
||||
await Startup.ConfigureDatabase(
|
||||
builder,
|
||||
startupLoggerFactory,
|
||||
startupServiceProvider.GetRequiredService<IDatabaseStartup[]>()
|
||||
);
|
||||
|
||||
// Call interfaces
|
||||
foreach (var startupInterface in appStartupInterfaces)
|
||||
{
|
||||
try
|
||||
{
|
||||
await startupInterface.BuildApp(builder);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
startupLogger.LogCritical(
|
||||
"An unhandled error occured while processing BuildApp call for interface '{interfaceName}': {e}",
|
||||
startupInterface.GetType().FullName,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddSingleton(config);
|
||||
builder.Services.AutoAddServices<Program>();
|
||||
builder.Services.AddHttpClient();
|
||||
|
||||
await Startup.ConfigureTokenAuthentication(builder, config);
|
||||
await Startup.ConfigureOAuth2(builder, startupLogger, config);
|
||||
|
||||
// Implementation service
|
||||
builder.Services.AddPlugins(configuration =>
|
||||
{
|
||||
configuration.AddInterface<IOAuth2Provider>();
|
||||
configuration.AddInterface<IAuthInterceptor>();
|
||||
|
||||
configuration.AddAssembly(typeof(Program).Assembly);
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
await Startup.PrepareDatabase(app);
|
||||
|
||||
if (config.Client.Enable)
|
||||
{
|
||||
if (app.Environment.IsDevelopment())
|
||||
app.UseWebAssemblyDebugging();
|
||||
|
||||
app.UseBlazorFrameworkFiles();
|
||||
app.UseStaticFiles();
|
||||
}
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseApiErrorHandling();
|
||||
|
||||
await Startup.UseTokenAuthentication(app);
|
||||
await Startup.UseOAuth2(app);
|
||||
|
||||
// Call interfaces
|
||||
foreach (var startupInterface in appStartupInterfaces)
|
||||
{
|
||||
try
|
||||
{
|
||||
await startupInterface.ConfigureApp(app);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
startupLogger.LogCritical(
|
||||
"An unhandled error occured while processing ConfigureApp call for interface '{interfaceName}': {e}",
|
||||
startupInterface.GetType().FullName,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
app.UseMiddleware<ApiAuthenticationMiddleware>();
|
||||
|
||||
app.UseMiddleware<AuthorizationMiddleware>();
|
||||
|
||||
// Call interfaces
|
||||
var endpointStartupInterfaces = startupServiceProvider.GetRequiredService<IEndpointStartup[]>();
|
||||
|
||||
foreach (var endpointStartup in endpointStartupInterfaces)
|
||||
{
|
||||
try
|
||||
{
|
||||
await endpointStartup.ConfigureEndpoints(app);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
startupLogger.LogCritical(
|
||||
"An unhandled error occured while processing ConfigureEndpoints call for interface '{interfaceName}': {e}",
|
||||
endpointStartup.GetType().FullName,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
if (config.Client.Enable)
|
||||
app.MapFallbackToFile("index.html");
|
||||
|
||||
await app.RunAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using MoonCore.Authentication;
|
||||
using MoonCore.Exceptions;
|
||||
@@ -7,9 +8,12 @@ using MoonCore.Extended.Helpers;
|
||||
using MoonCore.Extended.OAuth2.Consumer;
|
||||
using MoonCore.Extensions;
|
||||
using MoonCore.Helpers;
|
||||
using MoonCore.PluginFramework.Extensions;
|
||||
using Moonlight.ApiServer.Configuration;
|
||||
using Moonlight.ApiServer.Database.Entities;
|
||||
using Moonlight.ApiServer.Helpers;
|
||||
using Moonlight.ApiServer.Http.Middleware;
|
||||
using Moonlight.ApiServer.Interfaces.Auth;
|
||||
using Moonlight.ApiServer.Interfaces.OAuth2;
|
||||
using Moonlight.ApiServer.Interfaces.Startup;
|
||||
using Moonlight.Shared.Http.Responses.OAuth2;
|
||||
@@ -18,6 +22,202 @@ namespace Moonlight.ApiServer;
|
||||
|
||||
public static class Startup
|
||||
{
|
||||
public static async Task Main(string[] args)
|
||||
=> await Run(args, []);
|
||||
|
||||
public static async Task Run(string[] args, Assembly[]? pluginAssemblies = null)
|
||||
{
|
||||
// Cry about it
|
||||
#pragma warning disable ASP0000
|
||||
|
||||
// Fancy start console output... yes very fancy :>
|
||||
var rainbow = new Crayon.Rainbow(0.5);
|
||||
foreach (var c in "Moonlight")
|
||||
{
|
||||
Console.Write(
|
||||
rainbow
|
||||
.Next()
|
||||
.Bold()
|
||||
.Text(c.ToString())
|
||||
);
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
// Storage i guess
|
||||
Directory.CreateDirectory(PathBuilder.Dir("storage"));
|
||||
|
||||
// TODO: Load plugin/module assemblies
|
||||
|
||||
// Configure startup logger
|
||||
var startupLoggerFactory = new LoggerFactory();
|
||||
|
||||
// TODO: Add direct extension method
|
||||
var providers = LoggerBuildHelper.BuildFromConfiguration(configuration =>
|
||||
{
|
||||
configuration.Console.Enable = true;
|
||||
configuration.Console.EnableAnsiMode = true;
|
||||
configuration.FileLogging.Enable = false;
|
||||
});
|
||||
|
||||
startupLoggerFactory.AddProviders(providers);
|
||||
|
||||
var startupLogger = startupLoggerFactory.CreateLogger("Startup");
|
||||
|
||||
// Configure startup interfaces
|
||||
var startupServiceCollection = new ServiceCollection();
|
||||
|
||||
startupServiceCollection.AddConfiguration(options =>
|
||||
{
|
||||
options.UsePath(PathBuilder.Dir("storage"));
|
||||
options.UseEnvironmentPrefix("MOONLIGHT");
|
||||
|
||||
options.AddConfiguration<AppConfiguration>("app");
|
||||
});
|
||||
|
||||
startupServiceCollection.AddLogging(loggingBuilder => { loggingBuilder.AddProviders(providers); });
|
||||
|
||||
startupServiceCollection.AddPlugins(configuration =>
|
||||
{
|
||||
// Configure startup interfaces
|
||||
configuration.AddInterface<IAppStartup>();
|
||||
configuration.AddInterface<IDatabaseStartup>();
|
||||
configuration.AddInterface<IEndpointStartup>();
|
||||
|
||||
// Configure assemblies to scan
|
||||
configuration.AddAssembly(typeof(Startup).Assembly);
|
||||
|
||||
if(pluginAssemblies != null)
|
||||
configuration.AddAssemblies(pluginAssemblies);
|
||||
|
||||
//TODO: Load plugins from file
|
||||
});
|
||||
|
||||
|
||||
var startupServiceProvider = startupServiceCollection.BuildServiceProvider();
|
||||
var appStartupInterfaces = startupServiceProvider.GetRequiredService<IAppStartup[]>();
|
||||
|
||||
var config = startupServiceProvider.GetRequiredService<AppConfiguration>();
|
||||
ApplicationStateHelper.SetConfiguration(config);
|
||||
|
||||
// Start the actual app
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
await ConfigureLogging(builder);
|
||||
|
||||
await ConfigureDatabase(
|
||||
builder,
|
||||
startupLoggerFactory,
|
||||
startupServiceProvider.GetRequiredService<IDatabaseStartup[]>()
|
||||
);
|
||||
|
||||
// Call interfaces
|
||||
foreach (var startupInterface in appStartupInterfaces)
|
||||
{
|
||||
try
|
||||
{
|
||||
await startupInterface.BuildApp(builder);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
startupLogger.LogCritical(
|
||||
"An unhandled error occured while processing BuildApp call for interface '{interfaceName}': {e}",
|
||||
startupInterface.GetType().FullName,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddSingleton(config);
|
||||
builder.Services.AutoAddServices(typeof(Startup).Assembly);
|
||||
builder.Services.AddHttpClient();
|
||||
|
||||
await ConfigureTokenAuthentication(builder, config);
|
||||
await ConfigureOAuth2(builder, startupLogger, config);
|
||||
|
||||
// Implementation service
|
||||
builder.Services.AddPlugins(configuration =>
|
||||
{
|
||||
configuration.AddInterface<IOAuth2Provider>();
|
||||
configuration.AddInterface<IAuthInterceptor>();
|
||||
|
||||
configuration.AddAssembly(typeof(Startup).Assembly);
|
||||
|
||||
if(pluginAssemblies != null)
|
||||
configuration.AddAssemblies(pluginAssemblies);
|
||||
|
||||
//TODO: Load plugins from file
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
await PrepareDatabase(app);
|
||||
|
||||
if (config.Client.Enable)
|
||||
{
|
||||
if (app.Environment.IsDevelopment())
|
||||
app.UseWebAssemblyDebugging();
|
||||
|
||||
app.UseBlazorFrameworkFiles();
|
||||
app.UseStaticFiles();
|
||||
}
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseApiErrorHandling();
|
||||
|
||||
await UseTokenAuthentication(app);
|
||||
await UseOAuth2(app);
|
||||
|
||||
// Call interfaces
|
||||
foreach (var startupInterface in appStartupInterfaces)
|
||||
{
|
||||
try
|
||||
{
|
||||
await startupInterface.ConfigureApp(app);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
startupLogger.LogCritical(
|
||||
"An unhandled error occured while processing ConfigureApp call for interface '{interfaceName}': {e}",
|
||||
startupInterface.GetType().FullName,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
app.UseMiddleware<ApiAuthenticationMiddleware>();
|
||||
|
||||
app.UseMiddleware<AuthorizationMiddleware>();
|
||||
|
||||
// Call interfaces
|
||||
var endpointStartupInterfaces = startupServiceProvider.GetRequiredService<IEndpointStartup[]>();
|
||||
|
||||
foreach (var endpointStartup in endpointStartupInterfaces)
|
||||
{
|
||||
try
|
||||
{
|
||||
await endpointStartup.ConfigureEndpoints(app);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
startupLogger.LogCritical(
|
||||
"An unhandled error occured while processing ConfigureEndpoints call for interface '{interfaceName}': {e}",
|
||||
endpointStartup.GetType().FullName,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
if (config.Client.Enable)
|
||||
app.MapFallbackToFile("index.html");
|
||||
|
||||
await app.RunAsync();
|
||||
}
|
||||
|
||||
#region Logging
|
||||
|
||||
public static async Task ConfigureLogging(IHostApplicationBuilder builder)
|
||||
@@ -313,7 +513,7 @@ public static class Startup
|
||||
|
||||
return new Dictionary<string, object>()
|
||||
{
|
||||
{"userId", user.Id}
|
||||
{ "userId", user.Id }
|
||||
};
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
12
Moonlight.Client/DevClient.cs
Normal file
12
Moonlight.Client/DevClient.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Moonlight.Client;
|
||||
|
||||
public class DevClient
|
||||
{
|
||||
public async static Task Run(string[] args, Assembly[] assemblies)
|
||||
{
|
||||
Console.WriteLine("Preparing development client");
|
||||
await Startup.Run(args, assemblies);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,16 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<IsPackable>true</IsPackable>
|
||||
<Version>2.1.0</Version>
|
||||
<Title>Moonlight.Client</Title>
|
||||
<Authors>Moonlight Panel</Authors>
|
||||
<Description>A build of moonlight's client as a nuget package to develop moonlight plugins/modules</Description>
|
||||
<Copyright>Moonlight Panel</Copyright>
|
||||
<PackageProjectUrl>https://github.com/Moonlight-Panel/Moonlight</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/Moonlight-Panel/Moonlight</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>moonlight</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,126 +1,3 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||
using MoonCore.Blazor.Extensions;
|
||||
using MoonCore.Blazor.Services;
|
||||
using MoonCore.Blazor.Tailwind.Extensions;
|
||||
using MoonCore.Blazor.Tailwind.Forms;
|
||||
using MoonCore.Blazor.Tailwind.Forms.Components;
|
||||
using MoonCore.Exceptions;
|
||||
using MoonCore.Extensions;
|
||||
using MoonCore.Helpers;
|
||||
using MoonCore.Models;
|
||||
using MoonCore.PluginFramework.Extensions;
|
||||
using Moonlight.Client.Interfaces;
|
||||
using Moonlight.Client.Services;
|
||||
using Moonlight.Client.UI;
|
||||
using Moonlight.Client.UI.Forms;
|
||||
using Moonlight.Shared.Http.Requests.Auth;
|
||||
using Moonlight.Shared.Http.Responses.Auth;
|
||||
using Moonlight.Client;
|
||||
|
||||
// Build pre run logger
|
||||
var providers = LoggerBuildHelper.BuildFromConfiguration(configuration =>
|
||||
{
|
||||
configuration.Console.Enable = true;
|
||||
configuration.Console.EnableAnsiMode = true;
|
||||
configuration.FileLogging.Enable = false;
|
||||
});
|
||||
|
||||
using var loggerFactory = new LoggerFactory(providers);
|
||||
var logger = loggerFactory.CreateLogger("Startup");
|
||||
|
||||
// Fancy start console output... yes very fancy :>
|
||||
Console.Write("Running ");
|
||||
|
||||
var rainbow = new Crayon.Rainbow(0.5);
|
||||
foreach (var c in "Moonlight")
|
||||
{
|
||||
Console.Write(
|
||||
rainbow
|
||||
.Next()
|
||||
.Bold()
|
||||
.Text(c.ToString())
|
||||
);
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
// Building app
|
||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||
|
||||
// Configure application logging
|
||||
builder.Logging.ClearProviders();
|
||||
builder.Logging.AddProviders(providers);
|
||||
|
||||
builder.RootComponents.Add<App>("#app");
|
||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
||||
|
||||
builder.Services.AddScoped(_ => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
||||
|
||||
builder.AddTokenAuthentication();
|
||||
builder.AddOAuth2();
|
||||
|
||||
/*
|
||||
builder.Services.AddScoped(sp =>
|
||||
{
|
||||
var httpClient = sp.GetRequiredService<HttpClient>();
|
||||
var localStorageService = sp.GetRequiredService<LocalStorageService>();
|
||||
var result = new HttpApiClient(httpClient);
|
||||
|
||||
result.AddLocalStorageTokenAuthentication(localStorageService, async refreshToken =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var httpApiClient = new HttpApiClient(httpClient);
|
||||
|
||||
var response = await httpApiClient.PostJson<RefreshResponse>(
|
||||
"api/auth/refresh",
|
||||
new RefreshRequest()
|
||||
{
|
||||
RefreshToken = refreshToken
|
||||
}
|
||||
);
|
||||
|
||||
return (new TokenPair()
|
||||
{
|
||||
AccessToken = response.AccessToken,
|
||||
RefreshToken = response.RefreshToken
|
||||
}, response.ExpiresAt);
|
||||
}
|
||||
catch (HttpApiException)
|
||||
{
|
||||
return (new TokenPair()
|
||||
{
|
||||
AccessToken = "unset",
|
||||
RefreshToken = "unset"
|
||||
}, DateTime.MinValue);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
});*/
|
||||
|
||||
builder.Services.AddMoonCoreBlazorTailwind();
|
||||
builder.Services.AddScoped<WindowService>();
|
||||
builder.Services.AddScoped<LocalStorageService>();
|
||||
|
||||
builder.Services.AutoAddServices<Program>();
|
||||
|
||||
FormComponentRepository.Set<string, StringComponent>();
|
||||
FormComponentRepository.Set<int, IntComponent>();
|
||||
FormComponentRepository.Set<DateTime, DateComponent>();
|
||||
|
||||
// Interface service
|
||||
builder.Services.AddPlugins(configuration =>
|
||||
{
|
||||
configuration.AddAssembly(Assembly.GetEntryAssembly()!);
|
||||
|
||||
configuration.AddInterface<IAppLoader>();
|
||||
configuration.AddInterface<IAppScreen>();
|
||||
|
||||
configuration.AddInterface<ISidebarItemProvider>();
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
await app.RunAsync();
|
||||
await Startup.Run(args, []);
|
||||
131
Moonlight.Client/Startup.cs
Normal file
131
Moonlight.Client/Startup.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||
using MoonCore.Blazor.Extensions;
|
||||
using MoonCore.Blazor.Services;
|
||||
using MoonCore.Blazor.Tailwind.Extensions;
|
||||
using MoonCore.Blazor.Tailwind.Forms;
|
||||
using MoonCore.Blazor.Tailwind.Forms.Components;
|
||||
using MoonCore.Extensions;
|
||||
using MoonCore.Helpers;
|
||||
using MoonCore.PluginFramework.Extensions;
|
||||
using Moonlight.Client.Interfaces;
|
||||
using Moonlight.Client.Services;
|
||||
using Moonlight.Client.UI;
|
||||
using Moonlight.Client.UI.Forms;
|
||||
|
||||
namespace Moonlight.Client;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public static async Task Run(string[] args, Assembly[] assemblies)
|
||||
{
|
||||
// Build pre run logger
|
||||
var providers = LoggerBuildHelper.BuildFromConfiguration(configuration =>
|
||||
{
|
||||
configuration.Console.Enable = true;
|
||||
configuration.Console.EnableAnsiMode = true;
|
||||
configuration.FileLogging.Enable = false;
|
||||
});
|
||||
|
||||
using var loggerFactory = new LoggerFactory(providers);
|
||||
var logger = loggerFactory.CreateLogger("Startup");
|
||||
|
||||
// Fancy start console output... yes very fancy :>
|
||||
Console.Write("Running ");
|
||||
|
||||
var rainbow = new Crayon.Rainbow(0.5);
|
||||
foreach (var c in "Moonlight")
|
||||
{
|
||||
Console.Write(
|
||||
rainbow
|
||||
.Next()
|
||||
.Bold()
|
||||
.Text(c.ToString())
|
||||
);
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
// Building app
|
||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||
|
||||
// Configure application logging
|
||||
builder.Logging.ClearProviders();
|
||||
builder.Logging.AddProviders(providers);
|
||||
|
||||
builder.RootComponents.Add<App>("#app");
|
||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
||||
|
||||
builder.Services.AddScoped(_ => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
||||
|
||||
builder.AddTokenAuthentication();
|
||||
builder.AddOAuth2();
|
||||
|
||||
/*
|
||||
builder.Services.AddScoped(sp =>
|
||||
{
|
||||
var httpClient = sp.GetRequiredService<HttpClient>();
|
||||
var localStorageService = sp.GetRequiredService<LocalStorageService>();
|
||||
var result = new HttpApiClient(httpClient);
|
||||
|
||||
result.AddLocalStorageTokenAuthentication(localStorageService, async refreshToken =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var httpApiClient = new HttpApiClient(httpClient);
|
||||
|
||||
var response = await httpApiClient.PostJson<RefreshResponse>(
|
||||
"api/auth/refresh",
|
||||
new RefreshRequest()
|
||||
{
|
||||
RefreshToken = refreshToken
|
||||
}
|
||||
);
|
||||
|
||||
return (new TokenPair()
|
||||
{
|
||||
AccessToken = response.AccessToken,
|
||||
RefreshToken = response.RefreshToken
|
||||
}, response.ExpiresAt);
|
||||
}
|
||||
catch (HttpApiException)
|
||||
{
|
||||
return (new TokenPair()
|
||||
{
|
||||
AccessToken = "unset",
|
||||
RefreshToken = "unset"
|
||||
}, DateTime.MinValue);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
});*/
|
||||
|
||||
builder.Services.AddMoonCoreBlazorTailwind();
|
||||
builder.Services.AddScoped<WindowService>();
|
||||
builder.Services.AddScoped<LocalStorageService>();
|
||||
|
||||
builder.Services.AutoAddServices<Startup>();
|
||||
|
||||
FormComponentRepository.Set<string, StringComponent>();
|
||||
FormComponentRepository.Set<int, IntComponent>();
|
||||
FormComponentRepository.Set<DateTime, DateComponent>();
|
||||
|
||||
// Interface service
|
||||
builder.Services.AddPlugins(configuration =>
|
||||
{
|
||||
configuration.AddAssembly(typeof(Startup).Assembly);
|
||||
configuration.AddAssemblies(assemblies);
|
||||
|
||||
configuration.AddInterface<IAppLoader>();
|
||||
configuration.AddInterface<IAppScreen>();
|
||||
|
||||
configuration.AddInterface<ISidebarItemProvider>();
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
await app.RunAsync();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,17 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>true</IsPackable>
|
||||
<Version>2.1.0</Version>
|
||||
<Title>Moonlight.Shared</Title>
|
||||
<Authors>Moonlight Panel</Authors>
|
||||
<Description>A build of moonlight's shared classes as a nuget package to develop moonlight plugins/modules</Description>
|
||||
<Copyright>Moonlight Panel</Copyright>
|
||||
<PackageProjectUrl>https://github.com/Moonlight-Panel/Moonlight</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/Moonlight-Panel/Moonlight</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>moonlight</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user