This commit is contained in:
2025-10-26 10:40:21 -05:00
commit 45b9d70c90
14 changed files with 1043 additions and 0 deletions

64
MainWindow.xaml.cs Normal file
View File

@@ -0,0 +1,64 @@
using System;
using System.Linq;
using System.Windows;
namespace Bedtimer
{
public partial class MainWindow : Window
{
private Config _cfg = null!;
public MainWindow()
{
InitializeComponent();
_cfg = Config.LoadOrCreate();
BedHour.ItemsSource = Enumerable.Range(1, 12);
BedMinute.ItemsSource = new[] { "00", "05", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55" };
AmPm.ItemsSource = new[] { "AM", "PM" };
// load values
var (h, m, am) = ToClock(_cfg.BedMinutes);
BedHour.SelectedItem = h;
BedMinute.SelectedItem = m.ToString("00");
AmPm.SelectedItem = am ? "AM" : "PM";
WarnLead.Text = _cfg.WarnLead.ToString();
FlashLead.Text = _cfg.FlashLead.ToString();
LockDelay.Text = _cfg.LockDelay.ToString();
}
private static (int hour, int minute, bool am) ToClock(int minutes)
{
int hh24 = minutes / 60;
int mm = minutes % 60;
bool am = hh24 < 12;
int hh12 = hh24 % 12; if (hh12 == 0) hh12 = 12;
return (hh12, mm, am);
}
private static int ToMinutes(int hour12, int minute, bool am)
{
int hh24 = (hour12 % 12) + (am ? 0 : 12);
return hh24 * 60 + minute;
}
private void Save_Click(object sender, RoutedEventArgs e)
{
int hour = (int)(BedHour.SelectedItem ?? 10);
int minute = int.Parse((string?)BedMinute.SelectedItem ?? "30");
bool am = ((string?)AmPm.SelectedItem ?? "PM") == "AM";
_cfg.BedMinutes = ToMinutes(hour, minute, am);
_cfg.WarnLead = int.TryParse(WarnLead.Text, out var w) ? Math.Max(1, w) : 60;
_cfg.FlashLead = int.TryParse(FlashLead.Text, out var f) ? Math.Max(1, f) : 20;
_cfg.LockDelay = int.TryParse(LockDelay.Text, out var d) ? Math.Max(0, d) : 5;
_cfg.Save(); // non-admin -> triggers UAC; admin -> writes directly
_cfg = Config.LoadOrCreate();
MessageBox.Show(this, "Saved.", "Bedtimer", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void Close_Click(object sender, RoutedEventArgs e) => Close();
}
}