添加项目文件。

This commit is contained in:
ShaoHua
2025-12-30 10:29:28 +08:00
parent 2989e660b3
commit 57cfd16e7b
21 changed files with 2348 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
using System;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
namespace TodoList.Services
{
public partial class AppSettings : ObservableObject
{
[ObservableProperty]
private string shortcutModifiers = "Control,Alt"; // Comma separated
[ObservableProperty]
private string shortcutKey = "A";
}
public class SettingsService
{
private readonly string _filePath;
public AppSettings Settings { get; private set; }
public SettingsService()
{
var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var folder = Path.Combine(appData, "TodoListApp");
Directory.CreateDirectory(folder);
_filePath = Path.Combine(folder, "settings.json");
Settings = LoadSettings();
}
private AppSettings LoadSettings()
{
if (!File.Exists(_filePath)) return new AppSettings();
try
{
var json = File.ReadAllText(_filePath);
return JsonSerializer.Deserialize<AppSettings>(json) ?? new AppSettings();
}
catch
{
return new AppSettings();
}
}
public void SaveSettings()
{
try
{
var json = JsonSerializer.Serialize(Settings, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(_filePath, json);
}
catch { }
}
}
}