- Introduced AppThemeMode enum to define theme options: System, Light, Dark. - Updated AppSettingsDocument to include ThemeMode property. - Created AppThemeState service to manage current theme mode and handle changes. - Integrated theme mode handling in CouchbaseLiteAppSettingsService for persistence. - Added JavaScript for theme management in the frontend, supporting system preference detection. - Enhanced CSS with theme variables for consistent styling across light and dark modes. - Updated Playwright tests to ensure sidebar functionality and responsiveness.
41 lines
No EOL
1.1 KiB
C#
41 lines
No EOL
1.1 KiB
C#
using WorkTracker.Domain;
|
|
|
|
namespace WorkTracker.Services.Settings;
|
|
|
|
public sealed class AppThemeState
|
|
{
|
|
private readonly IAppSettingsService appSettingsService;
|
|
private AppThemeMode? currentThemeMode;
|
|
|
|
public AppThemeState(IAppSettingsService appSettingsService)
|
|
{
|
|
this.appSettingsService = appSettingsService;
|
|
}
|
|
|
|
public event Action<AppThemeMode>? ThemeModeChanged;
|
|
|
|
public AppThemeMode CurrentThemeMode => currentThemeMode ?? AppThemeMode.System;
|
|
|
|
public async Task<AppThemeMode> EnsureLoadedAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
if (currentThemeMode.HasValue)
|
|
{
|
|
return currentThemeMode.Value;
|
|
}
|
|
|
|
var settings = await appSettingsService.GetAsync(cancellationToken);
|
|
currentThemeMode = settings.ThemeMode;
|
|
return CurrentThemeMode;
|
|
}
|
|
|
|
public void SetThemeMode(AppThemeMode themeMode)
|
|
{
|
|
if (currentThemeMode == themeMode)
|
|
{
|
|
return;
|
|
}
|
|
|
|
currentThemeMode = themeMode;
|
|
ThemeModeChanged?.Invoke(themeMode);
|
|
}
|
|
} |