cfb1b99162
- 常驻 Host:无主窗口保活 + 系统托盘菜单 - Toast 弹窗:堆叠 / 自动消失 / 悬停暂停 / 淡入淡出 / 点击关闭 - Sticky 常驻弹窗与 InputMode 边框配色 - 跨虚拟桌面显示(源生成 COM PinView,AOT 友好) - 设置窗口(Semi + Ursa)+ JSON 源生成持久化 - AOT 准备:IsAotCompatible 0 警告
90 lines
2.4 KiB
C#
90 lines
2.4 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;
|
|
Corner = s.Corner;
|
|
Opacity = s.Opacity;
|
|
MaxVisible = s.MaxVisible;
|
|
PlaySound = s.PlaySound;
|
|
Width = s.Width;
|
|
FadeMilliseconds = s.FadeMilliseconds;
|
|
ShowOnAllDesktops = s.ShowOnAllDesktops;
|
|
}
|
|
|
|
public IReadOnlyList<ToastCorner> Corners { get; } =
|
|
[ToastCorner.TopLeft, ToastCorner.TopRight, ToastCorner.BottomLeft, ToastCorner.BottomRight];
|
|
|
|
[ObservableProperty]
|
|
public partial int DurationSeconds { get; set; }
|
|
|
|
[ObservableProperty]
|
|
public partial ToastCorner Corner { 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,
|
|
Corner = Corner,
|
|
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,
|
|
});
|
|
}
|
|
}
|