feat: add FinalToken v1 for Claude and Codex usage (#2)
FinalToken v1: a NativeAOT tray app for Windows 11 and CachyOS that tracks Claude Code and Codex usage and limits through their CLIs only, with no provider sign-in and no tokens (R1-R7, D1-D11). - Core: incremental collectors for Claude transcripts and Codex rollouts, limit probes through `claude -p /usage` and `codex app-server`, a journaled history store, the refresh engine, pace and popup decisions, and the snapshot.json contract. - App (Avalonia): stats panel with limit bars, pace, projections, token totals, charts, limit history and breakdowns; tray, settings, non-activating pace popups, single-instance activation, start with the OS, and the Off/Ask/Automatic Stream Deck plugin install. - Stream Deck plugin (SDK v2, NativeAOT) for Elgato and OpenDeck. - finaltoken-cli, tools/publish.py, the documentation check and the agent review workflow. Closes #1
This commit was merged in pull request #2.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using FinalToken.Core;
|
||||
using FinalToken.Core.StreamDeck;
|
||||
|
||||
namespace FinalToken.App;
|
||||
|
||||
public sealed class SettingsWindow : Window
|
||||
{
|
||||
public SettingsWindow(Settings initial, PluginInstallStatus status, Func<Settings, Task> save)
|
||||
{
|
||||
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 };
|
||||
button.Click += async (_, _) =>
|
||||
{
|
||||
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() };
|
||||
if (!value.IsValid) { error.Text = "Check the intervals and pace threshold."; return; }
|
||||
button.IsEnabled = false;
|
||||
try { await save(value); Close(); }
|
||||
catch (OperationCanceledException) { error.Text = "Settings save was cancelled."; button.IsEnabled = true; }
|
||||
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() };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user