2026-11-25 13:44:02 +01:00
|
|
|
#nullable enable
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using ReminderOrganizer.Services;
|
|
|
|
|
using ReminderOrganizer.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace ReminderOrganizer
|
|
|
|
|
{
|
|
|
|
|
public partial class App : Application
|
|
|
|
|
{
|
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnStartup(e);
|
|
|
|
|
|
Fix data loss risk, reminder bugs; theme, credits, tests
- Store tasks in %APPDATA% (single-file extract dir lost data on update),
atomic serialized saves, corrupt-file backup, migration of old tasks.json
- Reminders without description never showed (empty balloon text threw)
- Catch up missed reminders on start; monthly recurrence no longer drifts
- Task dialog: date pick kept 00:00, cancel leaked recurrence changes
- CSV import understands quoted fields written by export
- Confirm before deleting; name folders on create; tasks sorted by date
- Single instance, autostart starts hidden in tray, tray icon disposed
- Theme helper for all dialogs, MDL2/Path icons instead of emojis,
fixed folder selection/badge, localized counts and messages
- Credits (c) Michael Media + Discord link, exe Company/Copyright
- Locales embedded; xUnit tests (24); README, CLAUDE.md, sprite-generator
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 14:08:53 +01:00
|
|
|
// Only one instance: a second start would show duplicate reminders and race on tasks.json.
|
2026-11-25 14:52:25 +01:00
|
|
|
// Test runs with their own data folder (REMINDER_ORGANIZER_DATA) get their own lock.
|
|
|
|
|
var mutexName = "MichaelMedia.ReminderOrganizer" +
|
|
|
|
|
(Environment.GetEnvironmentVariable("REMINDER_ORGANIZER_DATA") is { Length: > 0 } d ? "." + d.GetHashCode() : "");
|
|
|
|
|
_singleInstance = new System.Threading.Mutex(true, mutexName, out var isFirst);
|
Fix data loss risk, reminder bugs; theme, credits, tests
- Store tasks in %APPDATA% (single-file extract dir lost data on update),
atomic serialized saves, corrupt-file backup, migration of old tasks.json
- Reminders without description never showed (empty balloon text threw)
- Catch up missed reminders on start; monthly recurrence no longer drifts
- Task dialog: date pick kept 00:00, cancel leaked recurrence changes
- CSV import understands quoted fields written by export
- Confirm before deleting; name folders on create; tasks sorted by date
- Single instance, autostart starts hidden in tray, tray icon disposed
- Theme helper for all dialogs, MDL2/Path icons instead of emojis,
fixed folder selection/badge, localized counts and messages
- Credits (c) Michael Media + Discord link, exe Company/Copyright
- Locales embedded; xUnit tests (24); README, CLAUDE.md, sprite-generator
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 14:08:53 +01:00
|
|
|
if (!isFirst)
|
|
|
|
|
{
|
|
|
|
|
Shutdown();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-25 13:44:02 +01:00
|
|
|
SetupExceptionHandling();
|
|
|
|
|
ServiceLocator.Initialize();
|
Fix data loss risk, reminder bugs; theme, credits, tests
- Store tasks in %APPDATA% (single-file extract dir lost data on update),
atomic serialized saves, corrupt-file backup, migration of old tasks.json
- Reminders without description never showed (empty balloon text threw)
- Catch up missed reminders on start; monthly recurrence no longer drifts
- Task dialog: date pick kept 00:00, cancel leaked recurrence changes
- CSV import understands quoted fields written by export
- Confirm before deleting; name folders on create; tasks sorted by date
- Single instance, autostart starts hidden in tray, tray icon disposed
- Theme helper for all dialogs, MDL2/Path icons instead of emojis,
fixed folder selection/badge, localized counts and messages
- Credits (c) Michael Media + Discord link, exe Company/Copyright
- Locales embedded; xUnit tests (24); README, CLAUDE.md, sprite-generator
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 14:08:53 +01:00
|
|
|
|
|
|
|
|
var main = new MainWindow();
|
|
|
|
|
MainWindow = main;
|
|
|
|
|
// Autostart passes --minimized: start straight into the tray.
|
|
|
|
|
if (Array.IndexOf(e.Args, "--minimized") >= 0)
|
|
|
|
|
main.StartHidden();
|
|
|
|
|
else
|
|
|
|
|
main.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private System.Threading.Mutex? _singleInstance;
|
|
|
|
|
|
Professional redesign: native window, settings, calmer UI
- WindowChrome: resizable, snap layouts, native shadow, DWM rounded
corners; size/position remembered; fade-in after load (no theme flash)
- Menu bar replaced by a settings window (theme system/light/dark,
language, sound, autostart, categories, data, shortcuts, about)
- Shared styles in Themes/Controls.xaml; neutral palette with one accent
applied to Application.Resources (context menus/tooltips themed)
- Rows: To-Do style check left, title + details, relative date right,
actions on hover, visible selection (Enter edits, Del deletes)
- No glow/scale effects; subtle animations (dialogs, snackbar, chevrons)
- Checking a recurring task moves it to the next date (with undo)
- Themed combo box, date picker, check box; neutral dialog headers
- New flat app icon (tools/make_icon.py)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 18:10:45 +01:00
|
|
|
/// <summary>Really exit (tray menu / "Exit"): the main window otherwise only hides to the tray.</summary>
|
|
|
|
|
public static void Quit()
|
|
|
|
|
{
|
|
|
|
|
(Current.MainWindow as MainWindow)?.AllowClose();
|
|
|
|
|
Current.Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
Fix data loss risk, reminder bugs; theme, credits, tests
- Store tasks in %APPDATA% (single-file extract dir lost data on update),
atomic serialized saves, corrupt-file backup, migration of old tasks.json
- Reminders without description never showed (empty balloon text threw)
- Catch up missed reminders on start; monthly recurrence no longer drifts
- Task dialog: date pick kept 00:00, cancel leaked recurrence changes
- CSV import understands quoted fields written by export
- Confirm before deleting; name folders on create; tasks sorted by date
- Single instance, autostart starts hidden in tray, tray icon disposed
- Theme helper for all dialogs, MDL2/Path icons instead of emojis,
fixed folder selection/badge, localized counts and messages
- Credits (c) Michael Media + Discord link, exe Company/Copyright
- Locales embedded; xUnit tests (24); README, CLAUDE.md, sprite-generator
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 14:08:53 +01:00
|
|
|
protected override void OnExit(ExitEventArgs e)
|
|
|
|
|
{
|
2026-11-25 14:52:25 +01:00
|
|
|
(MainWindow as MainWindow)?.OnAppExit();
|
Fix data loss risk, reminder bugs; theme, credits, tests
- Store tasks in %APPDATA% (single-file extract dir lost data on update),
atomic serialized saves, corrupt-file backup, migration of old tasks.json
- Reminders without description never showed (empty balloon text threw)
- Catch up missed reminders on start; monthly recurrence no longer drifts
- Task dialog: date pick kept 00:00, cancel leaked recurrence changes
- CSV import understands quoted fields written by export
- Confirm before deleting; name folders on create; tasks sorted by date
- Single instance, autostart starts hidden in tray, tray icon disposed
- Theme helper for all dialogs, MDL2/Path icons instead of emojis,
fixed folder selection/badge, localized counts and messages
- Credits (c) Michael Media + Discord link, exe Company/Copyright
- Locales embedded; xUnit tests (24); README, CLAUDE.md, sprite-generator
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 14:08:53 +01:00
|
|
|
Services.NotificationService.SharedTrayIcon?.Dispose();
|
|
|
|
|
_singleInstance?.Dispose();
|
|
|
|
|
base.OnExit(e);
|
2026-11-25 13:44:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetupExceptionHandling()
|
|
|
|
|
{
|
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
|
|
|
|
|
{
|
|
|
|
|
LogException((Exception)e.ExceptionObject, "AppDomain.UnhandledException");
|
|
|
|
|
if (e.IsTerminating)
|
|
|
|
|
Environment.Exit(1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DispatcherUnhandledException += (s, e) =>
|
|
|
|
|
{
|
|
|
|
|
LogException(e.Exception, "DispatcherUnhandledException");
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
MessageBox.Show($"An unexpected error occurred:\n{e.Exception.Message}",
|
|
|
|
|
"Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TaskScheduler.UnobservedTaskException += (s, e) =>
|
|
|
|
|
{
|
|
|
|
|
LogException(e.Exception, "UnobservedTaskException");
|
|
|
|
|
e.SetObserved();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void LogException(Exception ex, string source)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
Fix data loss risk, reminder bugs; theme, credits, tests
- Store tasks in %APPDATA% (single-file extract dir lost data on update),
atomic serialized saves, corrupt-file backup, migration of old tasks.json
- Reminders without description never showed (empty balloon text threw)
- Catch up missed reminders on start; monthly recurrence no longer drifts
- Task dialog: date pick kept 00:00, cancel leaked recurrence changes
- CSV import understands quoted fields written by export
- Confirm before deleting; name folders on create; tasks sorted by date
- Single instance, autostart starts hidden in tray, tray icon disposed
- Theme helper for all dialogs, MDL2/Path icons instead of emojis,
fixed folder selection/badge, localized counts and messages
- Credits (c) Michael Media + Discord link, exe Company/Copyright
- Locales embedded; xUnit tests (24); README, CLAUDE.md, sprite-generator
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 14:08:53 +01:00
|
|
|
Directory.CreateDirectory(DataService.DefaultDataDirectory);
|
|
|
|
|
var logPath = Path.Combine(DataService.DefaultDataDirectory, "error.log");
|
2026-11-25 13:44:02 +01:00
|
|
|
var logEntry = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{source}]\n{ex}\n\n";
|
|
|
|
|
File.AppendAllText(logPath, logEntry);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|