b89223fa54
- 定位改为 水平(左/中/右) × 垂直(上/中/下) + 边缘留白,取代四角枚举 - 完成类通知在目标窗口已聚焦时用更短停留(FocusedDurationSeconds) - 托盘左键单击直接打开设置,右键菜单仅保留退出 - 修复 host 拉起用 UseShellExecute=true,脱离钩子 stdout 管道,避免 Claude 卡在 running stop hook
106 lines
2.9 KiB
C#
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,
|
|
});
|
|
}
|
|
}
|