feat(app): 初始化自动关机工具首个版本
实现基于 WPF 的 AutoShutdown 主界面,支持关机、重启、睡眠、休眠、唤醒、锁屏和注销等电源任务。 支持指定时间和倒计时计划、执行前提醒、系统关机撤销、Windows 唤醒任务、托盘运行、自定义图标以及 OmniNotify 通知适配。 修复关闭到托盘时的运行提醒,并支持单击托盘图标打开或收起主界面。 补充 README、发布配置和 win-x64 Release 输出要求。 Release: win-x64
This commit is contained in:
38
Services/NotificationSettingsStore.cs
Normal file
38
Services/NotificationSettingsStore.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user