add: 久坐提醒项目文件
This commit is contained in:
46
AppSettings.cs
Normal file
46
AppSettings.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace TimerApp
|
||||
{
|
||||
public class AppSettings
|
||||
{
|
||||
public int WorkMinutes { get; set; } = 20;
|
||||
public int RestMinutes { get; set; } = 1;
|
||||
public int IdleThresholdSeconds { get; set; } = 30;
|
||||
public bool IsDarkMode { get; set; } = true;
|
||||
|
||||
private static string ConfigPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.json");
|
||||
|
||||
public static AppSettings Load()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(ConfigPath))
|
||||
{
|
||||
string json = File.ReadAllText(ConfigPath);
|
||||
return JsonSerializer.Deserialize<AppSettings>(json);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore errors, return default
|
||||
}
|
||||
return new AppSettings();
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
try
|
||||
{
|
||||
string json = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(ConfigPath, json);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user