2018-04-13 23:15:03 +02:00
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using BTCPayServer.Logging;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using NBXplorer;
|
|
|
|
|
using NBXplorer.Models;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using BTCPayServer.Events;
|
|
|
|
|
using BTCPayServer.Services;
|
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.HostedServices
|
|
|
|
|
{
|
|
|
|
|
public class CssThemeManager
|
|
|
|
|
{
|
2018-04-24 00:42:03 +02:00
|
|
|
|
public void Update(ThemeSettings data)
|
2018-04-13 23:15:03 +02:00
|
|
|
|
{
|
2018-04-24 00:42:03 +02:00
|
|
|
|
if (String.IsNullOrWhiteSpace(data.BootstrapCssUri))
|
|
|
|
|
_bootstrapUri = "/vendor/bootstrap4/css/bootstrap.css?v=" + DateTime.Now.Ticks;
|
|
|
|
|
else
|
|
|
|
|
_bootstrapUri = data.BootstrapCssUri;
|
2018-04-13 23:15:03 +02:00
|
|
|
|
|
|
|
|
|
|
2018-04-24 00:42:03 +02:00
|
|
|
|
if (String.IsNullOrWhiteSpace(data.CreativeStartCssUri))
|
|
|
|
|
_creativeStartUri = "/vendor/bootstrap4-creativestart/creative.css?v=" + DateTime.Now.Ticks;
|
|
|
|
|
else
|
|
|
|
|
_creativeStartUri = data.CreativeStartCssUri;
|
|
|
|
|
}
|
2018-04-18 00:24:00 +02:00
|
|
|
|
|
2018-04-24 00:42:03 +02:00
|
|
|
|
private string _bootstrapUri;
|
2018-04-18 00:24:00 +02:00
|
|
|
|
public string BootstrapUri
|
|
|
|
|
{
|
|
|
|
|
get { return _bootstrapUri; }
|
|
|
|
|
}
|
2018-04-13 23:15:03 +02:00
|
|
|
|
|
2018-04-24 00:42:03 +02:00
|
|
|
|
private string _creativeStartUri;
|
2018-04-18 00:24:00 +02:00
|
|
|
|
public string CreativeStartUri
|
|
|
|
|
{
|
|
|
|
|
get { return _creativeStartUri; }
|
|
|
|
|
}
|
2018-04-24 00:42:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CssThemeManagerHostedService : BaseAsyncService
|
|
|
|
|
{
|
|
|
|
|
private SettingsRepository _SettingsRepository;
|
|
|
|
|
private CssThemeManager _CssThemeManager;
|
|
|
|
|
|
|
|
|
|
public CssThemeManagerHostedService(SettingsRepository settingsRepository, CssThemeManager cssThemeManager)
|
2018-04-13 23:15:03 +02:00
|
|
|
|
{
|
2018-04-24 00:42:03 +02:00
|
|
|
|
_SettingsRepository = settingsRepository;
|
|
|
|
|
_CssThemeManager = cssThemeManager;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-27 04:52:04 +02:00
|
|
|
|
internal override Task[] InitializeTasks()
|
2018-04-24 00:42:03 +02:00
|
|
|
|
{
|
|
|
|
|
return new[]
|
|
|
|
|
{
|
2018-04-27 04:52:04 +02:00
|
|
|
|
CreateLoopTask(ListenForThemeChanges)
|
2018-04-24 00:42:03 +02:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task ListenForThemeChanges()
|
|
|
|
|
{
|
|
|
|
|
await new SynchronizationContextRemover();
|
|
|
|
|
var data = (await _SettingsRepository.GetSettingAsync<ThemeSettings>()) ?? new ThemeSettings();
|
|
|
|
|
_CssThemeManager.Update(data);
|
|
|
|
|
|
2018-04-27 04:52:04 +02:00
|
|
|
|
await _SettingsRepository.WaitSettingsChanged<ThemeSettings>(Cancellation);
|
2018-04-13 23:15:03 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|