mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Removing CssThemeManager dependency on ServerController
Using newly created BaseAsyncService to listen for database changes of theme setting
This commit is contained in:
@@ -25,17 +25,14 @@ namespace BTCPayServer.Controllers
|
|||||||
private UserManager<ApplicationUser> _UserManager;
|
private UserManager<ApplicationUser> _UserManager;
|
||||||
SettingsRepository _SettingsRepository;
|
SettingsRepository _SettingsRepository;
|
||||||
private IRateProviderFactory _RateProviderFactory;
|
private IRateProviderFactory _RateProviderFactory;
|
||||||
private CssThemeManager _CssThemeManager;
|
|
||||||
|
|
||||||
public ServerController(UserManager<ApplicationUser> userManager,
|
public ServerController(UserManager<ApplicationUser> userManager,
|
||||||
IRateProviderFactory rateProviderFactory,
|
IRateProviderFactory rateProviderFactory,
|
||||||
SettingsRepository settingsRepository,
|
SettingsRepository settingsRepository)
|
||||||
CssThemeManager cssThemeManager)
|
|
||||||
{
|
{
|
||||||
_UserManager = userManager;
|
_UserManager = userManager;
|
||||||
_SettingsRepository = settingsRepository;
|
_SettingsRepository = settingsRepository;
|
||||||
_RateProviderFactory = rateProviderFactory;
|
_RateProviderFactory = rateProviderFactory;
|
||||||
_CssThemeManager = cssThemeManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("server/rates")]
|
[Route("server/rates")]
|
||||||
@@ -234,9 +231,6 @@ namespace BTCPayServer.Controllers
|
|||||||
public async Task<IActionResult> Theme(ThemeSettings settings)
|
public async Task<IActionResult> Theme(ThemeSettings settings)
|
||||||
{
|
{
|
||||||
await _SettingsRepository.UpdateSetting(settings);
|
await _SettingsRepository.UpdateSetting(settings);
|
||||||
// TODO: remove controller/class-level property and have only reference to
|
|
||||||
// CssThemeManager here in this method
|
|
||||||
_CssThemeManager.Update(settings);
|
|
||||||
TempData["StatusMessage"] = "Theme settings updated successfully";
|
TempData["StatusMessage"] = "Theme settings updated successfully";
|
||||||
return View(settings);
|
return View(settings);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,47 +16,59 @@ namespace BTCPayServer.HostedServices
|
|||||||
{
|
{
|
||||||
public class CssThemeManager
|
public class CssThemeManager
|
||||||
{
|
{
|
||||||
public CssThemeManager(SettingsRepository settingsRepository)
|
|
||||||
{
|
|
||||||
Update(settingsRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void Update(SettingsRepository settingsRepository)
|
|
||||||
{
|
|
||||||
var data = (await settingsRepository.GetSettingAsync<ThemeSettings>()) ?? new ThemeSettings();
|
|
||||||
Update(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(ThemeSettings data)
|
public void Update(ThemeSettings data)
|
||||||
{
|
{
|
||||||
UpdateBootstrap(data.BootstrapCssUri);
|
if (String.IsNullOrWhiteSpace(data.BootstrapCssUri))
|
||||||
UpdateCreativeStart(data.CreativeStartCssUri);
|
_bootstrapUri = "/vendor/bootstrap4/css/bootstrap.css?v=" + DateTime.Now.Ticks;
|
||||||
|
else
|
||||||
|
_bootstrapUri = data.BootstrapCssUri;
|
||||||
|
|
||||||
|
|
||||||
|
if (String.IsNullOrWhiteSpace(data.CreativeStartCssUri))
|
||||||
|
_creativeStartUri = "/vendor/bootstrap4-creativestart/creative.css?v=" + DateTime.Now.Ticks;
|
||||||
|
else
|
||||||
|
_creativeStartUri = data.CreativeStartCssUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string _bootstrapUri = "/vendor/bootstrap4/css/bootstrap.css?v=" + DateTime.Now.Ticks;
|
private string _bootstrapUri;
|
||||||
public string BootstrapUri
|
public string BootstrapUri
|
||||||
{
|
{
|
||||||
get { return _bootstrapUri; }
|
get { return _bootstrapUri; }
|
||||||
}
|
}
|
||||||
public void UpdateBootstrap(string newUri)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrWhiteSpace(newUri))
|
|
||||||
_bootstrapUri = "/vendor/bootstrap4/css/bootstrap.css?v="+ DateTime.Now.Ticks;
|
|
||||||
else
|
|
||||||
_bootstrapUri = newUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string _creativeStartUri = "/vendor/bootstrap4-creativestart/creative.css?v=" + DateTime.Now.Ticks;
|
private string _creativeStartUri;
|
||||||
public string CreativeStartUri
|
public string CreativeStartUri
|
||||||
{
|
{
|
||||||
get { return _creativeStartUri; }
|
get { return _creativeStartUri; }
|
||||||
}
|
}
|
||||||
public void UpdateCreativeStart(string newUri)
|
}
|
||||||
|
|
||||||
|
public class CssThemeManagerHostedService : BaseAsyncService
|
||||||
{
|
{
|
||||||
if (String.IsNullOrWhiteSpace(newUri))
|
private SettingsRepository _SettingsRepository;
|
||||||
_creativeStartUri = "/vendor/bootstrap4-creativestart/creative.css?v=" + DateTime.Now.Ticks;
|
private CssThemeManager _CssThemeManager;
|
||||||
else
|
|
||||||
_creativeStartUri = newUri;
|
public CssThemeManagerHostedService(SettingsRepository settingsRepository, CssThemeManager cssThemeManager)
|
||||||
|
{
|
||||||
|
_SettingsRepository = settingsRepository;
|
||||||
|
_CssThemeManager = cssThemeManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override Task[] initializeTasks()
|
||||||
|
{
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
createLoopTask(ListenForThemeChanges)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task ListenForThemeChanges()
|
||||||
|
{
|
||||||
|
await new SynchronizationContextRemover();
|
||||||
|
var data = (await _SettingsRepository.GetSettingAsync<ThemeSettings>()) ?? new ThemeSettings();
|
||||||
|
_CssThemeManager.Update(data);
|
||||||
|
|
||||||
|
await _SettingsRepository.WaitSettingsChanged<ThemeSettings>(_Cts.Token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,6 @@ namespace BTCPayServer.Hosting
|
|||||||
|
|
||||||
services.TryAddSingleton<LanguageService>();
|
services.TryAddSingleton<LanguageService>();
|
||||||
services.TryAddSingleton<NBXplorerDashboard>();
|
services.TryAddSingleton<NBXplorerDashboard>();
|
||||||
services.TryAddSingleton<CssThemeManager>();
|
|
||||||
services.TryAddSingleton<StoreRepository>();
|
services.TryAddSingleton<StoreRepository>();
|
||||||
services.TryAddSingleton<BTCPayWalletProvider>();
|
services.TryAddSingleton<BTCPayWalletProvider>();
|
||||||
services.TryAddSingleton<CurrencyNameTable>();
|
services.TryAddSingleton<CurrencyNameTable>();
|
||||||
@@ -148,6 +147,9 @@ namespace BTCPayServer.Hosting
|
|||||||
BlockTarget = 20
|
BlockTarget = 20
|
||||||
});
|
});
|
||||||
|
|
||||||
|
services.AddSingleton<CssThemeManager>();
|
||||||
|
services.AddSingleton<IHostedService, CssThemeManagerHostedService>();
|
||||||
|
|
||||||
services.AddSingleton<Payments.IPaymentMethodHandler<DerivationStrategy>, Payments.Bitcoin.BitcoinLikePaymentHandler>();
|
services.AddSingleton<Payments.IPaymentMethodHandler<DerivationStrategy>, Payments.Bitcoin.BitcoinLikePaymentHandler>();
|
||||||
services.AddSingleton<IHostedService, Payments.Bitcoin.NBXplorerListener>();
|
services.AddSingleton<IHostedService, Payments.Bitcoin.NBXplorerListener>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user