Snooze notifications, morning summary, ICS import, data folder sync

- Windows toast notifications with snooze (10 min / 1 h / tomorrow) and
  done buttons; balloon fallback; works when Windows starts the app
- Recurring entries snooze via SnoozedUntil without moving their date;
  lead reminders keep the real date
- Morning summary once a day from a chosen hour (pure DailySummary)
- iCalendar import incl. Google birthday calendar, folded lines, UTC,
  alarms, own export round trip, duplicates skipped by UID, undo
- Data folder selectable (location.json pointer), file watcher reloads
  changes from another PC (own writes ignored)
- Themed date picker calendar, WPF tray menu, arrow/Home/End/Space keys
- 90 tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-29 20:37:20 +01:00
parent 7486eebd67
commit 33459bdec7
18 changed files with 1300 additions and 61 deletions

View File

@@ -1,51 +1,117 @@
#nullable enable
using System;
using System.IO;
using System.Windows;
using System.Windows.Forms;
using Microsoft.Toolkit.Uwp.Notifications;
namespace ReminderOrganizer.Services
{
/// <summary>
/// Windows toast notifications (Action Center) with snooze buttons. Falls back to the tray balloon if toasts
/// are not available (e.g. notifications turned off or an old Windows build).
/// </summary>
public class NotificationService : INotificationService
{
private readonly object _lock = new();
private readonly ILocalizationService _loc;
private string? _logoPath;
public static NotifyIcon? SharedTrayIcon { get; set; }
public NotificationService(ILocalizationService localizationService)
{
_loc = localizationService;
}
public void ShowNotification(string title, string message)
{
try
{
System.Diagnostics.Debug.WriteLine($"[NotificationService] ShowNotification: {title} - {message}");
System.Diagnostics.Debug.WriteLine($"[NotificationService] SharedTrayIcon is null: {SharedTrayIcon == null}");
ShowBalloonTip(title, message);
Builder(title, message).AddArgument("action", "open").Show();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"[NotificationService] Error: {ex.Message}");
System.Diagnostics.Debug.WriteLine($"[Toast] {ex.Message}");
ShowBalloon(title, message);
}
}
private void ShowBalloonTip(string title, string message)
public void ShowReminder(string title, string message, string taskId, bool isLead)
{
lock (_lock)
try
{
if (SharedTrayIcon != null)
{
// ShowBalloonTip throws on empty text – tasks without description would never notify.
SharedTrayIcon.BalloonTipTitle = string.IsNullOrWhiteSpace(title) ? "Reminder Organizer" : title;
SharedTrayIcon.BalloonTipText = string.IsNullOrWhiteSpace(message) ? " " : message;
SharedTrayIcon.BalloonTipIcon = ToolTipIcon.Info;
SharedTrayIcon.ShowBalloonTip(5000);
System.Diagnostics.Debug.WriteLine("[NotificationService] BalloonTip shown!");
}
else
{
System.Diagnostics.Debug.WriteLine("[NotificationService] SharedTrayIcon is null, cannot show balloon tip!");
}
string lead = isLead ? "1" : "0";
ToastButton Snooze(string label, string minutes) => new ToastButton()
.SetContent(label)
.AddArgument("action", "snooze").AddArgument("min", minutes)
.AddArgument("id", taskId).AddArgument("lead", lead)
.SetBackgroundActivation();
Builder(title, message)
.AddArgument("action", "open").AddArgument("id", taskId)
.AddButton(Snooze(_loc.GetString("Snooze10"), "10"))
.AddButton(Snooze(_loc.GetString("Snooze60"), "60"))
.AddButton(Snooze(_loc.GetString("SnoozeTomorrow"), "tomorrow"))
.AddButton(new ToastButton()
.SetContent(_loc.GetString("ToastDone"))
.AddArgument("action", "done").AddArgument("id", taskId).AddArgument("lead", lead)
.SetBackgroundActivation())
.Show();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"[Toast] {ex.Message}");
ShowBalloon(title, message);
}
}
public void Dispose()
private ToastContentBuilder Builder(string title, string message)
{
var b = new ToastContentBuilder()
.AddText(string.IsNullOrWhiteSpace(title) ? "Reminder Organizer" : title);
if (!string.IsNullOrWhiteSpace(message)) b.AddText(message);
if (LogoPath() is { } logo) b.AddAppLogoOverride(new Uri(logo), ToastGenericAppLogoCrop.Default);
return b;
}
/// <summary>Toasts need the logo as a file – extract it once to the app folder.</summary>
private string? LogoPath()
{
if (_logoPath != null) return _logoPath;
try
{
var path = Path.Combine(DataService.AppDirectory, "toast-logo.png");
if (!File.Exists(path))
{
var res = System.Windows.Application.GetResourceStream(new Uri("pack://application:,,,/Assets/app.png"));
if (res == null) return null;
Directory.CreateDirectory(DataService.AppDirectory);
using var fs = File.Create(path);
res.Stream.CopyTo(fs);
}
return _logoPath = path;
}
catch
{
return null;
}
}
private static void ShowBalloon(string title, string message)
{
try
{
if (SharedTrayIcon == null) return;
// ShowBalloonTip throws on empty text – tasks without description would never notify.
SharedTrayIcon.BalloonTipTitle = string.IsNullOrWhiteSpace(title) ? "Reminder Organizer" : title;
SharedTrayIcon.BalloonTipText = string.IsNullOrWhiteSpace(message) ? " " : message;
SharedTrayIcon.BalloonTipIcon = ToolTipIcon.Info;
SharedTrayIcon.ShowBalloonTip(5000);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"[Balloon] {ex.Message}");
}
}
}
}