Files
notify/Notify/ViewModels/SettingsViewModel.cs
chuan 5ce2c8a982 feat: Claude Code 原生 Windows 通知(C# / .NET 10 + Avalonia 12)
为 Claude Code 提供原生 Windows toast 通知:点击跳回原窗口、切回 Windows
Terminal 标签、跨虚拟桌面、调用方图标、非阻塞投递;NativeAOT 单文件分发。
2026-06-22 18:05:15 +08:00

106 lines
2.9 KiB
C#

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<HEdge> Horizontals { get; } = [HEdge.Left, HEdge.Center, HEdge.Right];
public IReadOnlyList<VEdge> 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,
});
}
}