Merge branch 'v2' into AddTicketSystem

This commit is contained in:
Marcel Baumgartner 2023-11-10 15:13:51 +01:00 committed by GitHub
commit 0e43278bdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 98 additions and 9 deletions

View file

@ -23,4 +23,5 @@ public class Events
public static EventHandler<Ticket> OnTicketCreated;
public static EventHandler<TicketMessageEventArgs> OnTicketMessage;
public static EventHandler<Ticket> OnTicketUpdated;
public static EventHandler OnMoonlightRestart;
}

View file

@ -0,0 +1,27 @@
using Moonlight.App.Event;
using Moonlight.App.Extensions;
using Moonlight.App.Helpers;
namespace Moonlight.App.Services.Sys;
public class MoonlightService // This service can be used to perform strictly panel specific actions
{
private readonly ConfigService ConfigService;
public WebApplication Application { get; set; } // Do NOT modify using a plugin
public MoonlightService(ConfigService configService)
{
ConfigService = configService;
}
public async Task Restart()
{
Logger.Info("Restarting moonlight");
// Notify all users that this instance will restart
await Events.OnMoonlightRestart.InvokeAsync();
await Task.Delay(TimeSpan.FromSeconds(3));
await Application.StopAsync();
}
}

View file

@ -13,10 +13,14 @@ using Moonlight.App.Services.Interop;
using Moonlight.App.Services.ServiceManage;
using Moonlight.App.Services.Store;
using Moonlight.App.Services.Ticketing;
using Moonlight.App.Services.Sys;
using Moonlight.App.Services.Users;
using Moonlight.App.Services.Utils;
using Serilog;
var configService = new ConfigService();
var moonlightService = new MoonlightService(configService);
Directory.CreateDirectory(PathBuilder.Dir("storage"));
Directory.CreateDirectory(PathBuilder.Dir("storage", "logs"));
@ -84,10 +88,11 @@ builder.Services.AddScoped<TicketCreateService>();
// Services
builder.Services.AddScoped<IdentityService>();
builder.Services.AddSingleton<ConfigService>();
builder.Services.AddSingleton(configService);
builder.Services.AddSingleton<SessionService>();
builder.Services.AddSingleton<BucketService>();
builder.Services.AddSingleton<MailService>();
builder.Services.AddSingleton(moonlightService);
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
@ -104,6 +109,7 @@ var config =
builder.Logging.AddConfiguration(config.Build());
var app = builder.Build();
moonlightService.Application = app;
app.UseStaticFiles();
app.UseRouting();

View file

@ -3,7 +3,7 @@
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5132",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"

View file

@ -0,0 +1,18 @@
@inject NavigationManager Navigation
<div class="w-100">
<div class="card-body">
<div class="text-start mb-8">
<h1 class="text-dark mb-3 fs-3x">
Restarting
</h1>
<div class="text-gray-400 fw-semibold fs-6">
The panel is restarting. This may take a moment
</div>
</div>
<div class="d-flex flex-stack">
<a href="javascript:location.reload()" class="btn btn-primary me-2 flex-shrink-0">Reconnect</a>
</div>
</div>
</div>

View file

@ -2,6 +2,7 @@
@using Moonlight.App.Models.Abstractions
@using Moonlight.App.Models.Enums
@using Moonlight.Shared.Components.Auth
@using Moonlight.App.Event
@inherits LayoutComponentBase
@implements IDisposable
@ -11,6 +12,7 @@
@inject IdentityService IdentityService
@inject SessionService SessionService
@inject NavigationManager Navigation
@inject IJSRuntime JsRuntime
@{
var url = new Uri(Navigation.Uri);
@ -32,6 +34,12 @@
<ChangePassword/>
</OverlayLayout>
}
else if (RestartLock)
{
<OverlayLayout>
<RestartAlert/>
</OverlayLayout>
}
else
{
<DefaultLayout>
@ -90,6 +98,7 @@ else
@code
{
private bool Initialized = false;
private bool RestartLock = false;
private Session? MySession;
@ -114,6 +123,12 @@ else
MySession.UpdatedAt = DateTime.UtcNow;
}
};
Events.OnMoonlightRestart += async (_, _) =>
{
RestartLock = true;
await InvokeAsync(StateHasChanged);
};
}
protected override async Task OnAfterRenderAsync(bool firstRender)

View file

@ -1,4 +1,14 @@
<div class="d-flex flex-column flex-root" id="kt_app_root">
@* disable any reconnect screens *@
<style>
#components-reconnect-modal
{
display: none !important;
pointer-events: none;
}
</style>
<div class="d-flex flex-column flex-root" id="kt_app_root">
<div class="d-flex flex-column flex-lg-row flex-column-fluid">
<a href="/" class="d-block d-lg-none mx-auto py-20">
<img alt="Logo" src="/metronic8/demo38/assets/media/logos/default.svg" class="theme-light-show h-25px">

View file

@ -2,7 +2,19 @@
@using Moonlight.App.Extensions.Attributes
@using Moonlight.App.Models.Enums
@using Moonlight.App.Services
@using Moonlight.App.Services.Sys
@attribute [RequirePermission(Permission.AdminRoot)]
@inject MoonlightService MoonlightService
<AdminSysNavigation Index="0" />
<div class="row mt-5">
<div class="col-md-4 col-12">
<div class="card card-body">
<ConfirmButton OnClick="MoonlightService.Restart" Text="Restart" CssClasses="btn-danger" />
</div>
</div>
</div>