using System.Collections.Generic; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Notify.Models; using Notify.Services; namespace Notify.ViewModels; public partial class SettingsViewModel : ObservableObject { private readonly SettingsService _settings; private readonly ToastManager _toasts; public SettingsViewModel(SettingsService settings, ToastManager toasts) { _settings = settings; _toasts = toasts; var s = settings.Current; DurationSeconds = s.DurationSeconds; FocusedDurationSeconds = s.FocusedDurationSeconds; Horizontal = s.Horizontal; Vertical = s.Vertical; Margin = s.Margin; Opacity = s.Opacity; MaxVisible = s.MaxVisible; PlaySound = s.PlaySound; Width = s.Width; FadeMilliseconds = s.FadeMilliseconds; ShowOnAllDesktops = s.ShowOnAllDesktops; } public IReadOnlyList Horizontals { get; } = [HEdge.Left, HEdge.Center, HEdge.Right]; public IReadOnlyList Verticals { get; } = [VEdge.Top, VEdge.Center, VEdge.Bottom]; [ObservableProperty] public partial int DurationSeconds { get; set; } [ObservableProperty] public partial int FocusedDurationSeconds { get; set; } [ObservableProperty] public partial HEdge Horizontal { get; set; } [ObservableProperty] public partial VEdge Vertical { get; set; } [ObservableProperty] public partial int Margin { get; set; } [ObservableProperty] public partial double Opacity { get; set; } [ObservableProperty] public partial int MaxVisible { get; set; } [ObservableProperty] public partial bool PlaySound { get; set; } [ObservableProperty] public partial double Width { get; set; } [ObservableProperty] public partial int FadeMilliseconds { get; set; } [ObservableProperty] public partial bool ShowOnAllDesktops { get; set; } [ObservableProperty] public partial string StatusText { get; set; } = string.Empty; [RelayCommand] private void Save() { _settings.Save(new ToastSettings { DurationSeconds = DurationSeconds, FocusedDurationSeconds = FocusedDurationSeconds, Horizontal = Horizontal, Vertical = Vertical, Margin = Margin, Opacity = Opacity, MaxVisible = MaxVisible, PlaySound = PlaySound, Width = Width, FadeMilliseconds = FadeMilliseconds, ShowOnAllDesktops = ShowOnAllDesktops, }); StatusText = "已保存"; } [RelayCommand] private void TestToast() { // 用当前编辑中的值预览(先保存再弹,所见即所得) Save(); _toasts.Show(new ToastRequest { Title = "预览弹窗", Message = "这是一条测试通知 — 点击可关闭", InputMode = false, }); } }