mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-22 00:54:26 +08:00
settings_re7
This commit is contained in:
@@ -412,6 +412,19 @@ public sealed partial class AppearanceSettingsPageViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string _themeColor = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private Color _themeColorPickerValue;
|
||||
|
||||
partial void OnThemeColorPickerValueChanged(Color value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ThemeColor = value.ToString();
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _useSystemChrome;
|
||||
|
||||
@@ -474,6 +487,14 @@ public sealed partial class AppearanceSettingsPageViewModel : ViewModelBase
|
||||
var theme = _settingsFacade.Theme.Get();
|
||||
IsNightMode = theme.IsNightMode;
|
||||
ThemeColor = theme.ThemeColor ?? string.Empty;
|
||||
if (Color.TryParse(ThemeColor, out var color))
|
||||
{
|
||||
ThemeColorPickerValue = color;
|
||||
}
|
||||
else
|
||||
{
|
||||
ThemeColorPickerValue = Color.Parse("#FF3B82F6");
|
||||
}
|
||||
UseSystemChrome = theme.UseSystemChrome;
|
||||
|
||||
var wallpaper = _settingsFacade.Wallpaper.Get();
|
||||
@@ -588,8 +609,11 @@ public sealed partial class AppearanceSettingsPageViewModel : ViewModelBase
|
||||
|
||||
private void SaveWallpaper()
|
||||
{
|
||||
var current = _settingsFacade.Wallpaper.Get();
|
||||
_settingsFacade.Wallpaper.Save(new WallpaperSettingsState(
|
||||
string.IsNullOrWhiteSpace(WallpaperPath) ? null : WallpaperPath,
|
||||
current.Type,
|
||||
current.Color,
|
||||
SelectedWallpaperPlacement.Value));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using LanMountainDesktop.Services;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
|
||||
@@ -19,6 +24,8 @@ public sealed partial class WallpaperSettingsPageViewModel : ViewModelBase
|
||||
_settingsFacade = settingsFacade;
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(_settingsFacade.Region.Get().LanguageCode);
|
||||
WallpaperPlacements = CreateWallpaperPlacements();
|
||||
WallpaperTypes = CreateWallpaperTypes();
|
||||
PresetColors = CreatePresetColors();
|
||||
RefreshLocalizedText();
|
||||
|
||||
_isInitializing = true;
|
||||
@@ -27,41 +34,90 @@ public sealed partial class WallpaperSettingsPageViewModel : ViewModelBase
|
||||
}
|
||||
|
||||
public IReadOnlyList<SelectionOption> WallpaperPlacements { get; }
|
||||
public IReadOnlyList<SelectionOption> WallpaperTypes { get; }
|
||||
public IReadOnlyList<string> PresetColors { get; }
|
||||
|
||||
[CommunityToolkit.Mvvm.ComponentModel.ObservableProperty]
|
||||
[ObservableProperty]
|
||||
private string _wallpaperPath = string.Empty;
|
||||
|
||||
[CommunityToolkit.Mvvm.ComponentModel.ObservableProperty]
|
||||
private SelectionOption _selectedWallpaperPlacement = new("Fill", "Fill");
|
||||
[ObservableProperty]
|
||||
private SelectionOption _selectedWallpaperType = null!;
|
||||
|
||||
[CommunityToolkit.Mvvm.ComponentModel.ObservableProperty]
|
||||
[ObservableProperty]
|
||||
private string? _selectedColor;
|
||||
|
||||
[ObservableProperty]
|
||||
private SelectionOption _selectedWallpaperPlacement = null!;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _wallpaperHeader = string.Empty;
|
||||
|
||||
[CommunityToolkit.Mvvm.ComponentModel.ObservableProperty]
|
||||
[ObservableProperty]
|
||||
private string _wallpaperTypeLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _wallpaperPathLabel = string.Empty;
|
||||
|
||||
[CommunityToolkit.Mvvm.ComponentModel.ObservableProperty]
|
||||
[ObservableProperty]
|
||||
private string _wallpaperColorLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _wallpaperPlacementLabel = string.Empty;
|
||||
|
||||
[CommunityToolkit.Mvvm.ComponentModel.ObservableProperty]
|
||||
[ObservableProperty]
|
||||
private string _wallpaperPlacementDescription = string.Empty;
|
||||
|
||||
[CommunityToolkit.Mvvm.ComponentModel.ObservableProperty]
|
||||
[ObservableProperty]
|
||||
private string _importWallpaperButtonText = string.Empty;
|
||||
|
||||
[CommunityToolkit.Mvvm.ComponentModel.ObservableProperty]
|
||||
[ObservableProperty]
|
||||
private string _filePickerTitle = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isImageOrVideo;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isSolidColor;
|
||||
|
||||
[ObservableProperty]
|
||||
private Bitmap? _previewImage;
|
||||
|
||||
public void Load()
|
||||
{
|
||||
var wallpaper = _settingsFacade.Wallpaper.Get();
|
||||
WallpaperPath = wallpaper.WallpaperPath ?? string.Empty;
|
||||
|
||||
SelectedWallpaperType = WallpaperTypes.FirstOrDefault(t => t.Value == wallpaper.Type) ?? WallpaperTypes[0];
|
||||
SelectedColor = wallpaper.Color ?? PresetColors[0];
|
||||
|
||||
var wallpaperPlacement = string.IsNullOrWhiteSpace(wallpaper.Placement)
|
||||
? "Fill"
|
||||
: wallpaper.Placement;
|
||||
SelectedWallpaperPlacement = WallpaperPlacements.FirstOrDefault(option =>
|
||||
string.Equals(option.Value, wallpaperPlacement, StringComparison.OrdinalIgnoreCase))
|
||||
?? WallpaperPlacements[0];
|
||||
|
||||
UpdateVisibility();
|
||||
UpdatePreviewImage(WallpaperPath);
|
||||
}
|
||||
|
||||
partial void OnSelectedWallpaperTypeChanged(SelectionOption value)
|
||||
{
|
||||
UpdateVisibility();
|
||||
if (_isInitializing) return;
|
||||
SaveWallpaper();
|
||||
}
|
||||
|
||||
private void UpdateVisibility()
|
||||
{
|
||||
IsImageOrVideo = SelectedWallpaperType?.Value is "Image" or "Video";
|
||||
IsSolidColor = SelectedWallpaperType?.Value == "SolidColor";
|
||||
}
|
||||
|
||||
partial void OnSelectedColorChanged(string? value)
|
||||
{
|
||||
if (_isInitializing) return;
|
||||
SaveWallpaper();
|
||||
}
|
||||
|
||||
public async Task ImportWallpaperAsync(string sourcePath)
|
||||
@@ -75,28 +131,48 @@ public sealed partial class WallpaperSettingsPageViewModel : ViewModelBase
|
||||
|
||||
partial void OnWallpaperPathChanged(string value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
UpdatePreviewImage(value);
|
||||
if (_isInitializing) return;
|
||||
SaveWallpaper();
|
||||
}
|
||||
|
||||
private void UpdatePreviewImage(string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path) || !System.IO.File.Exists(path))
|
||||
{
|
||||
PreviewImage = null;
|
||||
return;
|
||||
}
|
||||
|
||||
SaveWallpaper();
|
||||
try
|
||||
{
|
||||
using var stream = System.IO.File.OpenRead(path);
|
||||
PreviewImage = new Bitmap(stream);
|
||||
}
|
||||
catch
|
||||
{
|
||||
PreviewImage = null;
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnSelectedWallpaperPlacementChanged(SelectionOption value)
|
||||
{
|
||||
if (_isInitializing || value is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isInitializing || value is null) return;
|
||||
SaveWallpaper();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void SelectColor(string color)
|
||||
{
|
||||
SelectedColor = color;
|
||||
}
|
||||
|
||||
private void SaveWallpaper()
|
||||
{
|
||||
_settingsFacade.Wallpaper.Save(new WallpaperSettingsState(
|
||||
string.IsNullOrWhiteSpace(WallpaperPath) ? null : WallpaperPath,
|
||||
SelectedWallpaperType.Value,
|
||||
SelectedColor,
|
||||
SelectedWallpaperPlacement.Value));
|
||||
}
|
||||
|
||||
@@ -112,10 +188,32 @@ public sealed partial class WallpaperSettingsPageViewModel : ViewModelBase
|
||||
];
|
||||
}
|
||||
|
||||
private IReadOnlyList<SelectionOption> CreateWallpaperTypes()
|
||||
{
|
||||
return
|
||||
[
|
||||
new SelectionOption("Image", L("settings.wallpaper.type.image", "Image")),
|
||||
new SelectionOption("Video", L("settings.wallpaper.type.video", "Video")),
|
||||
new SelectionOption("SolidColor", L("settings.wallpaper.type.solid_color", "Solid Color"))
|
||||
];
|
||||
}
|
||||
|
||||
private IReadOnlyList<string> CreatePresetColors()
|
||||
{
|
||||
return
|
||||
[
|
||||
"#D8A7B1", "#B6C9BB", "#A2B5BB", "#E6E2D3",
|
||||
"#B5A397", "#C5C1C0", "#D4BE8D", "#C08261",
|
||||
"#8E9775", "#9FBAD3", "#E5BAA2", "#4E596F"
|
||||
];
|
||||
}
|
||||
|
||||
private void RefreshLocalizedText()
|
||||
{
|
||||
WallpaperHeader = L("settings.wallpaper.title", "Wallpaper");
|
||||
WallpaperTypeLabel = L("settings.wallpaper.type_label", "Wallpaper Type");
|
||||
WallpaperPathLabel = L("settings.wallpaper.current_label", "Current Wallpaper");
|
||||
WallpaperColorLabel = L("settings.wallpaper.color_label", "Wallpaper Color");
|
||||
WallpaperPlacementLabel = L("settings.wallpaper.placement_label", "Placement");
|
||||
WallpaperPlacementDescription = L("settings.wallpaper.placement_desc", "Adjust how the image fills the desktop.");
|
||||
ImportWallpaperButtonText = L("settings.wallpaper.pick_button", "Import Wallpaper");
|
||||
|
||||
Reference in New Issue
Block a user