-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cs
More file actions
48 lines (41 loc) · 1.32 KB
/
Config.cs
File metadata and controls
48 lines (41 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Text.Json;
namespace MonitorWindowsRestore;
public class Config
{
public List<string> Programs { get; set; } = [];
public int DebounceDelayMs { get; set; } = 500;
public int RestoreDelayMs { get; set; } = 1000;
public int RequiredMonitorCount { get; set; } = 2;
private static readonly string ConfigPath = Path.Combine(
AppContext.BaseDirectory, "config.json");
private static readonly JsonSerializerOptions JsonOptions = new()
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
public static Config Load()
{
if (!File.Exists(ConfigPath))
{
var defaultConfig = new Config
{
Programs =
[
"chrome.exe",
"zen.exe",
"Obsidian.exe",
"thunderbird.exe"
]
};
defaultConfig.Save();
return defaultConfig;
}
var json = File.ReadAllText(ConfigPath);
return JsonSerializer.Deserialize<Config>(json, JsonOptions) ?? new Config();
}
public void Save()
{
var json = JsonSerializer.Serialize(this, JsonOptions);
File.WriteAllText(ConfigPath, json);
}
}