-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMainPage.TaskSnooze.cs
More file actions
132 lines (113 loc) · 5.06 KB
/
Copy pathMainPage.TaskSnooze.cs
File metadata and controls
132 lines (113 loc) · 5.06 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
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Media;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using FluentTaskScheduler.Models;
using FluentTaskScheduler.Models.Enums;
using FluentTaskScheduler.Services;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using System.Linq;
using Microsoft.UI.Dispatching;
using FluentTaskScheduler.ViewModels;
using System;
using Windows.ApplicationModel.DataTransfer;
namespace FluentTaskScheduler
{
/// <summary>Per-task snooze controls.</summary>
public sealed partial class MainPage
{
// ── Per-task snooze ─────────────────────────────────────────────────────
/// <summary>
/// Syncs the detail dialog's snooze controls with the selected task: the status line and
/// "Resume now" only make sense while that task is actually snoozed.
/// </summary>
private void UpdateTaskSnoozeUi()
{
var task = ViewModel.SelectedTask;
if (task == null) return;
string status = TaskSnoozeService.StatusTextFor(task.Path);
bool snoozed = !string.IsNullOrEmpty(status);
TaskSnoozeStatusText.Text = status;
TaskSnoozeStatusText.Visibility = snoozed ? Visibility.Visible : Visibility.Collapsed;
SnoozeTaskCancel.Visibility = snoozed ? Visibility.Visible : Visibility.Collapsed;
// The picker is transient — never leave it open across tasks or reopens.
TaskSnoozeCustomPanel.Visibility = Visibility.Collapsed;
TaskSnoozeCustomError.IsOpen = false;
}
private void SnoozeTaskDuration_Click(object sender, RoutedEventArgs e)
{
var task = ViewModel.SelectedTask;
if (task == null) return;
if (sender is not MenuFlyoutItem item || !int.TryParse(item.Tag?.ToString(), out int minutes)) return;
TaskSnoozeService.Snooze(task.Path, TimeSpan.FromMinutes(minutes));
AfterTaskSnoozeChanged();
}
private void SnoozeTaskUntilReboot_Click(object sender, RoutedEventArgs e)
{
var task = ViewModel.SelectedTask;
if (task == null) return;
TaskSnoozeService.SnoozeUntilReboot(task.Path);
AfterTaskSnoozeChanged();
}
private void SnoozeTaskCancel_Click(object sender, RoutedEventArgs e)
{
var task = ViewModel.SelectedTask;
if (task == null) return;
TaskSnoozeService.Cancel(task.Path);
AfterTaskSnoozeChanged();
}
/// <summary>
/// Reveals the inline custom-end-time picker. This cannot be a ContentDialog of its own:
/// it is invoked from inside TaskDetailsDialog, and WinUI permits only one ContentDialog
/// open at a time — the nested ShowAsync threw and the click appeared to do nothing.
/// </summary>
private void SnoozeTaskCustom_Click(object sender, RoutedEventArgs e)
{
if (ViewModel.SelectedTask == null) return;
TaskSnoozeCustomError.IsOpen = false;
TaskSnoozeCustomDate.Date = DateTimeOffset.Now;
TaskSnoozeCustomTime.Time = DateTime.Now.AddHours(1).TimeOfDay;
TaskSnoozeCustomPanel.Visibility = Visibility.Visible;
}
private void TaskSnoozeCustomCancel_Click(object sender, RoutedEventArgs e)
{
TaskSnoozeCustomPanel.Visibility = Visibility.Collapsed;
TaskSnoozeCustomError.IsOpen = false;
}
private void TaskSnoozeCustomApply_Click(object sender, RoutedEventArgs e)
{
var task = ViewModel.SelectedTask;
if (task == null) return;
try
{
var end = TaskSnoozeCustomDate.Date.Date + TaskSnoozeCustomTime.Time;
if (end <= DateTime.Now)
{
TaskSnoozeCustomError.Message = L("Snooze.Error.PastTime", "Pick a time in the future.");
TaskSnoozeCustomError.IsOpen = true;
return;
}
TaskSnoozeService.SnoozeUntilLocalTime(task.Path, end);
TaskSnoozeCustomPanel.Visibility = Visibility.Collapsed;
TaskSnoozeCustomError.IsOpen = false;
AfterTaskSnoozeChanged();
}
catch (Exception ex)
{
Serilog.Log.Error(ex, "{Message}", $"Failed to snooze task '{task.Path}' until a custom time.");
TaskSnoozeCustomError.Message = ex.Message;
TaskSnoozeCustomError.IsOpen = true;
}
}
/// <summary>Refreshes the dialog and the task list after a task's snooze state changed.</summary>
private void AfterTaskSnoozeChanged()
{
UpdateTaskSnoozeUi();
_ = ViewModel.LoadTasksAsync();
}
}
}