Files
auto-shutdown/Services/NotificationSettingsStore.cs
home-PC d2d81a482b feat(app): 初始化自动关机工具首个版本
实现基于 WPF 的 AutoShutdown 主界面,支持关机、重启、睡眠、休眠、唤醒、锁屏和注销等电源任务。

支持指定时间和倒计时计划、执行前提醒、系统关机撤销、Windows 唤醒任务、托盘运行、自定义图标以及 OmniNotify 通知适配。

修复关闭到托盘时的运行提醒,并支持单击托盘图标打开或收起主界面。

补充 README、发布配置和 win-x64 Release 输出要求。

Release: win-x64
2026-05-18 23:54:58 +08:00

39 lines
1.1 KiB
C#

using System.IO;
using System.Text.Json;
using AutoShutdown.Models;
namespace AutoShutdown.Services;
internal sealed class NotificationSettingsStore
{
private readonly string _path = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"AutoShutdown",
"notification-settings.json");
public NotificationSettings Load()
{
try
{
if (!File.Exists(_path))
{
return NotificationSettings.Default();
}
var json = File.ReadAllText(_path);
return JsonSerializer.Deserialize<NotificationSettings>(json) ?? NotificationSettings.Default();
}
catch
{
return NotificationSettings.Default();
}
}
public void Save(NotificationSettings settings)
{
Directory.CreateDirectory(Path.GetDirectoryName(_path)!);
var json = JsonSerializer.Serialize(settings, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(_path, json);
}
}