-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppSettings.cs
More file actions
71 lines (63 loc) · 2.28 KB
/
Copy pathAppSettings.cs
File metadata and controls
71 lines (63 loc) · 2.28 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using MDConvertLib;
namespace MarkdownThing
{
public class AppSettings
{
public bool HasSeenWelcome { get; set; }
public PreviewTheme PreviewTheme { get; set; } = PreviewTheme.Default;
public bool DarkPreview { get; set; }
public bool DarkEditor { get; set; }
public string PdfPaper { get; set; } = "A4";
public int PdfMarginTopMm { get; set; } = 20;
public int PdfMarginBottomMm { get; set; } = 20;
public int PdfMarginLeftMm { get; set; } = 15;
public int PdfMarginRightMm { get; set; } = 15;
public int? WindowWidth { get; set; }
public int? WindowHeight { get; set; }
public int? WindowX { get; set; }
public int? WindowY { get; set; }
public bool WindowMaximized { get; set; }
public int SplitterDistance { get; set; } = 450;
public bool WordWrap { get; set; }
public double PreviewZoom { get; set; } = 1.0;
public static AppSettings Load()
{
AppDataPaths.MigrateLegacyData();
try
{
if (File.Exists(AppDataPaths.SettingsFile))
{
var json = File.ReadAllText(AppDataPaths.SettingsFile);
return System.Text.Json.JsonSerializer.Deserialize<AppSettings>(json) ?? new AppSettings();
}
}
catch
{
// use defaults
}
return new AppSettings();
}
public void Save()
{
try
{
Directory.CreateDirectory(AppDataPaths.AppFolder);
var json = System.Text.Json.JsonSerializer.Serialize(this,
new System.Text.Json.JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(AppDataPaths.SettingsFile, json);
}
catch
{
// non-fatal
}
}
public PdfExportOptions ToPdfOptions() => new()
{
PaperFormat = PdfExportOptions.ParsePaper(PdfPaper),
MarginTop = $"{PdfMarginTopMm}mm",
MarginBottom = $"{PdfMarginBottomMm}mm",
MarginLeft = $"{PdfMarginLeftMm}mm",
MarginRight = $"{PdfMarginRightMm}mm"
};
}
}