f4cc81bb71
- Add theme system (Dark/Light palettes, ModernTheme, ThemeManager) - Add InputDialog, Spinner common view - Add DuplicatesCsvExportService - Refresh views, dialogs, and view models across tabs - Update localization strings (en/fr) - Tweak services (transfer, permissions, search, user access, ownership elevation, bulk operations) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using SharepointToolbox.Core.Models;
|
|
using SharepointToolbox.Infrastructure.Persistence;
|
|
|
|
namespace SharepointToolbox.Services;
|
|
|
|
public class SettingsService
|
|
{
|
|
private readonly SettingsRepository _repository;
|
|
|
|
private static readonly HashSet<string> SupportedLanguages = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
"en", "fr"
|
|
};
|
|
|
|
public SettingsService(SettingsRepository repository)
|
|
{
|
|
_repository = repository;
|
|
}
|
|
|
|
public Task<AppSettings> GetSettingsAsync()
|
|
=> _repository.LoadAsync();
|
|
|
|
public async Task SetLanguageAsync(string cultureCode)
|
|
{
|
|
if (!SupportedLanguages.Contains(cultureCode))
|
|
throw new ArgumentException($"Unsupported language code '{cultureCode}'. Supported: en, fr.", nameof(cultureCode));
|
|
|
|
var settings = await _repository.LoadAsync();
|
|
settings.Lang = cultureCode;
|
|
await _repository.SaveAsync(settings);
|
|
}
|
|
|
|
public async Task SetDataFolderAsync(string path)
|
|
{
|
|
var settings = await _repository.LoadAsync();
|
|
settings.DataFolder = path;
|
|
await _repository.SaveAsync(settings);
|
|
}
|
|
|
|
public async Task SetAutoTakeOwnershipAsync(bool enabled)
|
|
{
|
|
var settings = await _repository.LoadAsync();
|
|
settings.AutoTakeOwnership = enabled;
|
|
await _repository.SaveAsync(settings);
|
|
}
|
|
|
|
public async Task SetThemeAsync(string mode)
|
|
{
|
|
if (mode is not ("System" or "Light" or "Dark"))
|
|
throw new ArgumentException($"Unsupported theme '{mode}'. Supported: System, Light, Dark.", nameof(mode));
|
|
|
|
var settings = await _repository.LoadAsync();
|
|
settings.Theme = mode;
|
|
await _repository.SaveAsync(settings);
|
|
}
|
|
}
|