-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReminderSettingsWindow.xaml.cs
More file actions
470 lines (419 loc) · 17.3 KB
/
ReminderSettingsWindow.xaml.cs
File metadata and controls
470 lines (419 loc) · 17.3 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
using System;
using System.ComponentModel;
using System.Configuration;
using System.Windows;
namespace TimeTask
{
public partial class ReminderSettingsWindow : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private int _firstWarningAfterDays;
private int _secondWarningAfterDays;
private int _staleTaskThresholdDays;
private int _maxInactiveWarnings;
private int _reminderCheckIntervalMinutes;
private string _metricsWindowLabel = string.Empty;
private string _suggestionHitRateText = "0.0%";
private string _interruptionIndexText = "0.0%";
private string _topEffectiveActionText = "N/A";
private string _suggestionOutcomeText = string.Empty;
private string _recommendedStuckThresholdText = string.Empty;
private string _recommendedDailyNudgeLimitText = string.Empty;
private bool _proactiveAssistEnabled = true;
private bool _behaviorLearningEnabled = true;
private bool _stuckNudgesEnabled = true;
private bool _llmSkillAssistEnabled = true;
private int _quietHoursStart = 22;
private int _quietHoursEnd = 8;
public int FirstWarningAfterDays
{
get => _firstWarningAfterDays;
set
{
_firstWarningAfterDays = value;
OnPropertyChanged(nameof(FirstWarningAfterDays));
}
}
public int SecondWarningAfterDays
{
get => _secondWarningAfterDays;
set
{
_secondWarningAfterDays = value;
OnPropertyChanged(nameof(SecondWarningAfterDays));
}
}
public int StaleTaskThresholdDays
{
get => _staleTaskThresholdDays;
set
{
_staleTaskThresholdDays = value;
OnPropertyChanged(nameof(StaleTaskThresholdDays));
}
}
public int MaxInactiveWarnings
{
get => _maxInactiveWarnings;
set
{
_maxInactiveWarnings = value;
OnPropertyChanged(nameof(MaxInactiveWarnings));
}
}
public int ReminderCheckIntervalMinutes
{
get => _reminderCheckIntervalMinutes;
set
{
_reminderCheckIntervalMinutes = value;
OnPropertyChanged(nameof(ReminderCheckIntervalMinutes));
}
}
public string MetricsWindowLabel
{
get => _metricsWindowLabel;
set
{
_metricsWindowLabel = value;
OnPropertyChanged(nameof(MetricsWindowLabel));
}
}
public string SuggestionHitRateText
{
get => _suggestionHitRateText;
set
{
_suggestionHitRateText = value;
OnPropertyChanged(nameof(SuggestionHitRateText));
}
}
public string InterruptionIndexText
{
get => _interruptionIndexText;
set
{
_interruptionIndexText = value;
OnPropertyChanged(nameof(InterruptionIndexText));
}
}
public string TopEffectiveActionText
{
get => _topEffectiveActionText;
set
{
_topEffectiveActionText = value;
OnPropertyChanged(nameof(TopEffectiveActionText));
}
}
public string SuggestionOutcomeText
{
get => _suggestionOutcomeText;
set
{
_suggestionOutcomeText = value;
OnPropertyChanged(nameof(SuggestionOutcomeText));
}
}
public string RecommendedStuckThresholdText
{
get => _recommendedStuckThresholdText;
set
{
_recommendedStuckThresholdText = value;
OnPropertyChanged(nameof(RecommendedStuckThresholdText));
}
}
public string RecommendedDailyNudgeLimitText
{
get => _recommendedDailyNudgeLimitText;
set
{
_recommendedDailyNudgeLimitText = value;
OnPropertyChanged(nameof(RecommendedDailyNudgeLimitText));
}
}
public bool ProactiveAssistEnabled
{
get => _proactiveAssistEnabled;
set
{
_proactiveAssistEnabled = value;
OnPropertyChanged(nameof(ProactiveAssistEnabled));
}
}
public bool BehaviorLearningEnabled
{
get => _behaviorLearningEnabled;
set
{
_behaviorLearningEnabled = value;
OnPropertyChanged(nameof(BehaviorLearningEnabled));
}
}
public bool StuckNudgesEnabled
{
get => _stuckNudgesEnabled;
set
{
_stuckNudgesEnabled = value;
OnPropertyChanged(nameof(StuckNudgesEnabled));
}
}
public bool LlmSkillAssistEnabled
{
get => _llmSkillAssistEnabled;
set
{
_llmSkillAssistEnabled = value;
OnPropertyChanged(nameof(LlmSkillAssistEnabled));
}
}
public int QuietHoursStart
{
get => _quietHoursStart;
set
{
_quietHoursStart = value;
OnPropertyChanged(nameof(QuietHoursStart));
}
}
public int QuietHoursEnd
{
get => _quietHoursEnd;
set
{
_quietHoursEnd = value;
OnPropertyChanged(nameof(QuietHoursEnd));
}
}
public ReminderSettingsWindow()
{
InitializeComponent();
DataContext = this;
InitializeLocalizedDefaults();
LoadCurrentSettings();
}
private void InitializeLocalizedDefaults()
{
MetricsWindowLabel = I18n.Tf("ReminderSettings_MetricsWindowFormat", 7);
SuggestionOutcomeText = I18n.T("ReminderSettings_OutcomeDefault");
RecommendedStuckThresholdText = I18n.Tf("ReminderSettings_MinutesFormat", 90);
RecommendedDailyNudgeLimitText = I18n.Tf("ReminderSettings_PerDayFormat", 2);
}
private void LoadCurrentSettings()
{
try
{
FirstWarningAfterDays = Properties.Settings.Default.FirstWarningAfterDays;
SecondWarningAfterDays = Properties.Settings.Default.SecondWarningAfterDays;
StaleTaskThresholdDays = Properties.Settings.Default.StaleTaskThresholdDays;
MaxInactiveWarnings = Properties.Settings.Default.MaxInactiveWarnings;
ReminderCheckIntervalMinutes = Properties.Settings.Default.ReminderCheckIntervalSeconds / 60;
LoadProactiveSettings();
LoadProfileMetrics();
}
catch (Exception ex)
{
Console.WriteLine($"Error loading reminder settings: {ex.Message}");
LoadDefaultSettings();
LoadProactiveSettings();
LoadProfileMetrics();
}
}
private void LoadDefaultSettings()
{
FirstWarningAfterDays = 1;
SecondWarningAfterDays = 3;
StaleTaskThresholdDays = 14;
MaxInactiveWarnings = 3;
ReminderCheckIntervalMinutes = 5;
ProactiveAssistEnabled = true;
BehaviorLearningEnabled = true;
StuckNudgesEnabled = true;
LlmSkillAssistEnabled = true;
QuietHoursStart = 22;
QuietHoursEnd = 8;
}
private void LoadProactiveSettings()
{
ProactiveAssistEnabled = GetAppSettingBool("ProactiveAssistEnabled", true);
BehaviorLearningEnabled = GetAppSettingBool("BehaviorLearningEnabled", true);
StuckNudgesEnabled = GetAppSettingBool("StuckNudgesEnabled", true);
LlmSkillAssistEnabled = GetAppSettingBool("LlmSkillAssistEnabled", true);
QuietHoursStart = GetAppSettingInt("QuietHoursStart", 22, 0, 23);
QuietHoursEnd = GetAppSettingInt("QuietHoursEnd", 8, 0, 23);
}
private static bool GetAppSettingBool(string key, bool defaultValue)
{
string value = ConfigurationManager.AppSettings[key];
return bool.TryParse(value, out bool parsed) ? parsed : defaultValue;
}
private static int GetAppSettingInt(string key, int defaultValue, int min, int max)
{
string value = ConfigurationManager.AppSettings[key];
if (int.TryParse(value, out int parsed))
{
return Math.Max(min, Math.Min(max, parsed));
}
return defaultValue;
}
private void LoadProfileMetrics()
{
try
{
var manager = new UserProfileManager();
var metrics = manager.GetDashboardMetrics(7);
MetricsWindowLabel = I18n.Tf("ReminderSettings_MetricsWindowFormat", metrics.WindowDays);
SuggestionHitRateText = $"{metrics.HitRate:P1}";
InterruptionIndexText = $"{metrics.InterruptionIndex:P1}";
TopEffectiveActionText = ToActionLabel(metrics.TopEffectiveActionId);
SuggestionOutcomeText = I18n.Tf(
"ReminderSettings_OutcomeFormat",
metrics.SuggestionsShown,
metrics.SuggestionsAccepted,
metrics.SuggestionsDeferred,
metrics.SuggestionsRejected);
var recommendation = manager.GetAdaptiveNudgeRecommendation(7);
RecommendedStuckThresholdText = I18n.Tf("ReminderSettings_MinutesFormat", recommendation.RecommendedStuckThresholdMinutes);
RecommendedDailyNudgeLimitText = I18n.Tf("ReminderSettings_PerDayFormat", recommendation.RecommendedDailyNudgeLimit);
}
catch (Exception ex)
{
Console.WriteLine($"Error loading profile metrics: {ex.Message}");
MetricsWindowLabel = I18n.Tf("ReminderSettings_MetricsWindowFormat", 7);
SuggestionHitRateText = "N/A";
InterruptionIndexText = "N/A";
TopEffectiveActionText = "N/A";
SuggestionOutcomeText = "N/A";
RecommendedStuckThresholdText = "N/A";
RecommendedDailyNudgeLimitText = "N/A";
}
}
private static string ToActionLabel(string actionId)
{
switch ((actionId ?? string.Empty).Trim().ToLowerInvariant())
{
case "start_10_min": return I18n.T("ReminderSettings_ActionStart10");
case "split_20_min": return I18n.T("ReminderSettings_ActionSplit20");
case "delegate_or_drop": return I18n.T("ReminderSettings_ActionDelegate");
case "pause_and_switch": return I18n.T("ReminderSettings_ActionPauseSwitch");
case "decision_now": return I18n.T("ReminderSettings_ActionDecisionNow");
case "fallback_min_step": return I18n.T("ReminderSettings_ActionFallback");
case "n/a":
case "":
return "N/A";
default:
return actionId;
}
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
if (ValidateSettings())
{
try
{
Properties.Settings.Default.FirstWarningAfterDays = FirstWarningAfterDays;
Properties.Settings.Default.SecondWarningAfterDays = SecondWarningAfterDays;
Properties.Settings.Default.StaleTaskThresholdDays = StaleTaskThresholdDays;
Properties.Settings.Default.MaxInactiveWarnings = MaxInactiveWarnings;
Properties.Settings.Default.ReminderCheckIntervalSeconds = ReminderCheckIntervalMinutes * 60;
SaveProactiveSettings();
Properties.Settings.Default.Save();
MessageBox.Show(I18n.T("ReminderSettings_SaveSuccess"), I18n.T("ReminderSettings_TitleSaveSuccess"),
MessageBoxButton.OK, MessageBoxImage.Information);
DialogResult = true;
Close();
}
catch (Exception ex)
{
Console.WriteLine($"Error saving reminder settings: {ex.Message}");
MessageBox.Show(I18n.T("ReminderSettings_SaveFailed"), I18n.T("ReminderSettings_TitleSaveFailed"),
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
private bool ValidateSettings()
{
if (FirstWarningAfterDays < 1 || FirstWarningAfterDays > 30)
{
MessageBox.Show(I18n.T("ReminderSettings_ValidationFirstWarning"), I18n.T("ReminderSettings_TitleValidation"),
MessageBoxButton.OK, MessageBoxImage.Warning);
return false;
}
if (SecondWarningAfterDays < FirstWarningAfterDays || SecondWarningAfterDays > 60)
{
MessageBox.Show(I18n.T("ReminderSettings_ValidationSecondWarning"), I18n.T("ReminderSettings_TitleValidation"),
MessageBoxButton.OK, MessageBoxImage.Warning);
return false;
}
if (StaleTaskThresholdDays < SecondWarningAfterDays || StaleTaskThresholdDays > 365)
{
MessageBox.Show(I18n.T("ReminderSettings_ValidationStaleThreshold"), I18n.T("ReminderSettings_TitleValidation"),
MessageBoxButton.OK, MessageBoxImage.Warning);
return false;
}
if (MaxInactiveWarnings < 1 || MaxInactiveWarnings > 10)
{
MessageBox.Show(I18n.T("ReminderSettings_ValidationMaxWarnings"), I18n.T("ReminderSettings_TitleValidation"),
MessageBoxButton.OK, MessageBoxImage.Warning);
return false;
}
if (ReminderCheckIntervalMinutes < 1 || ReminderCheckIntervalMinutes > 60)
{
MessageBox.Show(I18n.T("ReminderSettings_ValidationInterval"), I18n.T("ReminderSettings_TitleValidation"),
MessageBoxButton.OK, MessageBoxImage.Warning);
return false;
}
if (QuietHoursStart < 0 || QuietHoursStart > 23 || QuietHoursEnd < 0 || QuietHoursEnd > 23)
{
MessageBox.Show(I18n.T("ReminderSettings_ValidationQuietHours"), I18n.T("ReminderSettings_TitleValidation"),
MessageBoxButton.OK, MessageBoxImage.Warning);
return false;
}
return true;
}
private void SaveProactiveSettings()
{
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = config.AppSettings.Settings;
SetOrAddAppSetting(settings, "ProactiveAssistEnabled", ProactiveAssistEnabled ? "true" : "false");
SetOrAddAppSetting(settings, "BehaviorLearningEnabled", BehaviorLearningEnabled ? "true" : "false");
SetOrAddAppSetting(settings, "StuckNudgesEnabled", StuckNudgesEnabled ? "true" : "false");
SetOrAddAppSetting(settings, "LlmSkillAssistEnabled", LlmSkillAssistEnabled ? "true" : "false");
SetOrAddAppSetting(settings, "QuietHoursStart", QuietHoursStart.ToString());
SetOrAddAppSetting(settings, "QuietHoursEnd", QuietHoursEnd.ToString());
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
private static void SetOrAddAppSetting(KeyValueConfigurationCollection settings, string key, string value)
{
if (settings[key] == null)
{
settings.Add(key, value);
}
else
{
settings[key].Value = value;
}
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
private void ResetButton_Click(object sender, RoutedEventArgs e)
{
var result = MessageBox.Show(I18n.T("ReminderSettings_ResetConfirm"), I18n.T("ReminderSettings_TitleResetConfirm"),
MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
LoadDefaultSettings();
}
}
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}