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

@@ -23,14 +23,56 @@ namespace ReminderOrganizer.Services
private readonly SemaphoreSlim _writeLock = new(1, 1);
public string DataFilePath { get; }
public string DataFilePath { get; private set; }
public string DataDirectory => Path.GetDirectoryName(DataFilePath)!;
/// <summary>%APPDATA%\ReminderOrganizer – or REMINDER_ORGANIZER_DATA (for tests/screenshots).</summary>
public static string DefaultDataDirectory =>
/// <summary>Time stamp of our own last write – a different one means another PC (sync) changed the file.</summary>
public DateTime LastWriteUtc { get; private set; }
/// <summary>
/// App folder (pointer file, error log): %APPDATA%\ReminderOrganizer – or REMINDER_ORGANIZER_DATA (tests/screenshots).
/// </summary>
public static string AppDirectory =>
Environment.GetEnvironmentVariable("REMINDER_ORGANIZER_DATA") is { Length: > 0 } custom
? custom
: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ReminderOrganizer");
/// <summary>Where tasks.json lives: the folder chosen in Settings (e.g. OneDrive), otherwise the app folder.</summary>
public static string DefaultDataDirectory => ReadPointer(AppDirectory) ?? AppDirectory;
private const string PointerFile = "location.json";
/// <summary>Chosen data folder from location.json, or null (none / folder gone).</summary>
public static string? ReadPointer(string appDirectory)
{
try
{
var file = Path.Combine(appDirectory, PointerFile);
if (!File.Exists(file)) return null;
using var doc = JsonDocument.Parse(File.ReadAllText(file));
var folder = doc.RootElement.TryGetProperty("DataFolder", out var p) ? p.GetString() : null;
return !string.IsNullOrWhiteSpace(folder) && Directory.Exists(folder) ? folder : null;
}
catch
{
return null;
}
}
/// <summary>Stores the data folder; null or the app folder itself removes the pointer.</summary>
public static void WritePointer(string appDirectory, string? folder)
{
Directory.CreateDirectory(appDirectory);
var file = Path.Combine(appDirectory, PointerFile);
if (string.IsNullOrWhiteSpace(folder) ||
string.Equals(Path.GetFullPath(folder).TrimEnd('\\'), Path.GetFullPath(appDirectory).TrimEnd('\\'), StringComparison.OrdinalIgnoreCase))
{
if (File.Exists(file)) File.Delete(file);
return;
}
File.WriteAllText(file, JsonSerializer.Serialize(new { DataFolder = folder }, _jsonOptions));
}
public DataService() : this(DefaultDataDirectory) { }
public DataService(string dataDirectory)
@@ -39,6 +81,62 @@ namespace ReminderOrganizer.Services
DataFilePath = Path.Combine(dataDirectory, "tasks.json");
}
/// <summary>Use another folder from now on (after moving or adopting its tasks.json).</summary>
public void SwitchTo(string dataDirectory)
{
StopWatching();
Directory.CreateDirectory(dataDirectory);
DataFilePath = Path.Combine(dataDirectory, "tasks.json");
LastWriteUtc = File.Exists(DataFilePath) ? File.GetLastWriteTimeUtc(DataFilePath) : default;
}
// ---------- sync: notice changes made by another PC ----------
private FileSystemWatcher? _watcher;
private Timer? _debounce;
/// <summary>Calls <paramref name="onExternalChange"/> (thread pool) when tasks.json changes and it wasn't us.</summary>
public void StartWatching(Action onExternalChange)
{
StopWatching();
if (File.Exists(DataFilePath)) LastWriteUtc = File.GetLastWriteTimeUtc(DataFilePath);
_debounce = new Timer(_ =>
{
try
{
if (IsExternalChange()) onExternalChange();
}
catch { /* file busy – next event */ }
});
_watcher = new FileSystemWatcher(DataDirectory, "tasks.json")
{
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.Size,
EnableRaisingEvents = true
};
FileSystemEventHandler h = (_, _) => _debounce?.Change(1000, Timeout.Infinite); // sync tools write in bursts
_watcher.Changed += h;
_watcher.Created += h;
_watcher.Renamed += (_, _) => _debounce?.Change(1000, Timeout.Infinite);
}
public void StopWatching()
{
_watcher?.Dispose();
_watcher = null;
_debounce?.Dispose();
_debounce = null;
}
/// <summary>True if the file on disk is newer than our own last write.</summary>
public bool IsExternalChange()
{
if (!File.Exists(DataFilePath)) return false;
var stamp = File.GetLastWriteTimeUtc(DataFilePath);
if (Math.Abs((stamp - LastWriteUtc).TotalMilliseconds) < 50) return false;
LastWriteUtc = stamp;
return true;
}
/// <summary>Copies tasks.json from an old location (next to the exe) if no data exists yet.</summary>
public void MigrateFrom(string? legacyDirectory)
{
@@ -105,6 +203,7 @@ namespace ReminderOrganizer.Services
File.Replace(tmp, DataFilePath, DataFilePath + ".bak");
else
File.Move(tmp, DataFilePath);
LastWriteUtc = File.GetLastWriteTimeUtc(DataFilePath); // our own write is not a "sync change"
}
public async Task SaveAsync(AppData data)