From 58f21a69aaa65a35da0551b4c7336562614ab925 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Fri, 11 Oct 2024 19:35:37 +0900 Subject: [PATCH] Improve UX for uninstalling disabled plugins --- .../Controllers/UIServerController.Plugins.cs | 10 +++++ .../HostedServices/EventHostedServiceBase.cs | 11 +++-- .../Views/UIServer/ListPlugins.cshtml | 44 ++++++++++++------- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/BTCPayServer/Controllers/UIServerController.Plugins.cs b/BTCPayServer/Controllers/UIServerController.Plugins.cs index 209384d13..fe7927bd9 100644 --- a/BTCPayServer/Controllers/UIServerController.Plugins.cs +++ b/BTCPayServer/Controllers/UIServerController.Plugins.cs @@ -59,6 +59,16 @@ namespace BTCPayServer.Controllers public Dictionary DownloadedPluginsByIdentifier { get; set; } = new Dictionary(); } + [HttpPost("server/plugins/uninstall-all")] + public IActionResult UnInstallAllDisabledPlugin( + [FromServices] PluginService pluginService, string plugin) + { + var disabled = pluginService.GetDisabledPlugins(); + foreach (var d in disabled) + pluginService.UninstallPlugin(d.Key); + return RedirectToAction(nameof(ListPlugins)); + } + [HttpPost("server/plugins/uninstall")] public IActionResult UnInstallPlugin( [FromServices] PluginService pluginService, string plugin) diff --git a/BTCPayServer/HostedServices/EventHostedServiceBase.cs b/BTCPayServer/HostedServices/EventHostedServiceBase.cs index 9de711106..7ee37f55e 100644 --- a/BTCPayServer/HostedServices/EventHostedServiceBase.cs +++ b/BTCPayServer/HostedServices/EventHostedServiceBase.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Threading; @@ -17,8 +18,8 @@ namespace BTCPayServer.HostedServices public EventAggregator EventAggregator => _EventAggregator; - private List _Subscriptions; - private CancellationTokenSource _Cts; + private List _Subscriptions = new List(); + private CancellationTokenSource _Cts = new CancellationTokenSource(); public CancellationToken CancellationToken => _Cts.Token; public EventHostedServiceBase(EventAggregator eventAggregator, Logs logs) { @@ -78,9 +79,7 @@ namespace BTCPayServer.HostedServices public virtual Task StartAsync(CancellationToken cancellationToken) { - _Subscriptions = new List(); SubscribeToEvents(); - _Cts = new CancellationTokenSource(); _ProcessingEvents = ProcessEvents(_Cts.Token); return Task.CompletedTask; } @@ -88,8 +87,8 @@ namespace BTCPayServer.HostedServices public virtual async Task StopAsync(CancellationToken cancellationToken) { - _Subscriptions?.ForEach(subscription => subscription.Dispose()); - _Cts?.Cancel(); + _Subscriptions.ForEach(subscription => subscription.Dispose()); + _Cts.Cancel(); try { await _ProcessingEvents; diff --git a/BTCPayServer/Views/UIServer/ListPlugins.cshtml b/BTCPayServer/Views/UIServer/ListPlugins.cshtml index aa426a978..428cc89bc 100644 --- a/BTCPayServer/Views/UIServer/ListPlugins.cshtml +++ b/BTCPayServer/Views/UIServer/ListPlugins.cshtml @@ -68,10 +68,25 @@ +@if (Model.Commands.Any()) +{ +
+ You need to restart BTCPay Server in order to update your active plugins. + @if (Model.CanShowRestart) + { +
+ +
+ } +
+} @if (Model.Disabled.Any()) {
Some plugins were disabled due to fatal errors. They may be incompatible with this version of BTCPay Server. +
+ +

Disabled Plugins

@@ -87,9 +102,19 @@ (@version) } -
- -
+ @{ + var uninstalled = Model.Commands.Any(c => c.plugin == plugin && c.command == "delete"); + } +
+ @if (uninstalled) + { + + } + else + { + + } +
} @@ -97,19 +122,6 @@ } -@if (Model.Commands.Any()) -{ -
- You need to restart BTCPay Server in order to update your active plugins. - @if (Model.CanShowRestart) - { -
- -
- } -
-} - @if (Model.Installed.Any()) {

Installed Plugins