2026-11-25 13:44:02 +01:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using System;
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Windows;
|
2026-11-25 13:44:02 +01:00
|
|
|
|
using System.Windows.Forms;
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
using Microsoft.Toolkit.Uwp.Notifications;
|
2026-11-25 13:44:02 +01:00
|
|
|
|
|
|
|
|
|
|
namespace ReminderOrganizer.Services
|
|
|
|
|
|
{
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
/// <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>
|
2026-11-25 13:44:02 +01:00
|
|
|
|
public class NotificationService : INotificationService
|
|
|
|
|
|
{
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
private readonly ILocalizationService _loc;
|
|
|
|
|
|
private string? _logoPath;
|
2026-11-25 13:44:02 +01:00
|
|
|
|
|
|
|
|
|
|
public static NotifyIcon? SharedTrayIcon { get; set; }
|
|
|
|
|
|
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
public NotificationService(ILocalizationService localizationService)
|
|
|
|
|
|
{
|
|
|
|
|
|
_loc = localizationService;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-25 13:44:02 +01:00
|
|
|
|
public void ShowNotification(string title, string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
Builder(title, message).AddArgument("action", "open").Show();
|
2026-11-25 13:44:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
System.Diagnostics.Debug.WriteLine($"[Toast] {ex.Message}");
|
|
|
|
|
|
ShowBalloon(title, message);
|
2026-11-25 13:44:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
public void ShowReminder(string title, string message, string taskId, bool isLead)
|
2026-11-25 13:44:02 +01:00
|
|
|
|
{
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
try
|
2026-11-25 13:44:02 +01:00
|
|
|
|
{
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
2026-11-25 13:44:02 +01:00
|
|
|
|
{
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
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);
|
2026-11-25 13:44:02 +01:00
|
|
|
|
}
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
return _logoPath = path;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
2026-11-25 13:44:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
private static void ShowBalloon(string title, string message)
|
2026-11-25 13:44:02 +01:00
|
|
|
|
{
|
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>
2026-11-29 20:37:20 +01:00
|
|
|
|
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}");
|
|
|
|
|
|
}
|
2026-11-25 13:44:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|