Files
schmidt.florian c02829e2e1 app: let the settings hide limit windows and give the app an icon (#18)
The developer asked for an option to hide Claude's Fable week and for an
app icon that Windows can use (2026-11-04).

- Core: each provider's settings hold hidden limit windows by window
  series, so a hidden Codex week stays hidden across slot moves (D7, D8).
  Older settings files load with nothing hidden. Hidden windows give no
  pace popups.
- App: Settings → Providers lists each provider's limit windows with a
  Show checkbox, including hidden windows that are absent right now. The
  panel drops hidden windows in one place before it renders and queries
  history; the snapshot and history keep every window (D9).
- App: a usage gauge in the provider colours is the executable's icon,
  the window icon and the tray icon. tools/icon/make_icon.py renders it
  with Pillow, a development-only dependency, into a multi-size ICO and a
  PNG.

Closes #17
2026-11-04 19:41:44 +01:00

78 lines
3.6 KiB
C#

using Xunit;
namespace FinalToken.Core.Tests;
public sealed class HiddenWindowTests
{
private static readonly DateTimeOffset Now = new(2026, 10, 18, 12, 0, 0, TimeSpan.Zero);
private static LimitWindow Week => new(Provider.Codex, "codex:secondary", "Week", 80,
Now.AddDays(3.5), TimeSpan.FromDays(7), Now, "fixture");
[Fact]
public async Task HiddenWindowsRoundTripWithSeriesLengthAndAbsentLabel()
{
using var directory = new TestDirectory();
var settings = new Settings
{
Claude = new() { HiddenWindows = [new("week (fable)", TimeSpan.FromDays(7), "Current week (Fable)"), new("session", null, "Session")] },
Codex = new() { HiddenWindows = [HiddenLimitWindow.For(Week)] }
};
await SettingsFile.SaveAsync(directory.Path, settings, TestContext.Current.CancellationToken);
var diagnostics = new DiagnosticLog();
var loaded = SettingsFile.Load(directory.Path, diagnostics);
Assert.Equal(settings, loaded); Assert.Equal(settings.GetHashCode(), loaded.GetHashCode());
Assert.Equal(settings.Claude.HiddenWindows, loaded.Claude.HiddenWindows);
Assert.Equal(settings.Codex.HiddenWindows, loaded.Codex.HiddenWindows);
Assert.Empty(diagnostics.Recent);
}
[Fact]
public void OldFileHidesNothing()
{
using var directory = new TestDirectory();
directory.Write("settings.json", """{"claude":{"enabled":true},"codex":{"popupAhead":false}}""");
var diagnostics = new DiagnosticLog();
var settings = SettingsFile.Load(directory.Path, diagnostics);
Assert.Empty(settings.Claude.HiddenWindows); Assert.Empty(settings.Codex.HiddenWindows);
Assert.False(settings.Codex.PopupAhead); Assert.False(settings.Codex.IsHidden(Week));
Assert.Empty(diagnostics.Recent);
}
[Fact]
public void CodexWeekStaysHiddenAcrossSlotResetAndLabelChangesButNotLengthOrName()
{
var config = new ProviderSettings { HiddenWindows = [HiddenLimitWindow.For(Week)] };
Assert.True(config.IsHidden(Week));
Assert.True(config.IsHidden(Week with { Id = "codex:primary", ResetsAt = Now.AddDays(7), Label = "Renamed week" }));
Assert.False(config.IsHidden(Week with { Id = "codex:primary", Length = TimeSpan.FromHours(5) }));
Assert.False(config.IsHidden(Week with { Id = "other:secondary" }));
}
[Theory]
[InlineData(80)]
[InlineData(10)]
public void HiddenWindowHasNoAheadOrBehindPopupAcrossSlotMove(double used)
{
var window = Week with { UsedPercent = used, Id = "codex:primary" };
var pace = Pace.Calculate(window, Now);
Assert.NotNull(new PopupDecider().Observe(window, pace, new Settings()));
var settings = new Settings { Codex = new() { HiddenWindows = [HiddenLimitWindow.For(Week)] } };
Assert.Null(new PopupDecider().Observe(window, pace, settings));
Assert.NotNull(new PopupDecider().Observe(window with { Provider = Provider.Claude }, pace, settings));
}
[Theory]
[InlineData("null")]
[InlineData("[null]")]
[InlineData("[{\"name\":\"\",\"label\":\"Week\"}]")]
[InlineData("[{\"name\":\"week\",\"label\":\"Week\",\"length\":\"00:00:00\"}]")]
public void MalformedHiddenWindowsFallBackWithDiagnostic(string hidden)
{
using var directory = new TestDirectory();
directory.Write("settings.json", "{\"claude\":{\"hiddenWindows\":" + hidden + "}}");
var diagnostics = new DiagnosticLog();
Assert.Empty(SettingsFile.Load(directory.Path, diagnostics).Claude.HiddenWindows);
Assert.Equal("settings-defaults", Assert.Single(diagnostics.Recent).Code);
}
}