app: redesign the stats panel and settings (D8)
agent-review agent review: pass

The panel is now a dashboard: a one-row header with range and provider
controls, a tile per limit window with pace, forecasts, today's share
of the week and the daily budget, per-day week charts with even-pace and
budget lines, token stat tiles with one composition legend, hourly and
daily charts side by side, limit history, and top-8 breakdowns. Colours
follow fixed provider and status tokens instead of the OS accent;
numbers are compact to three significant digits. Settings are grouped
into cards with a sticky footer. Developer feedback on v1.

Refs #5
This commit is contained in:
Florian Schmidt
2026-10-14 22:59:24 +02:00
parent a20d0ab9dc
commit 73f79eb6ac
11 changed files with 1013 additions and 226 deletions
+82 -36
View File
@@ -1,5 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Layout;
using FinalToken.Core;
using FinalToken.Core.StreamDeck;
@@ -7,30 +8,61 @@ namespace FinalToken.App;
public sealed class SettingsWindow : Window
{
public SettingsWindow(Settings initial, PluginInstallStatus status, Func<Settings, Task> save)
public SettingsWindow(Settings initial, PluginInstallStatus status, Func<Settings, Task> save, Action? quit = null)
{
Title = "FinalToken settings"; Width = 620; Height = 800;
var body = Ui.Stack(Ui.Text("Settings", 26)); body.Margin = new Thickness(24);
var refresh = Number("Token refresh (seconds, 1–60)", (decimal)initial.RefreshInterval.TotalSeconds, 1, 60);
var probe = Number("Limit probe (minutes, 1–60)", (decimal)initial.ProbeInterval.TotalMinutes, 1, 60);
var threshold = Number("Pace threshold (points)", (decimal)initial.PaceThreshold, 0.1m, 100);
var ahead = Check("Ahead popups", initial.PopupAhead); var behind = Check("Behind popups", initial.PopupBehind);
var startup = Check("Start with the OS", initial.StartWithOs); var tray = Check("Close to tray", initial.CloseToTray);
var claude = ProviderControls("Claude", initial.Claude); var codex = ProviderControls("Codex", initial.Codex);
body.Children.Add(Ui.Text("Stream Deck", 19));
body.Children.Add(Ui.Text($"{status.State} · shipped {status.ShippedVersion ?? "none"} · installed {status.InstalledVersion ?? "none"}"));
var mode = new ComboBox { ItemsSource = new[] { "Off", "Ask", "Automatic" }, SelectedIndex = (int)initial.StreamDeckInstallMode };
body.Children.Add(mode);
body.Children.Add(Ui.Text("Dismissed plugin version (clear to ask again)"));
var dismissed = new TextBox { Text = initial.DismissedPluginVersion ?? "" }; body.Children.Add(dismissed);
var error = Ui.Text(""); body.Children.Add(error);
var button = new Button { Content = "Save", HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right };
Title = "FinalToken settings"; Width = 760; Height = 900; MinWidth = 600; MinHeight = 500; Ui.Theme(this);
var body = new StackPanel { Spacing = 16, Margin = new Thickness(24) };
body.Children.Add(Ui.Text("Settings", 24));
var general = Ui.Stack(Ui.Text("General", 15));
var refresh = Number(general, "Token refresh (seconds, 1–60)", (decimal)initial.RefreshInterval.TotalSeconds, 1, 60);
var probe = Number(general, "Limit probe (minutes, 1–60)", (decimal)initial.ProbeInterval.TotalMinutes, 1, 60);
var threshold = Number(general, "Pace threshold (points)", (decimal)initial.PaceThreshold, 0.1m, 100);
var startup = Check(general, "Start with the OS", initial.StartWithOs);
var tray = Check(general, "Close to tray", initial.CloseToTray);
body.Children.Add(Ui.Card(general));
var popups = Ui.Stack(Ui.Text("Popups", 15));
var ahead = Check(popups, "Ahead popups", initial.PopupAhead);
var behind = Check(popups, "Behind popups", initial.PopupBehind);
var claudePopups = PopupControls(popups, "Claude", initial.Claude);
var codexPopups = PopupControls(popups, "Codex", initial.Codex);
body.Children.Add(Ui.Card(popups));
var providers = Ui.Stack(Ui.Text("Providers", 15));
var claude = ProviderControls(providers, "Claude", initial.Claude);
var codex = ProviderControls(providers, "Codex", initial.Codex);
body.Children.Add(Ui.Card(providers));
var streamDeck = Ui.Stack(Ui.Text("Stream Deck", 15), Ui.Text($"{status.State} · shipped {status.ShippedVersion ?? "none"} · installed {status.InstalledVersion ?? "none"}", 13, "Secondary"));
var selectedMode = initial.StreamDeckInstallMode;
streamDeck.Children.Add(PanelWindow.Segments(["Off", "Ask", "Automatic"], (int)selectedMode, i => selectedMode = (InstallMode)i));
streamDeck.Children.Add(Ui.Text("Dismissed plugin version (clear to ask again)", 12, "Secondary"));
var dismissed = new TextBox { Text = initial.DismissedPluginVersion ?? "" }; streamDeck.Children.Add(dismissed);
body.Children.Add(Ui.Card(streamDeck));
var about = Ui.Stack(Ui.Text("About", 15), Ui.Text("FinalToken " + typeof(Program).Assembly.GetName().Version?.ToString(3)), Ui.Text(DataPaths.DataDirectory, 12, "Secondary"));
var error = Ui.Text("", 12, "Secondary");
about.Children.Add(Ui.Button("Open folder", () =>
{
try
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(DataPaths.DataDirectory) { UseShellExecute = true });
}
catch (Exception e) when (e is IOException or UnauthorizedAccessException or System.ComponentModel.Win32Exception or InvalidOperationException)
{ error.Text = "Could not open the data folder."; }
}));
body.Children.Add(Ui.Card(about));
var footer = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto,Auto"), ColumnSpacing = 8, Margin = new Thickness(24, 16) };
var quitButton = Ui.Button("Quit FinalToken", () => quit?.Invoke()); quitButton.IsEnabled = quit is not null;
footer.Children.Add(quitButton);
var cancel = Ui.Button("Cancel", Close); Grid.SetColumn(cancel, 2); footer.Children.Add(cancel);
var button = Ui.Button("Save", () => { }); Grid.SetColumn(button, 3); footer.Children.Add(button);
button.Click += async (_, _) =>
{
var value = initial with { RefreshInterval = TimeSpan.FromSeconds((double)(refresh.Value ?? 0)), ProbeInterval = TimeSpan.FromMinutes((double)(probe.Value ?? 0)),
var value = initial with
{
RefreshInterval = TimeSpan.FromSeconds((double)(refresh.Value ?? 0)), ProbeInterval = TimeSpan.FromMinutes((double)(probe.Value ?? 0)),
PaceThreshold = (double)(threshold.Value ?? 0), PopupAhead = ahead.IsChecked == true, PopupBehind = behind.IsChecked == true,
StartWithOs = startup.IsChecked == true, CloseToTray = tray.IsChecked == true, Claude = claude(), Codex = codex(),
StreamDeckInstallMode = (InstallMode)mode.SelectedIndex, DismissedPluginVersion = string.IsNullOrWhiteSpace(dismissed.Text) ? null : dismissed.Text.Trim() };
StartWithOs = startup.IsChecked == true, CloseToTray = tray.IsChecked == true,
Claude = claudePopups(claude()), Codex = codexPopups(codex()), StreamDeckInstallMode = selectedMode,
DismissedPluginVersion = string.IsNullOrWhiteSpace(dismissed.Text) ? null : dismissed.Text.Trim()
};
if (!value.IsValid) { error.Text = "Check the intervals and pace threshold."; return; }
button.IsEnabled = false;
try { await save(value); Close(); }
@@ -38,21 +70,35 @@ public sealed class SettingsWindow : Window
catch (Exception e) when (e is IOException or UnauthorizedAccessException or InvalidOperationException or ArgumentException)
{ error.Text = "Could not apply settings: " + e.Message; button.IsEnabled = true; }
};
body.Children.Add(button); Content = new ScrollViewer { Content = body };
NumericUpDown Number(string label, decimal value, decimal min, decimal max)
{ body.Children.Add(Ui.Text(label)); var c = new NumericUpDown { Value = value, Minimum = min, Maximum = max }; body.Children.Add(c); return c; }
CheckBox Check(string label, bool value)
{ var c = new CheckBox { Content = label, IsChecked = value }; body.Children.Add(c); return c; }
Func<ProviderSettings> ProviderControls(string name, ProviderSettings config)
{
body.Children.Add(Ui.Text(name, 19));
var enabled = Check("Enabled", config.Enabled); var popups = Check("Popups enabled", config.PopupsEnabled);
var pa = Check("Ahead", config.PopupAhead); var pb = Check("Behind", config.PopupBehind);
body.Children.Add(Ui.Text("CLI path (empty uses PATH)"));
var path = new TextBox { Name = name + "CliPath", Text = config.CliPath ?? "" }; body.Children.Add(path);
return () => config with { Enabled = enabled.IsChecked == true, PopupsEnabled = popups.IsChecked == true, PopupAhead = pa.IsChecked == true,
PopupBehind = pb.IsChecked == true, CliPath = string.IsNullOrWhiteSpace(path.Text) ? null : path.Text.Trim() };
}
var dock = new DockPanel();
var bottom = Ui.Stack(error, footer); DockPanel.SetDock(bottom, Dock.Bottom); dock.Children.Add(bottom);
dock.Children.Add(new ScrollViewer { Content = body }); Content = dock;
}
private static NumericUpDown Number(StackPanel parent, string label, decimal value, decimal min, decimal max)
{
var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,160"), ColumnSpacing = 16 };
grid.Children.Add(Ui.Text(label, 13, "Secondary"));
var control = new NumericUpDown { Value = value, Minimum = min, Maximum = max }; Grid.SetColumn(control, 1); grid.Children.Add(control);
parent.Children.Add(grid); return control;
}
private static CheckBox Check(StackPanel parent, string label, bool value)
{
var c = new CheckBox { Content = label, IsChecked = value, Name = label.Replace(" ", "") }; parent.Children.Add(c); return c;
}
private static Func<ProviderSettings, ProviderSettings> PopupControls(StackPanel parent, string name, ProviderSettings config)
{
var row = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 16 };
row.Children.Add(Ui.Text(name));
var enabled = Check(row, "Popups enabled", config.PopupsEnabled);
var ahead = Check(row, "Ahead", config.PopupAhead); var behind = Check(row, "Behind", config.PopupBehind);
parent.Children.Add(row);
return value => value with { PopupsEnabled = enabled.IsChecked == true, PopupAhead = ahead.IsChecked == true, PopupBehind = behind.IsChecked == true };
}
private static Func<ProviderSettings> ProviderControls(StackPanel parent, string name, ProviderSettings config)
{
parent.Children.Add(Ui.Text(name)); var enabled = Check(parent, "Enabled", config.Enabled);
parent.Children.Add(Ui.Text("CLI path (empty uses PATH)", 12, "Secondary"));
var path = new TextBox { Name = name + "CliPath", Text = config.CliPath ?? "" }; parent.Children.Add(path);
return () => config with { Enabled = enabled.IsChecked == true, CliPath = string.IsNullOrWhiteSpace(path.Text) ? null : path.Text.Trim() };
}
}