Filter reminder snooze options by default reminder

This commit is contained in:
Burak Kaan Köse
2026-02-27 21:57:41 +01:00
parent 0e742c7a8f
commit c942066878
11 changed files with 223 additions and 33 deletions
+38 -3
View File
@@ -215,12 +215,20 @@ public partial class App : WinoApplication,
// Check calendar reminder toast activation first.
if (toastArguments.TryGetValue(Constants.ToastCalendarActionKey, out string calendarAction) &&
calendarAction == Constants.ToastCalendarNavigateAction &&
toastArguments.TryGetValue(Constants.ToastCalendarItemIdKey, out string calendarItemIdString) &&
Guid.TryParse(calendarItemIdString, out Guid calendarItemId))
{
await HandleCalendarToastNavigationAsync(calendarItemId);
return;
if (calendarAction == Constants.ToastCalendarNavigateAction)
{
await HandleCalendarToastNavigationAsync(calendarItemId);
return;
}
if (calendarAction == Constants.ToastCalendarSnoozeAction)
{
await HandleCalendarToastSnoozeAsync(toastArgs, calendarItemId);
return;
}
}
// Check if this is a navigation toast (user clicked the notification).
@@ -267,6 +275,33 @@ public partial class App : WinoApplication,
navigationService.Navigate(WinoPage.EventDetailsPage, target);
}
private async Task HandleCalendarToastSnoozeAsync(AppNotificationActivatedEventArgs toastArgs, Guid calendarItemId)
{
if (!TryGetSnoozeDurationMinutes(toastArgs, out var snoozeDurationMinutes))
return;
var calendarService = Services.GetRequiredService<ICalendarService>();
var snoozedUntilLocal = DateTime.Now.AddMinutes(snoozeDurationMinutes);
await calendarService.SnoozeCalendarItemAsync(calendarItemId, snoozedUntilLocal).ConfigureAwait(false);
}
private static bool TryGetSnoozeDurationMinutes(AppNotificationActivatedEventArgs toastArgs, out int snoozeDurationMinutes)
{
snoozeDurationMinutes = 0;
if (toastArgs.UserInput == null ||
!toastArgs.UserInput.TryGetValue(Constants.ToastCalendarSnoozeDurationInputId, out var selectedValue) ||
selectedValue == null)
{
return false;
}
var selectedText = selectedValue.ToString();
return int.TryParse(selectedText, out snoozeDurationMinutes) && snoozeDurationMinutes > 0;
}
/// <summary>
/// Handles toast notification click for navigation.
/// Creates window if not running, sets up navigation parameter.
+48 -24
View File
@@ -5,7 +5,6 @@ using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Toolkit.Uwp.Notifications;
using Serilog;
using Windows.ApplicationModel;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Wino.Core.Domain.Entities.Calendar;
@@ -26,16 +25,19 @@ public class NotificationBuilder : INotificationBuilder
private readonly IFolderService _folderService;
private readonly IMailService _mailService;
private readonly IThumbnailService _thumbnailService;
private readonly IPreferencesService _preferencesService;
public NotificationBuilder(IAccountService accountService,
IFolderService folderService,
IMailService mailService,
IThumbnailService thumbnailService)
IThumbnailService thumbnailService,
IPreferencesService preferencesService)
{
_accountService = accountService;
_folderService = folderService;
_mailService = mailService;
_thumbnailService = thumbnailService;
_preferencesService = preferencesService;
WeakReferenceMessenger.Default.Register<MailReadStatusChanged>(this, (r, msg) =>
{
@@ -96,7 +98,7 @@ public class NotificationBuilder : INotificationBuilder
Src = new Uri("ms-winsoundevent:Notification.Mail")
});
ShowToast(builder, ToastTargetApp.Mail);
ShowToast(builder);
}
else
{
@@ -151,7 +153,7 @@ public class NotificationBuilder : INotificationBuilder
});
// Use UniqueId as tag to allow removal
ShowToast(builder, ToastTargetApp.Mail, mailItem.UniqueId.ToString());
ShowToast(builder, mailItem.UniqueId.ToString());
}
private ToastButton GetDismissButton()
@@ -242,7 +244,7 @@ public class NotificationBuilder : INotificationBuilder
{
try
{
ToastNotificationManager.History.Remove(mailUniqueId.ToString(), null, GetAppUserModelId(ToastTargetApp.Mail));
ToastNotificationManager.History.Remove(mailUniqueId.ToString());
}
catch (Exception ex)
{
@@ -263,7 +265,7 @@ public class NotificationBuilder : INotificationBuilder
builder.AddArgument(Constants.ToastMailAccountIdKey, account.Id.ToString());
builder.AddArgument(Constants.ToastModeKey, Constants.ToastModeMail);
builder.AddButton(new ToastButton().SetContent(Translator.Buttons_FixAccount));
ShowToast(builder, ToastTargetApp.Mail);
ShowToast(builder);
}
public void CreateWebView2RuntimeMissingNotification()
@@ -276,7 +278,7 @@ public class NotificationBuilder : INotificationBuilder
builder.AddButton(GetDismissButton());
builder.AddArgument(Constants.ToastModeKey, Constants.ToastModeMail);
ShowToast(builder, ToastTargetApp.Mail);
ShowToast(builder);
}
public Task CreateCalendarReminderNotificationAsync(CalendarItem calendarItem, long reminderDurationInSeconds)
@@ -302,19 +304,54 @@ public class NotificationBuilder : INotificationBuilder
builder.AddArgument(Constants.ToastCalendarActionKey, Constants.ToastCalendarNavigateAction);
builder.AddArgument(Constants.ToastCalendarItemIdKey, calendarItem.Id.ToString());
builder.AddArgument(Constants.ToastModeKey, Constants.ToastModeCalendar);
builder.AddButton(GetDismissButton());
var allowedSnoozeMinutes = CalendarReminderSnoozeOptions.GetAllowedSnoozeMinutes(
reminderDurationInSeconds,
_preferencesService.DefaultReminderDurationInSeconds);
if (allowedSnoozeMinutes.Count > 0)
{
var selectionBox = new ToastSelectionBox(Constants.ToastCalendarSnoozeDurationInputId)
{
DefaultSelectionBoxItemId = allowedSnoozeMinutes[0].ToString()
};
foreach (var snoozeMinutes in allowedSnoozeMinutes)
{
selectionBox.Items.Add(new ToastSelectionBoxItem(
snoozeMinutes.ToString(),
string.Format(Translator.CalendarReminder_SnoozeMinutesOption, snoozeMinutes)));
}
builder.AddInput(selectionBox);
builder.AddButton(new ToastButtonSnooze()
.SetSelectionBoxId(Constants.ToastCalendarSnoozeDurationInputId)
.AddArgument(Constants.ToastCalendarActionKey, Constants.ToastCalendarSnoozeAction)
.AddArgument(Constants.ToastCalendarItemIdKey, calendarItem.Id.ToString())
.AddArgument(Constants.ToastModeKey, Constants.ToastModeCalendar));
}
builder.AddButton(new ToastButtonDismiss());
if (Uri.TryCreate(calendarItem.HtmlLink, UriKind.Absolute, out var joinUri))
{
builder.AddButton(new ToastButton()
.SetContent(Translator.CalendarEventDetails_JoinOnline)
.SetProtocolActivation(joinUri));
}
builder.AddAudio(new ToastAudio()
{
Src = new Uri("ms-winsoundevent:Notification.Reminder")
});
var tag = $"calendar-reminder-{calendarItem.Id:N}-{reminderDurationInSeconds}";
ShowToast(builder, ToastTargetApp.Calendar, tag);
ShowToast(builder, tag);
return Task.CompletedTask;
}
private static void ShowToast(ToastContentBuilder builder, ToastTargetApp targetApp, string? tag = null)
private static void ShowToast(ToastContentBuilder builder, string? tag = null)
{
var toastNotification = new ToastNotification(builder.GetToastContent().GetXml());
@@ -323,20 +360,7 @@ public class NotificationBuilder : INotificationBuilder
toastNotification.Tag = tag;
}
var appUserModelId = GetAppUserModelId(targetApp);
var notifier = ToastNotificationManager.CreateToastNotifier(appUserModelId);
var notifier = ToastNotificationManager.CreateToastNotifier();
notifier.Show(toastNotification);
}
private static string GetAppUserModelId(ToastTargetApp targetApp)
{
_ = targetApp;
return $"{Package.Current.Id.FamilyName}!{MailApplicationId}";
}
private enum ToastTargetApp
{
Mail,
Calendar
}
}