Repository navigation
Expand file tree
/
Copy pathAppSettings.cs
More file actions
186 lines (148 loc) · 6.5 KB
/
Copy pathAppSettings.cs
File metadata and controls
186 lines (148 loc) · 6.5 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using Windows.Storage;
namespace Caffeinated.Helpers {
public class AppSettings {
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
private bool _activateOnLaunch;
public bool ActivateOnLaunch {
get { return _activateOnLaunch; }
set {
_activateOnLaunch = value;
localSettings.Values[nameof(ActivateOnLaunch)] = _activateOnLaunch.ToString();
}
}
private bool _isFirstLaunch;
public bool IsFirstLaunch
{
get { return _isFirstLaunch; }
set {
_isFirstLaunch = value;
localSettings.Values[nameof(IsFirstLaunch)] = _isFirstLaunch.ToString();
}
}
private bool _automaticallyLaunchWithWindows;
public bool AutomaticallyLaunchWithWindows {
get { return _automaticallyLaunchWithWindows; }
set {
_automaticallyLaunchWithWindows = value;
localSettings.Values[nameof(AutomaticallyLaunchWithWindows)] = _automaticallyLaunchWithWindows.ToString();
}
}
private bool _showMessageOnLaunch;
public bool ShowMessageOnLaunch {
get { return _showMessageOnLaunch; }
set {
_showMessageOnLaunch = value;
localSettings.Values[nameof(ShowMessageOnLaunch)] = _showMessageOnLaunch.ToString();
}
}
private int _defaultDuration;
public int DefaultDuration {
get { return _defaultDuration; }
set {
_defaultDuration = value;
localSettings.Values[nameof(DefaultDuration)] = _defaultDuration.ToString();
}
}
private TrayIcon _icon;
public TrayIcon Icon {
get { return _icon; }
set {
_icon = value;
localSettings.Values[nameof(Icon)] = _icon.ToString();
}
}
private TooltipFormat _tooltipFormat;
public TooltipFormat TooltipFormat {
get { return _tooltipFormat; }
set {
_tooltipFormat = value;
localSettings.Values[nameof(TooltipFormat)] = _tooltipFormat.ToString();
}
}
private bool _keepMonitorOn = true;
public bool KeepMonitorOn {
get { return _keepMonitorOn; }
set {
_keepMonitorOn = value;
localSettings.Values[nameof(KeepMonitorOn)] = _keepMonitorOn.ToString();
}
}
private bool _processWatchEnabled;
public bool ProcessWatchEnabled {
get { return _processWatchEnabled; }
set {
_processWatchEnabled = value;
localSettings.Values[nameof(ProcessWatchEnabled)] = _processWatchEnabled.ToString();
}
}
private List<string> _watchedProcessNames = [];
/// <summary>
/// Process names to watch (case-sensitive, without .exe extension).
/// </summary>
public List<string> WatchedProcessNames {
get { return _watchedProcessNames; }
set {
_watchedProcessNames = value ?? [];
localSettings.Values[nameof(WatchedProcessNames)] = string.Join("|", _watchedProcessNames);
}
}
private ObservableCollection<int> _durations;
public ObservableCollection<int> Durations {
get { return _durations; }
set {
_durations = value;
localSettings.Values[nameof(Durations)] = string.Join(',',Durations.ToArray());
}
}
public AppSettings() {
string ActivateOnLaunchSetting = (string)localSettings.Values[nameof(ActivateOnLaunch)];
ActivateOnLaunchSetting ??= "false";
_activateOnLaunch = bool.Parse(ActivateOnLaunchSetting);
string IsFirstLaunchSetting = (string)localSettings.Values[nameof(IsFirstLaunch)];
IsFirstLaunchSetting ??= "true";
_isFirstLaunch = bool.Parse(IsFirstLaunchSetting);
string AutomaticallyLaunchWithWindowsSetting = (string)localSettings.Values[nameof(AutomaticallyLaunchWithWindows)];
AutomaticallyLaunchWithWindowsSetting ??= "false";
_automaticallyLaunchWithWindows = bool.Parse(AutomaticallyLaunchWithWindowsSetting);
string ShowMessageOnLaunchSetting = (string)localSettings.Values[nameof(ShowMessageOnLaunch)];
ShowMessageOnLaunchSetting ??= "false";
_showMessageOnLaunch = bool.Parse(ShowMessageOnLaunchSetting);
string DefaultDurationSetting = (string)localSettings.Values[nameof(DefaultDuration)];
DefaultDurationSetting ??= "480";
_defaultDuration = int.Parse(DefaultDurationSetting);
string IconSetting = (string)localSettings.Values[nameof(Icon)];
IconSetting ??= "Mug";
_icon = IconSetting switch
{
"Mug" => TrayIcon.Mug,
"EyeWithZzz" => TrayIcon.EyeWithZzz,
_ => TrayIcon.Default,
};
string TooltipFormatSetting = (string)localSettings.Values[nameof(TooltipFormat)];
TooltipFormatSetting ??= "General";
_tooltipFormat = TooltipFormatSetting switch
{
"Specific" => TooltipFormat.Specific,
_ => TooltipFormat.General,
};
string KeepMonitorOnSetting = (string)localSettings.Values[nameof(KeepMonitorOn)];
KeepMonitorOnSetting ??= "true";
_keepMonitorOn = bool.Parse(KeepMonitorOnSetting);
string DurationsSetting = (string)localSettings.Values[nameof(Durations)];
DurationsSetting ??= "0,15,60,120,480";
List<string> splitResult = DurationsSetting.Split(',').ToList();
_durations = [];
foreach (string item in splitResult) {
_durations.Add(int.Parse(item));
}
Durations.CollectionChanged += Durations_CollectionChanged;
}
private void Durations_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) {
localSettings.Values[nameof(Durations)] = string.Join(',', Durations.ToArray());
}
}
}