diff --git a/Server/Components/Devices/DeviceCard.razor.cs b/Server/Components/Devices/DeviceCard.razor.cs
index e11b2eb24..b5851e2b0 100644
--- a/Server/Components/Devices/DeviceCard.razor.cs
+++ b/Server/Components/Devices/DeviceCard.razor.cs
@@ -36,6 +36,9 @@ public partial class DeviceCard : AuthComponentBase, IDisposable
[Inject]
private IClientAppState AppState { get; init; } = null!;
+ [Inject]
+ private IThemeProvider ThemeProvider { get; init; } = null!;
+
[Inject]
private ICircuitConnection CircuitConnection { get; init; } = null!;
@@ -79,7 +82,7 @@ protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
EnsureUserSet();
- _theme = await AppState.GetEffectiveTheme();
+ _theme = await ThemeProvider.GetEffectiveTheme();
_currentVersion = UpgradeService.GetCurrentVersion();
_deviceGroups = DataService.GetDeviceGroups(UserName);
AppState.PropertyChanged += AppState_PropertyChanged;
diff --git a/Server/Components/LoadingSignal.razor b/Server/Components/LoadingSignal.razor
index a05168c18..0466046bf 100644
--- a/Server/Components/LoadingSignal.razor
+++ b/Server/Components/LoadingSignal.razor
@@ -1,4 +1,4 @@
-@inject IClientAppState AppState
+@inject IThemeProvider ThemeProvider
@@ -20,7 +20,7 @@
protected override async Task OnInitializedAsync()
{
- _theme = await AppState.GetEffectiveTheme();
+ _theme = await ThemeProvider.GetEffectiveTheme();
await base.OnInitializedAsync();
}
diff --git a/Server/Program.cs b/Server/Program.cs
index 706771988..a6a5d245f 100644
--- a/Server/Program.cs
+++ b/Server/Program.cs
@@ -210,6 +210,7 @@
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+services.AddSingleton();
services.AddSingleton(WeakReferenceMessenger.Default);
services.AddRemoteControlServer(config =>
diff --git a/Server/Services/ClientAppState.cs b/Server/Services/ClientAppState.cs
index 3f6272f48..069fc7372 100644
--- a/Server/Services/ClientAppState.cs
+++ b/Server/Services/ClientAppState.cs
@@ -21,25 +21,14 @@ public interface IClientAppState : INotifyPropertyChanged, IInvokePropertyChange
void AddTerminalLine(string content, string className = "", string title = "");
- Task GetEffectiveTheme();
string GetTerminalHistory(bool forward);
}
public class ClientAppState : ViewModelBase, IClientAppState
{
- private readonly IApplicationConfig _appConfig;
- private readonly IAuthService _authService;
private readonly ConcurrentQueue _terminalHistory = new();
private int _terminalHistoryIndex = 0;
- public ClientAppState(
- IAuthService authService,
- IApplicationConfig appConfig)
- {
- _authService = authService;
- _appConfig = appConfig;
- }
-
public ConcurrentList DevicesFrameChatSessions { get; } = new();
public DeviceCardState DevicesFrameFocusedCardState
@@ -84,20 +73,6 @@ public void AddTerminalLine(string content, string className = "", string title
});
}
- public async Task GetEffectiveTheme()
- {
- if (await _authService.IsAuthenticated())
- {
- var userResult = await _authService.GetUser();
- if (userResult.IsSuccess)
- {
- return userResult.Value.UserOptions?.Theme ?? _appConfig.Theme;
- }
- }
-
- return _appConfig.Theme;
- }
-
public string GetTerminalHistory(bool forward)
{
if (!_terminalHistory.Any())
diff --git a/Server/Services/ThemeProvider.cs b/Server/Services/ThemeProvider.cs
new file mode 100644
index 000000000..3e9106197
--- /dev/null
+++ b/Server/Services/ThemeProvider.cs
@@ -0,0 +1,36 @@
+using Microsoft.Identity.Client;
+using Remotely.Shared.Enums;
+using System.Threading.Tasks;
+
+namespace Remotely.Server.Services;
+
+public interface IThemeProvider
+{
+ Task GetEffectiveTheme();
+}
+
+public class ThemeProvider : IThemeProvider
+{
+ private readonly IAuthService _authService;
+ private readonly IApplicationConfig _appConfig;
+
+ public ThemeProvider(IAuthService authService, IApplicationConfig appConfig)
+ {
+ _authService = authService;
+ _appConfig = appConfig;
+ }
+
+ public async Task GetEffectiveTheme()
+ {
+ if (await _authService.IsAuthenticated())
+ {
+ var userResult = await _authService.GetUser();
+ if (userResult.IsSuccess)
+ {
+ return userResult.Value.UserOptions?.Theme ?? _appConfig.Theme;
+ }
+ }
+
+ return _appConfig.Theme;
+ }
+}