From 33459bdec75f78a536bf6a63a41cdff1d72bec03 Mon Sep 17 00:00:00 2001 From: Michi Date: Sun, 29 Nov 2026 20:37:20 +0100 Subject: [PATCH] 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 --- App.xaml.cs | 18 ++- CLAUDE.md | 5 +- Core/DailySummary.cs | 35 +++++ Locales/de.json | 19 ++- Locales/en.json | 19 ++- MainWindow.xaml.cs | 113 +++++++++++++- Models/ReminderModels.cs | 39 +++++ README.md | 9 +- ReminderOrganizer.csproj | 1 + Services/DataService.cs | 105 ++++++++++++- Services/IcsImport.cs | 189 +++++++++++++++++++++++ Services/Interfaces.cs | 8 +- Services/NotificationService.cs | 108 ++++++++++--- SettingsWindow.xaml | 30 +++- Tests/ImportSnoozeTests.cs | 159 +++++++++++++++++++ Tests/SyncTests.cs | 66 ++++++++ Themes/Controls.xaml | 178 +++++++++++++++++++++- ViewModels/MainViewModel.cs | 260 ++++++++++++++++++++++++++++++-- 18 files changed, 1300 insertions(+), 61 deletions(-) create mode 100644 Core/DailySummary.cs create mode 100644 Services/IcsImport.cs create mode 100644 Tests/ImportSnoozeTests.cs create mode 100644 Tests/SyncTests.cs diff --git a/App.xaml.cs b/App.xaml.cs index df21cb3..53a4baf 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using System; using System.IO; using System.Threading.Tasks; @@ -30,10 +30,18 @@ namespace ReminderOrganizer SetupExceptionHandling(); ServiceLocator.Initialize(); + // Buttons in Windows notifications (snooze / done / open) – also when Windows started us for it. + Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat.OnActivated += args => + { + var toastArgs = Microsoft.Toolkit.Uwp.Notifications.ToastArguments.Parse(args.Argument); + Current.Dispatcher.BeginInvoke(new Action(() => (Current.MainWindow as MainWindow)?.HandleToast(toastArgs))); + }; + bool fromToast = Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat.WasCurrentProcessToastActivated(); + var main = new MainWindow(); MainWindow = main; - // Autostart passes --minimized: start straight into the tray. - if (Array.IndexOf(e.Args, "--minimized") >= 0) + // Autostart passes --minimized: start straight into the tray. A toast button decides itself. + if (Array.IndexOf(e.Args, "--minimized") >= 0 || fromToast) main.StartHidden(); else main.Show(); @@ -84,8 +92,8 @@ namespace ReminderOrganizer { try { - Directory.CreateDirectory(DataService.DefaultDataDirectory); - var logPath = Path.Combine(DataService.DefaultDataDirectory, "error.log"); + Directory.CreateDirectory(DataService.AppDirectory); + var logPath = Path.Combine(DataService.AppDirectory, "error.log"); var logEntry = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{source}]\n{ex}\n\n"; File.AppendAllText(logPath, logEntry); } diff --git a/CLAUDE.md b/CLAUDE.md index 1016fb8..e2dcbf0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -8,7 +8,10 @@ services through `ServiceLocator` (Microsoft.Extensions.DependencyInjection). `ProcessDue`) is pure and tested. - `Services/`: `DataService` (JSON in %APPDATA%, atomic + serialized), `LocalizationService` (Locales are **EmbeddedResource** `Locales..json`), `TaskCsv` + `Core/Csv` (import/export), `AutostartService` - (HKCU Run, `"exe" --minimized`), `NotificationService` (tray balloon). + (HKCU Run, `"exe" --minimized`), `NotificationService` (Windows toasts via Microsoft.Toolkit.Uwp.Notifications with snooze/done buttons → `App` `OnActivated` → `MainWindow.HandleToast` → `MainViewModel.HandleToastAction`; tray balloon as fallback), `IcsImport`/`IcsExport`. +- Data folder: `DataService.AppDirectory` (pointer `location.json`, error.log, toast logo) vs. `DefaultDataDirectory` (tasks.json, + may be OneDrive). `FileSystemWatcher` + `LastWriteUtc` → `MainViewModel.ReloadFromDiskAsync` when another PC changed the file. +- Morning summary: `Core/DailySummary.cs` (pure), shown from `CheckReminders`. - Anniversaries: `ReminderTask.IsAnniversary` (stored as JSON `"IsBirthday"` for older files) + `CategoryId` → `Models/Category.cs` (presets birthday/wedding/jubilee/memorial + own ones, text with `{0}`/`{o}`). Filter/sort/group rules are in `Core/TaskQuery.cs` (pure, tested). diff --git a/Core/DailySummary.cs b/Core/DailySummary.cs new file mode 100644 index 0000000..159b682 --- /dev/null +++ b/Core/DailySummary.cs @@ -0,0 +1,35 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Linq; +using ReminderOrganizer.Models; + +namespace ReminderOrganizer.Core +{ + /// Content of the morning summary. Null when there is nothing worth showing. + public sealed record DailySummaryData( + IReadOnlyList Today, + IReadOnlyList Overdue, + IReadOnlyList AnniversariesSoon); + + public static class DailySummary + { + /// Days ahead in which anniversaries are announced (tomorrow … in 3 days). + public const int AnniversaryDays = 3; + + public static DailySummaryData? Build(IEnumerable tasks, DateTime now) + { + var open = tasks.Where(t => !t.IsNotified).ToList(); + var today = open.Where(t => t.ReminderDate.Date == now.Date).OrderBy(t => t.ReminderDate).ToList(); + var overdue = open.Where(t => !t.IsRecurring && t.ReminderDate.Date < now.Date).OrderBy(t => t.ReminderDate).ToList(); + var soon = open.Where(t => t.IsAnniversary) + .Where(t => (t.ReminderDate.Date - now.Date).Days is > 0 and <= AnniversaryDays) + .OrderBy(t => t.ReminderDate).ToList(); + return today.Count + overdue.Count + soon.Count == 0 ? null : new DailySummaryData(today, overdue, soon); + } + + /// Should the summary be shown now? Once per day, from on. + public static bool IsDue(DateTime now, int hour, DateTime? lastShown) => + now.Hour >= hour && (lastShown == null || lastShown.Value.Date < now.Date); + } +} diff --git a/Locales/de.json b/Locales/de.json index 98bca43..82dcc6b 100644 --- a/Locales/de.json +++ b/Locales/de.json @@ -196,5 +196,22 @@ "CatPlaceholderYears": "Anzahl der Jahre", "CatPlaceholderOrdinal": "Ordnungszahl (25.)", "CatChangeLook": "Symbol und Farbe ändern", - "AddCategoryShort": "Kategorie" + "AddCategoryShort": "Kategorie", + "Snooze10": "10 Min", + "Snooze60": "1 Std", + "SnoozeTomorrow": "Morgen", + "ToastDone": "Erledigt", + "SummarySetting": "Tagesübersicht", + "SummarySettingHint": "Einmal am Tag: heutige Einträge, nahe Geburtstage und Überfälliges.", + "SummaryTitle": "Dein Tag", + "SummaryToday": "Heute:", + "SummaryOverdue": "{0} überfällig", + "DataFolderHint": "Für mehrere PCs einen synchronisierten Ordner wählen, z. B. in OneDrive.", + "ChangeFolder": "Ändern…", + "ChooseDataFolder": "Datenordner wählen", + "DataFolderHasData": "In diesem Ordner liegen schon Erinnerungen.\n\nJa = die Erinnerungen dort verwenden\nNein = sie durch meine ersetzen", + "ImportIcs": "Kalender importieren (.ics)", + "IcsImported": "{0} Einträge importiert, {1} übersprungen", + "IcsNothingNew": "Keine neuen Einträge gefunden ({0} übersprungen – schon vorhanden oder vergangen).", + "FolderBirthdays": "Geburtstage" } diff --git a/Locales/en.json b/Locales/en.json index 3fd0881..76ea9a4 100644 --- a/Locales/en.json +++ b/Locales/en.json @@ -196,5 +196,22 @@ "CatPlaceholderYears": "number of years", "CatPlaceholderOrdinal": "ordinal (25th)", "CatChangeLook": "Change icon and color", - "AddCategoryShort": "Category" + "AddCategoryShort": "Category", + "Snooze10": "10 min", + "Snooze60": "1 hour", + "SnoozeTomorrow": "Tomorrow", + "ToastDone": "Done", + "SummarySetting": "Morning summary", + "SummarySettingHint": "Once a day: today's entries, upcoming birthdays and anything overdue.", + "SummaryTitle": "Your day", + "SummaryToday": "Today:", + "SummaryOverdue": "{0} overdue", + "DataFolderHint": "For several PCs choose a synced folder, e.g. in OneDrive.", + "ChangeFolder": "Change…", + "ChooseDataFolder": "Choose data folder", + "DataFolderHasData": "This folder already contains reminders.\n\nYes = use the reminders in that folder\nNo = replace them with mine", + "ImportIcs": "Import calendar (.ics)", + "IcsImported": "{0} entries imported, {1} skipped", + "IcsNothingNew": "No new entries found ({0} skipped – already there or in the past).", + "FolderBirthdays": "Birthdays" } diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 99d8cbc..37fc565 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -1,6 +1,7 @@ #nullable enable using System; using System.ComponentModel; +using System.Linq; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Controls; @@ -62,6 +63,10 @@ namespace ReminderOrganizer // The window starts invisible so the user never sees the default theme flash. BeginAnimation(OpacityProperty, new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(160))); + + _ready = true; + foreach (var pending in _pendingToasts.ToArray()) HandleToast(pending); + _pendingToasts.Clear(); } public void OnAppExit() @@ -207,6 +212,48 @@ namespace ReminderOrganizer _viewModel.EditTaskCommand.Execute(_viewModel.SelectedTask); e.Handled = true; } + // list navigation (the folder tree keeps its own arrow keys) + else if (!typing && !FolderTree.IsKeyboardFocusWithin && e.Key is Key.Down or Key.Up or Key.Home or Key.End) + { + MoveSelection(e.Key); + e.Handled = true; + } + else if (!typing && e.Key == Key.Space && _viewModel.SelectedTask is { } sel) + { + sel.IsNotified = !sel.IsNotified; + _viewModel.ToggleDoneCommand.Execute(sel); + e.Handled = true; + } + } + + /// Arrow keys move the selection in display order (across groups) and keep it visible. + private void MoveSelection(Key key) + { + var items = _viewModel.TasksView?.Cast().ToList(); + if (items == null || items.Count == 0) return; + int idx = _viewModel.SelectedTask is { } cur ? items.IndexOf(cur) : -1; + int next = key switch + { + Key.Home => 0, + Key.End => items.Count - 1, + Key.Down => idx < 0 ? 0 : Math.Min(items.Count - 1, idx + 1), + _ => idx < 0 ? items.Count - 1 : Math.Max(0, idx - 1) + }; + _viewModel.SelectedTask = items[next]; + Dispatcher.BeginInvoke(() => FindContainer(ListScroll, items[next])?.BringIntoView(), + System.Windows.Threading.DispatcherPriority.Loaded); + } + + /// Rows sit inside group containers, so ItemContainerGenerator can't find them – search the tree. + private static FrameworkElement? FindContainer(DependencyObject root, object item) + { + for (int i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++) + { + var child = VisualTreeHelper.GetChild(root, i); + if (child is ContentPresenter cp && ReferenceEquals(cp.Content, item)) return cp; + if (FindContainer(child, item) is { } found) return found; + } + return null; } private void OnEditTaskRequested(object? sender, ReminderTask? task) @@ -284,17 +331,71 @@ namespace ReminderOrganizer Services.NotificationService.SharedTrayIcon = _notifyIcon; - var menu = new System.Windows.Forms.ContextMenuStrip(); - menu.Items.Add(_viewModel.L("Open"), null, (s, e) => ShowMainWindow()); - menu.Items.Add(_viewModel.L("Exit"), null, (s, e) => + // WPF menu instead of the WinForms one, so it uses the app's theme styles. + _notifyIcon.MouseUp += (s, e) => { - App.Quit(); - }); - _notifyIcon.ContextMenuStrip = menu; + if (e.Button == System.Windows.Forms.MouseButtons.Right) ShowTrayMenu(); + }; _notifyIcon.DoubleClick += (s, e) => ShowMainWindow(); _notifyIcon.BalloonTipClicked += (s, e) => ShowMainWindow(); } + [DllImport("user32.dll")] + private static extern bool SetForegroundWindow(IntPtr hWnd); + + private void ShowTrayMenu() + { + MenuItem Item(string key, string glyph, Action onClick) + { + var mi = new MenuItem + { + Header = _viewModel.L(key), + Icon = new TextBlock { Text = glyph, FontFamily = (FontFamily)FindResource("IconFont"), FontSize = 12 } + }; + mi.Click += (_, _) => onClick(); + return mi; + } + + var menu = new ContextMenu { Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint }; + menu.Items.Add(Item("Open", "", ShowMainWindow)); + menu.Items.Add(Item("NewEntry", "", () => + { + ShowMainWindow(); + if (_viewModel.AddTaskCommand.CanExecute(null)) _viewModel.AddTaskCommand.Execute(null); + })); + var sound = Item("PlaySound", "", () => _viewModel.PlaySound = !_viewModel.PlaySound); + sound.IsChecked = _viewModel.PlaySound; + sound.Icon = null; // the check mark shows the state + menu.Items.Add(sound); + menu.Items.Add(new Separator()); + menu.Items.Add(Item("Exit", "", App.Quit)); + + menu.IsOpen = true; + // A popup from the tray only closes on outside clicks if it owns the foreground. + if (PresentationSource.FromVisual(menu) is HwndSource src) SetForegroundWindow(src.Handle); + } + + // ---------- Windows notification buttons ---------- + + private readonly System.Collections.Generic.List _pendingToasts = new(); + private bool _ready; + + /// Snooze / done / open from a toast. Waits until the data is loaded. + public void HandleToast(Microsoft.Toolkit.Uwp.Notifications.ToastArguments args) + { + if (!_ready) + { + _pendingToasts.Add(args); + return; + } + args.TryGetValue("action", out string? action); + args.TryGetValue("id", out string? id); + args.TryGetValue("min", out string? minutes); + args.TryGetValue("lead", out string? lead); + _viewModel.HandleToastAction(action ?? "open", id, minutes, lead == "1"); + if ((action ?? "open") == "open") ShowMainWindow(); + } + private void ShowMainWindow() { Show(); diff --git a/Models/ReminderModels.cs b/Models/ReminderModels.cs index 140822e..8a5d12e 100644 --- a/Models/ReminderModels.cs +++ b/Models/ReminderModels.cs @@ -59,6 +59,33 @@ namespace ReminderOrganizer.Models set { if (SetProperty(ref _recurrenceType, value)) OnPropertyChanged(nameof(AgeText)); } } + private DateTime? _snoozedUntil; + /// Snoozed reminder for recurring entries (the real date stays unchanged). + public DateTime? SnoozedUntil + { + get => _snoozedUntil; + set => SetProperty(ref _snoozedUntil, value); + } + + /// + /// "Remind me again later": one-off tasks move their date; recurring tasks and anniversaries keep their + /// date (it already moved to the next occurrence) and get an extra reminder at now + delay. + /// + /// true for a lead ("in 2 days") reminder: the real date must not move. + public void Snooze(DateTime until, bool keepDate = false) + { + if (IsRecurring || keepDate) + { + SnoozedUntil = until; + } + else + { + ReminderDate = until; + IsNotified = false; + IsPreNotified = true; // the lead reminder is long past + } + } + private int _leadDays; /// Extra reminder this many days before the date (0 = none). public int LeadDays @@ -242,6 +269,13 @@ namespace ReminderOrganizer.Models foreach (var task in folder.Tasks) { if (task.IsNotified) continue; + // snoozed reminder of a recurring entry: fire once, keep the real date + if (task.SnoozedUntil is DateTime snoozed && snoozed <= now) + { + due.Add(new DueReminder(task, task.ReminderDate, false, task.UpcomingAge)); + task.SnoozedUntil = null; + continue; + } if (task.ReminderDate <= now) { due.Add(new DueReminder(task, task.ReminderDate, false, task.UpcomingAge)); @@ -344,6 +378,11 @@ namespace ReminderOrganizer.Models public double? WindowHeight { get; set; } public bool WindowMaximized { get; set; } + /// Morning summary: on/off, hour, last day it was shown. + public bool DailySummary { get; set; } = true; + public int SummaryHour { get; set; } = 8; + public DateTime? LastSummaryDate { get; set; } + /// "list", "compact" or "cards". public string ViewMode { get; set; } = "list"; /// Group the list by month (collapsible). diff --git a/README.md b/README.md index 32c10f0..a8fc28a 100644 --- a/README.md +++ b/README.md @@ -16,17 +16,20 @@ It runs in the system tray (notification area). ("25th anniversary · Silver"), Jubilee, Memorial day, plus your own (Settings → Categories: icon, color, text) - Sidebar **Categories** shows every birthday / wedding … across all folders - Views **list / compact / cards**; **group by month** (click a month to fold it) -- Reminders missed while the app was closed are shown at the next start, with a reminder sound (can be turned off) +- Windows notifications with **snooze** (10 min, 1 hour, tomorrow) and **Done**; missed reminders are shown at the next start, with a reminder sound (can be turned off) +- **Morning summary** once a day (time adjustable): today's entries, birthdays in the next 3 days, overdue items - **Folder colors** and order (drag or context menu); drag a task onto a folder to move it - **Undo** after deleting (Ctrl+Z), shortcuts Ctrl+N (new task), Del, Esc - CSV import/export (`Folder;Name;Description;Date;IsRecurring;RecurrenceType`, date `yyyy-MM-dd HH:mm`) -- **Calendar export (.ics)** for Outlook, Google and Apple Calendar (recurrence + advance reminder included) +- **Calendar import and export (.ics)** for Outlook, Google and Apple Calendar (recurrence, advance reminder, birthdays incl. Google's birthday calendar; re-importing skips existing entries) +- **Data folder selectable** (e.g. OneDrive) – several PCs share the same reminders; changes from another PC are loaded automatically +- Keyboard: arrow keys / Home / End move through the list, Space marks done - Dark/light theme, German/English; the first start follows the Windows settings - Autostart with Windows, starting hidden in the tray (`--minimized`) ## Data -Tasks are stored in `%APPDATA%\ReminderOrganizer\tasks.json`. The app keeps `tasks.json.bak` as a backup +Tasks are stored in `%APPDATA%\ReminderOrganizer\tasks.json`, or in the folder chosen under Settings → Data (pointer file `location.json`). The app keeps `tasks.json.bak` as a backup of the previous save, and saves a broken file as `tasks.json.corrupt-