diff --git a/Moonlight/App/Configuration/ConfigV1.cs b/Moonlight/App/Configuration/ConfigV1.cs index 7836b7cb..67224fd2 100644 --- a/Moonlight/App/Configuration/ConfigV1.cs +++ b/Moonlight/App/Configuration/ConfigV1.cs @@ -174,7 +174,7 @@ public class ConfigV1 { [JsonProperty("Token")] public string Token { get; set; } = Guid.NewGuid().ToString(); - [JsonProperty("ReCaptcha")] public ReCaptchaData ReCaptcha { get; set; } + [JsonProperty("ReCaptcha")] public ReCaptchaData ReCaptcha { get; set; } = new(); } public class ReCaptchaData diff --git a/Moonlight/App/Helpers/Wings/WingsConsole.cs b/Moonlight/App/Helpers/Wings/WingsConsole.cs index d1efb9bc..9767e540 100644 --- a/Moonlight/App/Helpers/Wings/WingsConsole.cs +++ b/Moonlight/App/Helpers/Wings/WingsConsole.cs @@ -243,6 +243,7 @@ public class WingsConsole : IDisposable } } catch(JsonReaderException){} + catch(JsonSerializationException){} catch (Exception e) { if (!Disconnecting) diff --git a/Moonlight/App/Services/Interop/AlertService.cs b/Moonlight/App/Services/Interop/AlertService.cs index 24a15fa4..a5cad8f1 100644 --- a/Moonlight/App/Services/Interop/AlertService.cs +++ b/Moonlight/App/Services/Interop/AlertService.cs @@ -1,21 +1,40 @@ using CurrieTechnologies.Razor.SweetAlert2; +using Microsoft.JSInterop; namespace Moonlight.App.Services.Interop; public class AlertService { - private readonly SweetAlertService SweetAlertService; private readonly SmartTranslateService SmartTranslateService; + private readonly IJSRuntime JsRuntime; + private SweetAlertService? SweetAlertService; - public AlertService(SweetAlertService service, SmartTranslateService smartTranslateService) + public AlertService(SmartTranslateService smartTranslateService, IJSRuntime jsRuntime) { - SweetAlertService = service; SmartTranslateService = smartTranslateService; + JsRuntime = jsRuntime; + } + + // We create the swal service here and not using the dependency injection + // because it initializes when instantiated which leads to js invoke errors + private Task EnsureService() + { + if (SweetAlertService == null) + { + SweetAlertService = new(JsRuntime, new() + { + Theme = SweetAlertTheme.Dark + }); + } + + return Task.CompletedTask; } public async Task Info(string title, string desciption) { - await SweetAlertService.FireAsync(new SweetAlertOptions() + await EnsureService(); + + await SweetAlertService!.FireAsync(new SweetAlertOptions() { Title = title, Text = desciption, @@ -30,7 +49,9 @@ public class AlertService public async Task Success(string title, string desciption) { - await SweetAlertService.FireAsync(new SweetAlertOptions() + await EnsureService(); + + await SweetAlertService!.FireAsync(new SweetAlertOptions() { Title = title, Text = desciption, @@ -45,7 +66,9 @@ public class AlertService public async Task Warning(string title, string desciption) { - await SweetAlertService.FireAsync(new SweetAlertOptions() + await EnsureService(); + + await SweetAlertService!.FireAsync(new SweetAlertOptions() { Title = title, Text = desciption, @@ -60,7 +83,9 @@ public class AlertService public async Task Error(string title, string desciption) { - await SweetAlertService.FireAsync(new SweetAlertOptions() + await EnsureService(); + + await SweetAlertService!.FireAsync(new SweetAlertOptions() { Title = title, Text = desciption, @@ -75,7 +100,9 @@ public class AlertService public async Task YesNo(string title, string desciption, string yesText, string noText) { - var result = await SweetAlertService.FireAsync(new SweetAlertOptions() + await EnsureService(); + + var result = await SweetAlertService!.FireAsync(new SweetAlertOptions() { Title = title, Text = desciption, @@ -91,7 +118,9 @@ public class AlertService public async Task Text(string title, string desciption, string setValue) { - var result = await SweetAlertService.FireAsync(new SweetAlertOptions() + await EnsureService(); + + var result = await SweetAlertService!.FireAsync(new SweetAlertOptions() { Title = title, Text = desciption, diff --git a/Moonlight/App/Services/Statistics/StatisticsCaptureService.cs b/Moonlight/App/Services/Statistics/StatisticsCaptureService.cs index 39f341e9..28333f48 100644 --- a/Moonlight/App/Services/Statistics/StatisticsCaptureService.cs +++ b/Moonlight/App/Services/Statistics/StatisticsCaptureService.cs @@ -36,8 +36,6 @@ public class StatisticsCaptureService { while (await Timer.WaitForNextTickAsync()) { - Logger.Warn("Creating statistics"); - using var scope = ServiceScopeFactory.CreateScope(); var statisticsRepo = scope.ServiceProvider.GetRequiredService>(); diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index 1ffe3145..cc520db6 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -18,7 +18,7 @@ - + diff --git a/Moonlight/Program.cs b/Moonlight/Program.cs index 223e2f26..d78d7967 100644 --- a/Moonlight/Program.cs +++ b/Moonlight/Program.cs @@ -32,7 +32,6 @@ using Moonlight.App.Services.SupportChat; using Sentry; using Serilog; using Serilog.Events; -using Serilog.Sinks.SystemConsole.Themes; namespace Moonlight { @@ -249,7 +248,6 @@ namespace Moonlight // Third party services builder.Services.AddBlazorTable(); - builder.Services.AddSweetAlert2(options => { options.Theme = SweetAlertTheme.Dark; }); builder.Services.AddBlazorContextMenu(); builder.Services.AddBlazorDownloadFile(); diff --git a/Moonlight/Shared/Components/Xterm/Terminal.razor b/Moonlight/Shared/Components/Xterm/Terminal.razor index 16ee2bbc..e47426e7 100644 --- a/Moonlight/Shared/Components/Xterm/Terminal.razor +++ b/Moonlight/Shared/Components/Xterm/Terminal.razor @@ -39,7 +39,15 @@ public async void Dispose() { - await Xterm.DisposeAsync(); + try + { + await Xterm.DisposeAsync(); + } + catch (Exception) + { + // ignore dispose errors. They occur when the tab closes unexpectedly + // so we can ignore them + } } private async void OnFirstRender() diff --git a/Moonlight/Shared/Layouts/MainLayout.razor b/Moonlight/Shared/Layouts/MainLayout.razor index 040186ad..8eac6b55 100644 --- a/Moonlight/Shared/Layouts/MainLayout.razor +++ b/Moonlight/Shared/Layouts/MainLayout.razor @@ -163,13 +163,11 @@ private bool IsIpBanned = false; - protected override void OnInitialized() - { - AddBodyAttribute("data-kt-app-page-loading", "on"); - } - protected override void OnAfterRender(bool firstRender) { + if(firstRender) + AddBodyAttribute("data-kt-app-page-loading", "on"); + //Initialize classes and attributes for layout with dark sidebar AddBodyAttribute("data-kt-app-reset-transition", "true"); diff --git a/Moonlight/Shared/Views/Admin/Nodes/Setup.razor b/Moonlight/Shared/Views/Admin/Nodes/Setup.razor index d3ae6c11..1296259e 100644 --- a/Moonlight/Shared/Views/Admin/Nodes/Setup.razor +++ b/Moonlight/Shared/Views/Admin/Nodes/Setup.razor @@ -40,7 +40,7 @@   host: 0.0.0.0
  port: @(Node.HttpPort)
  ssl:
-     enabled: false
+     enabled: @(Node.Ssl ? "true" : "false")
    cert: /etc/letsencrypt/live/@(Node.Fqdn)/fullchain.pem
    key: /etc/letsencrypt/live/@(Node.Fqdn)/privkey.pem
  disable_remote_download: false