cfb1b99162
- 常驻 Host:无主窗口保活 + 系统托盘菜单 - Toast 弹窗:堆叠 / 自动消失 / 悬停暂停 / 淡入淡出 / 点击关闭 - Sticky 常驻弹窗与 InputMode 边框配色 - 跨虚拟桌面显示(源生成 COM PinView,AOT 友好) - 设置窗口(Semi + Ursa)+ JSON 源生成持久化 - AOT 准备:IsAotCompatible 0 警告
64 lines
1.6 KiB
C#
64 lines
1.6 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
using Notify.Models;
|
|
using Notify.Serialization;
|
|
|
|
namespace Notify.Services;
|
|
|
|
/// <summary>
|
|
/// 加载/保存弹窗设置,并在变更时通知订阅者
|
|
/// </summary>
|
|
public sealed class SettingsService
|
|
{
|
|
private static readonly string Dir =
|
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ClaudeCodeNotify");
|
|
|
|
private static readonly string FilePath = Path.Combine(Dir, "settings.json");
|
|
|
|
public ToastSettings Current { get; private set; } = new();
|
|
|
|
/// <summary>
|
|
/// 设置被保存后触发
|
|
/// </summary>
|
|
public event Action<ToastSettings>? Changed;
|
|
|
|
public void Load()
|
|
{
|
|
try
|
|
{
|
|
if (File.Exists(FilePath))
|
|
{
|
|
var json = File.ReadAllText(FilePath);
|
|
var loaded = JsonSerializer.Deserialize(json, AppJsonContext.Default.ToastSettings);
|
|
if (loaded is not null)
|
|
{
|
|
Current = loaded;
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// 配置损坏则回退到默认值,不影响保活
|
|
Current = new ToastSettings();
|
|
}
|
|
}
|
|
|
|
public void Save(ToastSettings settings)
|
|
{
|
|
Current = settings;
|
|
try
|
|
{
|
|
Directory.CreateDirectory(Dir);
|
|
var json = JsonSerializer.Serialize(settings, AppJsonContext.Default.ToastSettings);
|
|
File.WriteAllText(FilePath, json);
|
|
}
|
|
catch
|
|
{
|
|
// 落盘失败不致命,内存里仍生效
|
|
}
|
|
|
|
Changed?.Invoke(Current);
|
|
}
|
|
}
|