Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
183bbc2de9
|
No files matched your search
@@ -37,6 +37,15 @@ numeric core and does not move; the heading is the full version — corrected 20
|
||||
|
||||
### Changed
|
||||
|
||||
- **Games opens at once from any page** (owner request 2026-11-06: switching to Games stalled 0.5–1.5 s). The window
|
||||
keeps the library page it built and shows it again on every later visit, reading the library again behind it; the
|
||||
library is read off the UI thread; the cards appear before the executables are checked — a USB drive that sleeps
|
||||
took a second or more to answer, and no card was shown until every one had — and each card gets its *Not installed*
|
||||
pill when its check answers; a read keeps every card that would look the same instead of rebuilding them all; the
|
||||
list view builds only the rows on screen (`spike-notes` §27).
|
||||
- **Changing the language keeps the page you are on** — Settings, after a change made there. The App remembered only
|
||||
the pages it opened from code, so the language changed on Settings came back on the last game page opened
|
||||
(`src/FrameLedger.App/Services/ShellHost.cs`).
|
||||
- **DLSS 5 is named where the game ran it** (owner decision D84, amending D64). The owner's Hogwarts Legacy, Neural
|
||||
Rendering on, loaded DLSS 5's runtime (`nvngx_dlssnr.dll` 310.9.16.0, from the game's folder) and the session could say
|
||||
only *DLSS 5 runtime loaded* — nothing measured whether it ran. The Overlay's Streamline hook now decodes DLSS 5's
|
||||
|
||||
+8
-1
@@ -305,7 +305,14 @@ All screens are `Page`s registered with the navigation page provider and navigat
|
||||
> message at once in its one snackbar, so only the last name stayed on screen. And only the newest read of the library is
|
||||
> shown: reads overlap — a session that ends, an import, a removal — and the one that started first could finish last,
|
||||
> its executable checks waiting on a slow drive, and put back a removed game's card (`GamesViewModel.LoadAsync`,
|
||||
> `GamesViewModelTests.AnOlderReadThatFinishesLastIsNotShownOverANewerOne`)*). **The page reloads by itself** while it is on screen when a session ends (`SessionCompleted`) or an
|
||||
> `GamesViewModelTests.AnOlderReadThatFinishesLastIsNotShownOverANewerOne`)*). *(beta.34, owner request 2026-11-06 —
|
||||
> "switching to Games stalls 0.5–1.5 s", `spike-notes` §27: the window keeps the page it built and shows it again on
|
||||
> every later visit, reading the library again behind it; the library is read on the thread pool; the cards appear
|
||||
> before any executable is checked — 39 of the owner's 41 Steam games are on a USB drive that sleeps — and each card
|
||||
> gets its *Not installed* pill when its check answers; a read keeps every card that would look the same; the list
|
||||
> view is bounded (`MaxHeight` 640) so it builds the rows on screen. `GamesViewModelTests`
|
||||
> `.TheCardsComeBeforeTheExecutableChecksAndThePillAfter`, `.APageShownAgainReadsTheLibraryAndKeepsTheCardsThatLookTheSame`,
|
||||
> `WindowPageCacheTests`.)* **The page reloads by itself** while it is on screen when a session ends (`SessionCompleted`) or an
|
||||
> import adds games (`LibraryChanges` — navigating to the page already on screen does nothing in WPF UI 4.3.0, so an
|
||||
> import from the menu never showed until the page was left). **Import** (FR-1.2): the games already in the library — at
|
||||
> this path or under another drive letter — are hidden by default (*Show the N games already in the library* brings them
|
||||
|
||||
@@ -17,6 +17,10 @@ Languages: **en** (neutral/default) · **vi** · **ja**. Same `.resx` pattern as
|
||||
- One `Strings.resx` (+ `Strings.vi.resx`, `Strings.ja.resx`) per assembly that has user-visible text (`App`, `Shared` ~~for error codes~~ for the safety family, the `Safety_*` keys — corrected 2026-10-04). Access through a generated strongly-typed class; **no string literals in XAML/C# for user-visible text** (analyzer TODO: Meziantou MA0011/manual review in PR checklist). **As built (P3 PR-2, 2026-09-13):** the class is `Strings.Designer.cs`, written by `tools/resx-gen.ps1 -Resx <file>` and **committed** — not the SDK's `ResXFileCodeGenerator`, which the SDK-style WPF project does not run — with `Culture`, `ResourceManager`, `Keys`, and one property per key; the audit below fails when it is stale. The first family is `src/FrameLedger.App/Strings.resx` (65 keys); `Shared`'s arrives with PR-4's `Safety_*` text, because an empty family is what the audit refuses.
|
||||
- XAML binding via `{x:Static res:Strings.Key}` ~~plus a `LocalizeExtension` for the few dynamic cases~~ *(corrected 2026-10-04: no `LocalizeExtension` exists; text that varies is composed in the view model from `Strings.*`)*.
|
||||
- **Runtime switching:** setting change → set `CultureInfo.CurrentUICulture` + `Thread` defaults → re-create the main window shell (cheap; state preserved via VM). Persist in `settings`.
|
||||
**The new window opens on the page that was on screen** *(beta.34, owner request 2026-11-06)* — Settings, after a
|
||||
change made there. `ShellHost` remembered only the pages opened from code (`PageNavigator`), never a click in the
|
||||
pane, so a language changed on Settings brought back the last game page opened; it now notes every page the live
|
||||
window's NavigationView shows (`ShellHost.NoteShown`).
|
||||
**Two kinds of text did not follow, until beta.15:** a list of choices built once in a static (Settings' themes and update
|
||||
channels, the Logs page's two lists, the Games page's sort order — `x:Static` read the list built in the language the
|
||||
App started in), and the singletons that outlive the rebuilt window (the tray's menu, the title bar's Agent pill and the
|
||||
|
||||
@@ -115,6 +115,14 @@ Code-behind wires services once: `navigationService.SetNavigationControl(RootNav
|
||||
- Navigate **only** via `INavigationService.Navigate(typeof(SomePage))` — never manipulate `Frame` directly, never `new` a Page.
|
||||
- Pages implement `INavigableView<TViewModel>` with `ViewModel` injected via constructor DI; `DataContext = this` in the page constructor (WPF UI template idiom) so bindings read `ViewModel.*`.
|
||||
- Page state: pages are Transient; anything that must survive navigation lives in the ViewModel-backing services/DB, not the Page.
|
||||
**Except the library, since beta.34** (owner request 2026-11-06, "Games stalls 0.5–1.5 s"; `spike-notes` §27): the window
|
||||
keeps the `GamesPage` it built — `Services.WindowPageCache`, the window's own `INavigationViewPageProvider`, set after
|
||||
`INavigationService.SetNavigationControl` (which hands the NavigationView the container's provider) — and its view model
|
||||
reads the library again each time the page is shown (`GamesViewModel.Attach`). Still Transient in the container; one
|
||||
instance per window, so a language change's new window builds its own in the new language. **Not**
|
||||
`NavigationViewItem.NavigationCacheMode`: WPF UI 4.3.0 reads it only when the NavigationView has neither a service
|
||||
provider nor a page provider (`NavigationView.Navigation.cs`, `GetNavigationItemInstance`), and this App sets one — the
|
||||
attribute would have changed nothing.
|
||||
|
||||
## Control mapping (always prefer these)
|
||||
|
||||
|
||||
@@ -50,3 +50,4 @@ Each section below lives in its own file under `docs/spike-notes/`, moved verbat
|
||||
| §24 | The whole gate on .NET 11 RC3 — what the alpha line's SDK asks of the source (2026-10-31, beta.32, D73–D76) | [`spike-notes/24-dotnet11-probe.md`](spike-notes/24-dotnet11-probe.md) |
|
||||
| §25 | Xbox app / Microsoft Store (GDK) titles — the layout, the launch chain, the image paths (2026-11-03, beta.33, D77–D82) | [`spike-notes/25-xbox-gdk.md`](spike-notes/25-xbox-gdk.md) |
|
||||
| §26 | DLSS 5 on Hogwarts Legacy, Dynamic frame generation on Phantom Blade Zero, and Streamline 2.12 → 2.14.16 (2026-11-06, beta.34, D83, D84) | [`spike-notes/26-dlss5-dynamic-streamline.md`](spike-notes/26-dlss5-dynamic-streamline.md) |
|
||||
| §27 | Switching to Games, and a language change that lands elsewhere (2026-11-06, beta.34) | [`spike-notes/27-games-page-2026-11-06.md`](spike-notes/27-games-page-2026-11-06.md) |
|
||||
@@ -0,0 +1,41 @@
|
||||
## 27 · Switching to Games, and a language change that lands elsewhere *(2026-11-06, beta.34)*
|
||||
|
||||
**Why this was measured.** The owner, 2026-11-06: switching from any page to Games stalls about 0.5–1.5 s before the
|
||||
page appears; and changing the language in Settings brings back the last content page (a game's detail) instead of
|
||||
Settings. §21 (beta.23) had measured the library at 275 ms for 48 games and left it, the grid non-virtualizing by the
|
||||
owner's decision (2026-10-15); the library has 65 games now.
|
||||
|
||||
**What the code showed** (read, then measured): every page is transient and rebuilt per visit; `GamesViewModel` read the
|
||||
settings, the games and the per-game session summary on the UI thread (Microsoft.Data.Sqlite completes its asynchronous
|
||||
calls synchronously), then asked for every executable's file **and showed no card until all had answered** — 39 of the
|
||||
owner's 41 Steam games are on the USB drive D:, which sleeps — and cleared and re-added every card on each read; the list
|
||||
view's `DataGrid` had no height bound and built every row. WPF UI's `NavigationCacheMode` would not have helped: 4.3.0
|
||||
reads it only when the NavigationView has neither a service provider nor a page provider, and this App sets one. The
|
||||
language: `ShellHost` remembered only pages opened from code (`PageNavigator`), never a pane click.
|
||||
|
||||
**The decision table, written before the runs:** fix what keeps the first card from appearing, what rebuilds a page on
|
||||
every visit, and what blocks the UI thread ≥ 50 ms; leave the grid non-virtualizing (the owner's decision); record the
|
||||
rest.
|
||||
|
||||
**How.** A scratch xUnit test over the App's own `GamesViewModel` and `GamesPage` (not committed — it times, and a timing
|
||||
assertion in CI is a flake), Release, on the dev PC of §21: a scratch ledger shaped like the owner's — 65 games, a third
|
||||
with a session — with the first executable check held **800 ms** (a USB drive waking) and every later one answering at
|
||||
once. Seven iterations a run, the median; three runs a side, the code before this change (PR-3's tree) and after it.
|
||||
*First cards*: from the view model's construction to all 65 cards listed. *Build*: a new page laid out at 1200×900 with
|
||||
its 65 cards. *Revisit*: before, a new page again (every visit built one); after, the kept page laid out again.
|
||||
|
||||
| | before (three runs) | after (three runs) |
|
||||
|---|---|---|
|
||||
| First cards | 822 – 830 ms | 10 – 15 ms |
|
||||
| Build (first visit) | 165 – 197 ms | 164 – 223 ms — the same work, run-to-run noise |
|
||||
| Revisit | 181 – 215 ms | 15 – 16 ms |
|
||||
|
||||
**Built** (beta.34): the window keeps the library page it built (`Services.WindowPageCache`, the window's own page
|
||||
provider, set after `INavigationService.SetNavigationControl`) and the page reads the library again each time it is shown
|
||||
(`GamesViewModel.Attach`); the library is read on the thread pool; the cards are listed first and the executable checks
|
||||
follow, each card getting its *Not installed* pill when its check answers; a read keeps every card that would look the
|
||||
same (`GameCardViewModel.LooksLike`, `GamesViewModel.Sync` — no `Clear`); the list view is bounded (`MaxHeight` 640).
|
||||
`ShellHost` notes every page the live window shows, so a rebuild opens on Settings after a change made there.
|
||||
|
||||
**Left as it was:** the first visit's build (≈ 2.5–3.4 ms a card at 65) — the non-virtualizing grid's cost, unchanged by
|
||||
decision; a page kept per window holds its 65 cards' visuals for the window's life.
|
||||
@@ -45,8 +45,11 @@ public partial class MainWindow : FluentWindow
|
||||
theme.Apply(appearance.Theme, null);
|
||||
InitializeComponent();
|
||||
|
||||
RootNavigation.SetPageProviderService(pages);
|
||||
navigation.SetNavigationControl(RootNavigation);
|
||||
// beta.34: this window's own provider, set AFTER SetNavigationControl — which hands the NavigationView the
|
||||
// container's provider (upstream 4.3.0 NavigationService.SetNavigationControl) and would replace one set before it.
|
||||
// It keeps the library page for the window's life (WindowPageCache); every other page is the container's.
|
||||
RootNavigation.SetPageProviderService(new WindowPageCache(pages));
|
||||
snackbar.SetSnackbarPresenter(SnackbarPresenter);
|
||||
dialogs.SetDialogHost(DialogHost);
|
||||
|
||||
|
||||
@@ -123,8 +123,10 @@
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<!-- The list: one row per game across the width; double-click or Enter opens it. -->
|
||||
<DataGrid x:Name="GameList" Margin="0,16,0,0" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"
|
||||
<!-- The list: one row per game across the width; double-click or Enter opens it. Bounded since beta.34, as the
|
||||
Sessions grid is since beta.23: inside the page's scroller it was measured with no height limit and built every
|
||||
row, a Play button each (spike-notes §21, §27). -->
|
||||
<DataGrid x:Name="GameList" Margin="0,16,0,0" MaxHeight="640" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"
|
||||
CanUserSortColumns="False" HeadersVisibility="Column" IsReadOnly="True" SelectionMode="Single"
|
||||
ItemsSource="{Binding ViewModel.Games}"
|
||||
MouseDoubleClick="OnListDoubleClick" KeyDown="OnListKeyDown"
|
||||
|
||||
@@ -35,6 +35,10 @@ public sealed class ShellHost(IServiceProvider services, INavigationService navi
|
||||
MainWindow window = services.GetRequiredService<MainWindow>();
|
||||
window.Closing += OnClosing;
|
||||
window.Closed += OnClosed;
|
||||
// beta.34 (owner request 2026-11-06): every page the window shows is the one a rebuild opens on — a click in the pane
|
||||
// included, which never went through PageNavigator. A language changed on Settings stays on Settings; it came back
|
||||
// on the last page opened from code (a game's page, typically).
|
||||
window.RootNavigation.Navigated += (_, e) => NoteShown(ReferenceEquals(window, _current), e.Page);
|
||||
_current = window;
|
||||
window.Show();
|
||||
Interlocked.Exchange(ref _handle, new System.Windows.Interop.WindowInteropHelper(window).Handle);
|
||||
@@ -71,6 +75,21 @@ public sealed class ShellHost(IServiceProvider services, INavigationService navi
|
||||
/// <summary>The page the shell will open on, kept across a rebuild.</summary>
|
||||
public void Remember(Type page) => _page = page;
|
||||
|
||||
/// <summary>The page a rebuild opens on (beta.34: the page on screen).</summary>
|
||||
internal Type Page => _page;
|
||||
|
||||
/// <summary>
|
||||
/// A page the live window shows (beta.34): remembered whichever way it was reached — the pane, the keyboard, a link, code.
|
||||
/// The old window of a rebuild, closing, changes nothing.
|
||||
/// </summary>
|
||||
internal void NoteShown(bool live, object? page)
|
||||
{
|
||||
if (live && page is not null)
|
||||
{
|
||||
_page = page.GetType();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A new window in the current UI culture; the old one closes after the new one is up. The long-lived pieces that
|
||||
/// read their text once — the tray's menu, the Agent pill — read it again (<see cref="ILanguageFollower"/>, beta.15).
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
||||
|
||||
using FrameLedger.App.Pages;
|
||||
using Wpf.Ui.Abstractions;
|
||||
|
||||
namespace FrameLedger.App.Services;
|
||||
|
||||
/// <summary>
|
||||
/// The window's page provider (beta.34, owner request 2026-11-06: "switching to Games stalls 0.5–1.5 s"): the container's,
|
||||
/// except that the library page is built once per window and shown again on every later visit — its cards already laid
|
||||
/// out — and reads the library again in the background (<see cref="ViewModels.GamesViewModel.Attach"/>).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>Why not WPF UI's own cache.</b> <c>NavigationViewItem.NavigationCacheMode</c> is read only when the NavigationView has
|
||||
/// neither a service provider nor a page provider (upstream 4.3.0 <c>NavigationView.Navigation.cs</c>,
|
||||
/// <c>GetNavigationItemInstance</c>): this App sets a page provider, so the attribute would have changed nothing.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Why per window.</b> A language change builds a new window (<see cref="ShellHost.Rebuild"/>) and shows it before the
|
||||
/// old one closes: a page shared between them would be asked into a second frame while the first still holds it, and would
|
||||
/// keep the old language's text. One instance of this class per <see cref="MainWindow"/> keeps both apart — the new window
|
||||
/// builds its own page in the new language.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The pages stay transient in the container (<c>16_WPFUI_SYNTAX</c> §Navigation); only <see cref="Kept"/> are held, and
|
||||
/// only by the window that built them.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class WindowPageCache(INavigationViewPageProvider inner) : INavigationViewPageProvider
|
||||
{
|
||||
private readonly INavigationViewPageProvider _inner = inner ?? throw new ArgumentNullException(nameof(inner));
|
||||
private readonly Dictionary<Type, object> _kept = [];
|
||||
|
||||
/// <summary>The pages a window keeps: the library, the one page whose build grows with the data (<c>spike-notes</c> §21, §27).</summary>
|
||||
public static IReadOnlySet<Type> Kept { get; } = new HashSet<Type> { typeof(GamesPage) };
|
||||
|
||||
public object? GetPage(Type pageType)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(pageType);
|
||||
if (!Kept.Contains(pageType))
|
||||
{
|
||||
return _inner.GetPage(pageType);
|
||||
}
|
||||
|
||||
if (_kept.TryGetValue(pageType, out object? page))
|
||||
{
|
||||
return page;
|
||||
}
|
||||
|
||||
page = _inner.GetPage(pageType);
|
||||
if (page is not null)
|
||||
{
|
||||
_kept[pageType] = page;
|
||||
}
|
||||
|
||||
return page;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using FrameLedger.App.Services;
|
||||
|
||||
namespace FrameLedger.App.ViewModels;
|
||||
@@ -12,17 +13,28 @@ namespace FrameLedger.App.ViewModels;
|
||||
/// playtime, last played, hooking state — or, since 2026-09-23, "Not recorded" in its place for an entry whose recording is
|
||||
/// off, and since 2026-09-25 "Anti-cheat" for one the guard found anti-cheat in; since beta.11 "Not installed" beside it
|
||||
/// when its executable is not on disk (<see cref="GameLibrary.ExecutableExists"/>, read when the library is listed, never
|
||||
/// stored), with the game page's own words for why (<see cref="Formats.ExecutableMissingText"/>).
|
||||
/// stored), with the game page's own words for why (<see cref="Formats.ExecutableMissingText"/>). Since beta.34 a card is
|
||||
/// shown before its executable is checked and gets the pill when the check answers (<see cref="SetInstalled"/>): a drive
|
||||
/// that sleeps took a second to say, and no card appeared until every one had.
|
||||
/// </summary>
|
||||
[SuppressMessage("Performance", "CA1863:Use 'CompositeFormat'", Justification = "the format strings are resources that follow the UI culture, which changes at runtime")]
|
||||
public sealed class GameCardViewModel
|
||||
public sealed partial class GameCardViewModel : ObservableObject
|
||||
{
|
||||
/// <summary>beta.11: the "Not installed" pill shows — the file, or the drive it was on, is not there now.</summary>
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(StatusText))]
|
||||
private bool _notInstalled;
|
||||
|
||||
/// <summary>What the pill means here — the drive that is not connected, or the path the file is gone from; null when installed.</summary>
|
||||
[ObservableProperty]
|
||||
private string? _notInstalledToolTip;
|
||||
|
||||
public GameCardViewModel(GameCard card, bool installed = true)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(card);
|
||||
Card = card;
|
||||
NotInstalled = !installed;
|
||||
NotInstalledToolTip = installed ? null : Formats.ExecutableMissingText(card.Row.Fingerprint.ExePath);
|
||||
_notInstalled = !installed;
|
||||
_notInstalledToolTip = installed ? null : Formats.ExecutableMissingText(card.Row.Fingerprint.ExePath);
|
||||
Id = card.Row.Id;
|
||||
Name = card.Row.Name;
|
||||
PlatformText = Formats.Platform(card.Row.Platform);
|
||||
@@ -99,12 +111,33 @@ public sealed class GameCardViewModel
|
||||
/// <summary>The list view's last-played cell: the date alone, or "not played yet".</summary>
|
||||
public string LastPlayedValue { get; }
|
||||
|
||||
/// <summary>beta.11: the "Not installed" pill shows — the file, or the drive it was on, is not there now.</summary>
|
||||
public bool NotInstalled { get; }
|
||||
|
||||
/// <summary>What the pill means here — the drive that is not connected, or the path the file is gone from; null when installed.</summary>
|
||||
public string? NotInstalledToolTip { get; }
|
||||
|
||||
/// <summary>The list view's status cell: what the hook pill says, and "Not installed" after it when that is so.</summary>
|
||||
public string StatusText => NotInstalled ? HookText + " · " + Strings.Games_Card_NotInstalled : HookText;
|
||||
|
||||
/// <summary>The executable check's answer, when it comes (beta.34) — with the reason, read off the UI thread with it.</summary>
|
||||
public void SetInstalled(bool installed, string? whyNot)
|
||||
{
|
||||
NotInstalled = !installed;
|
||||
NotInstalledToolTip = installed ? null : whyNot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether <paramref name="other"/> — the same game read again — would look the same on its card and in its row, and
|
||||
/// play the same executable (beta.34): a reload keeps the card it already has, and rebuilds only one that changed.
|
||||
/// </summary>
|
||||
public bool LooksLike(GameCardViewModel other)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(other);
|
||||
return Id == other.Id
|
||||
&& string.Equals(Name, other.Name, StringComparison.Ordinal)
|
||||
&& string.Equals(PlatformText, other.PlatformText, StringComparison.Ordinal)
|
||||
&& string.Equals(EngineText, other.EngineText, StringComparison.Ordinal)
|
||||
&& string.Equals(HookText, other.HookText, StringComparison.Ordinal)
|
||||
&& string.Equals(SessionsText, other.SessionsText, StringComparison.Ordinal)
|
||||
&& string.Equals(PlaytimeText, other.PlaytimeText, StringComparison.Ordinal)
|
||||
&& string.Equals(LastPlayedText, other.LastPlayedText, StringComparison.Ordinal)
|
||||
&& string.Equals(Card.Row.Fingerprint.ExePath, other.Card.Row.Fingerprint.ExePath, StringComparison.OrdinalIgnoreCase)
|
||||
&& string.Equals(Card.Row.Platform, other.Card.Row.Platform, StringComparison.Ordinal)
|
||||
&& string.Equals(Card.Row.StoreId, other.Card.Row.StoreId, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,10 @@ namespace FrameLedger.App.ViewModels;
|
||||
/// open by click. Since beta.11 (owner requests 2026-10-03): shown as a grid of cards that fills the width or as a list
|
||||
/// (<c>ui.library_view</c>), with the count in the header; <b>Refresh</b> reloads the library, looks in the stores for games
|
||||
/// installed since and offers only those, and marks entries whose executable is gone ("Not installed"); and the page
|
||||
/// reloads by itself when a session ends or an import adds games while it is on screen.
|
||||
/// reloads by itself when a session ends or an import adds games while it is on screen. Since beta.34 (owner request
|
||||
/// 2026-11-06, "Games stalls 0.5–1.5 s"; <c>spike-notes</c> §27) the page is kept by its window (<see cref="WindowPageCache"/>)
|
||||
/// and reads the library again each time it is shown; the library is read on the thread pool, the cards appear before
|
||||
/// the executables are checked, and a read keeps every card that would look the same.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1863:Use 'CompositeFormat'", Justification = "the format strings are resources that follow the UI culture, which changes at runtime")]
|
||||
public sealed partial class GamesViewModel : ObservableObject
|
||||
@@ -43,10 +46,11 @@ public sealed partial class GamesViewModel : ObservableObject
|
||||
private readonly Func<string, bool> _exists;
|
||||
private readonly UiThread _ui = new();
|
||||
private readonly List<string> _removed = [];
|
||||
private IReadOnlyList<GameCardViewModel> _all = [];
|
||||
private List<GameCardViewModel> _all = [];
|
||||
private int _reads;
|
||||
private bool _viewRead;
|
||||
private bool _attached;
|
||||
private bool _shownBefore;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _search = string.Empty;
|
||||
@@ -145,20 +149,73 @@ public sealed partial class GamesViewModel : ObservableObject
|
||||
PlayToolTip = await _player.IsDirectAsync(ct).ConfigureAwait(true) ? Strings.Play_ToolTip_Direct : Strings.Play_ToolTip_Store;
|
||||
}
|
||||
|
||||
IReadOnlyList<GameCard> cards = await _library.ListCardsAsync(ct).ConfigureAwait(true);
|
||||
// Whether each executable is on disk is a file-system question per entry — a drive that is gone can take a moment
|
||||
// to say so — so it is asked off the UI thread, the game page's own way (GameLibrary.ExecutableExists).
|
||||
Func<string, bool> exists = _exists;
|
||||
bool[] installed = await Task.Run(() => cards.Select(c => exists(c.Row.Fingerprint.ExePath)).ToArray(), ct)
|
||||
.ConfigureAwait(true);
|
||||
// beta.34: the library on the thread pool — Microsoft.Data.Sqlite completes its asynchronous calls synchronously,
|
||||
// so on the UI thread the read was the page's to wait for.
|
||||
GameLibrary library = _library;
|
||||
IReadOnlyList<GameCard> cards = await Task.Run(() => library.ListCardsAsync(ct), ct).ConfigureAwait(true);
|
||||
if (read != Volatile.Read(ref _reads))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_all = [.. cards.Select((c, i) => new GameCardViewModel(c, installed[i]))];
|
||||
// The cards first — each as the card it was, where it would look the same — and only then whether each executable
|
||||
// is on disk: a file-system question per entry that a sleeping drive answers in a second or more (39 of the owner's
|
||||
// 41 Steam games are on a USB drive), and no card was shown until every one had answered (spike-notes §27).
|
||||
_all = Merge(_all, cards);
|
||||
HeaderText = string.Format(CultureInfo.CurrentCulture, Strings.Games_Header_Count_Format, _all.Count);
|
||||
Apply();
|
||||
|
||||
Func<string, bool> exists = _exists;
|
||||
(bool Installed, string? WhyNot)[] checks = await Task.Run(() => cards.Select(c =>
|
||||
{
|
||||
string path = c.Row.Fingerprint.ExePath;
|
||||
bool installed = exists(path);
|
||||
return (installed, installed ? null : Formats.ExecutableMissingText(path));
|
||||
}).ToArray(), ct).ConfigureAwait(true);
|
||||
if (read != Volatile.Read(ref _reads))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var byId = _all.ToDictionary(static c => c.Id);
|
||||
for (int i = 0; i < cards.Count; i++)
|
||||
{
|
||||
if (byId.TryGetValue(cards[i].Row.Id, out GameCardViewModel? card))
|
||||
{
|
||||
card.SetInstalled(checks[i].Installed, checks[i].WhyNot);
|
||||
}
|
||||
}
|
||||
|
||||
Apply();
|
||||
PlayCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The library read again, as cards: an entry that would look the same keeps the card it has — its place on screen and
|
||||
/// its installed state until the check answers again — and only an entry that changed, or is new, gets a new one.
|
||||
/// </summary>
|
||||
private static List<GameCardViewModel> Merge(IReadOnlyList<GameCardViewModel> shown, IReadOnlyList<GameCard> cards)
|
||||
{
|
||||
var old = shown.ToDictionary(static c => c.Id);
|
||||
var merged = new List<GameCardViewModel>(cards.Count);
|
||||
foreach (GameCard card in cards)
|
||||
{
|
||||
var fresh = new GameCardViewModel(card);
|
||||
if (old.TryGetValue(card.Row.Id, out GameCardViewModel? kept))
|
||||
{
|
||||
if (kept.LooksLike(fresh))
|
||||
{
|
||||
merged.Add(kept);
|
||||
continue;
|
||||
}
|
||||
|
||||
fresh.SetInstalled(!kept.NotInstalled, kept.NotInstalledToolTip);
|
||||
}
|
||||
|
||||
merged.Add(fresh);
|
||||
}
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -184,6 +241,16 @@ public sealed partial class GamesViewModel : ObservableObject
|
||||
}
|
||||
|
||||
_attached = true;
|
||||
|
||||
// beta.34: the page is kept by its window and shown again on a later visit (WindowPageCache), so what happened while
|
||||
// it was away — a session that ended, a game removed, renamed or added on another page — is read now, behind the
|
||||
// cards already on screen. Its first Loaded follows the constructor's own read.
|
||||
if (_shownBefore)
|
||||
{
|
||||
Pending = LoadAsync();
|
||||
}
|
||||
|
||||
_shownBefore = true;
|
||||
}
|
||||
|
||||
public void Detach()
|
||||
@@ -368,13 +435,42 @@ public sealed partial class GamesViewModel : ObservableObject
|
||||
_ => shown.OrderBy(static c => c.Name, StringComparer.CurrentCultureIgnoreCase),
|
||||
};
|
||||
|
||||
Games.Clear();
|
||||
foreach (GameCardViewModel card in shown)
|
||||
{
|
||||
Games.Add(card);
|
||||
}
|
||||
|
||||
Sync(Games, [.. shown]);
|
||||
IsEmpty = _all.Count == 0;
|
||||
NoMatch = _all.Count > 0 && Games.Count == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes <paramref name="target"/> list <paramref name="wanted"/>, in its order, by removing, moving and inserting —
|
||||
/// never clearing (beta.34): a card that stays is the element already on screen, and the panel builds only the new.
|
||||
/// </summary>
|
||||
internal static void Sync(ObservableCollection<GameCardViewModel> target, IReadOnlyList<GameCardViewModel> wanted)
|
||||
{
|
||||
var keep = new HashSet<GameCardViewModel>(wanted);
|
||||
for (int i = target.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (!keep.Contains(target[i]))
|
||||
{
|
||||
target.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < wanted.Count; i++)
|
||||
{
|
||||
if (i < target.Count && ReferenceEquals(target[i], wanted[i]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int at = target.IndexOf(wanted[i]);
|
||||
if (at >= 0)
|
||||
{
|
||||
target.Move(at, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
target.Insert(i, wanted[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -317,6 +317,109 @@ public sealed class GamesViewModelTests
|
||||
vm.HeaderText.Should().EndWith("2");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// beta.34 (owner request 2026-11-06, "Games stalls 0.5–1.5 s"): the cards are listed before any executable is checked —
|
||||
/// a sleeping USB drive took a second or more to answer, and no card was shown until every one had — and each card
|
||||
/// gets its pill when its check answers.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TheCardsComeBeforeTheExecutableChecksAndThePillAfter()
|
||||
{
|
||||
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
||||
_ = await s.GameAsync("Alpha");
|
||||
_ = await s.GameAsync("Bravo");
|
||||
var bound = TimeSpan.FromSeconds(30);
|
||||
using var checking = new ManualResetEventSlim();
|
||||
using var mayAnswer = new ManualResetEventSlim();
|
||||
bool Asleep(string path)
|
||||
{
|
||||
checking.Set();
|
||||
_ = mayAnswer.Wait(bound, Ct);
|
||||
return false;
|
||||
}
|
||||
|
||||
var selection = new GameSelection();
|
||||
var nav = new NoNavigation();
|
||||
var vm = new GamesViewModel(s.Library, selection, nav, new AddGameFlow(s.Library, new NoPicker(), selection, nav, new NoStrip()), executableExists: Asleep);
|
||||
Task load = vm.Pending;
|
||||
try
|
||||
{
|
||||
checking.Wait(bound, Ct).Should().BeTrue("the checks begin once the cards are listed");
|
||||
vm.Games.Should().HaveCount(2, "the cards are on the page while the drive is still answering");
|
||||
vm.Games.Should().OnlyContain(static g => !g.NotInstalled, "not known yet, so no pill");
|
||||
}
|
||||
finally
|
||||
{
|
||||
mayAnswer.Set();
|
||||
}
|
||||
|
||||
await load;
|
||||
vm.Games.Should().OnlyContain(static g => g.NotInstalled, "the answer came, and each card has its pill");
|
||||
vm.Games.Should().OnlyContain(static g => g.NotInstalledToolTip != null && g.StatusText.Contains(Strings.Games_Card_NotInstalled, StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// beta.34: the page is kept by its window and shown again on a later visit, so it reads the library again then — what
|
||||
/// happened while it was away appears — and a read keeps every card that would look the same, so the cards on screen are
|
||||
/// not built again.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task APageShownAgainReadsTheLibraryAndKeepsTheCardsThatLookTheSame()
|
||||
{
|
||||
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
||||
GameRow alpha = await s.GameAsync("Alpha");
|
||||
_ = await s.GameAsync("Bravo");
|
||||
var selection = new GameSelection();
|
||||
var nav = new NoNavigation();
|
||||
var vm = new GamesViewModel(s.Library, selection, nav, new AddGameFlow(s.Library, new NoPicker(), selection, nav, new NoStrip()));
|
||||
Task first = vm.Pending;
|
||||
await first;
|
||||
vm.Attach();
|
||||
vm.Pending.Should().BeSameAs(first, "the first Loaded follows the constructor's own read");
|
||||
GameCardViewModel alphaCard = vm.Games.Single(static g => string.Equals(g.Name, "Alpha", StringComparison.Ordinal));
|
||||
GameCardViewModel bravoCard = vm.Games.Single(static g => string.Equals(g.Name, "Bravo", StringComparison.Ordinal));
|
||||
|
||||
vm.Detach();
|
||||
_ = await s.GameAsync("Charlie");
|
||||
_ = await s.SessionAsync(alpha.Id, DateTimeOffset.UtcNow);
|
||||
vm.Attach();
|
||||
Task again = vm.Pending;
|
||||
again.Should().NotBeSameAs(first, "shown again, the page reads the library again");
|
||||
await again;
|
||||
|
||||
vm.Games.Select(static g => g.Name).Should().Equal(["Alpha", "Bravo", "Charlie"]);
|
||||
vm.HeaderText.Should().EndWith("3");
|
||||
vm.Games.Single(static g => string.Equals(g.Name, "Bravo", StringComparison.Ordinal)).Should().BeSameAs(bravoCard, "it looks the same, so it is the card on screen");
|
||||
GameCardViewModel alphaNow = vm.Games.Single(static g => string.Equals(g.Name, "Alpha", StringComparison.Ordinal));
|
||||
alphaNow.Should().NotBeSameAs(alphaCard, "its session count changed");
|
||||
alphaNow.SessionCount.Should().Be(1);
|
||||
}
|
||||
|
||||
private static GameRow Row(long id) => new()
|
||||
{
|
||||
Id = id,
|
||||
Name = "G" + id.ToString(CultureInfo.InvariantCulture),
|
||||
Fingerprint = new() { ExePath = @"C:\Games\g.exe", SizeBytes = 1, MtimeUnixMs = 2 },
|
||||
HookEnabled = false,
|
||||
HookCrashCount = 0,
|
||||
AddedAt = DateTimeOffset.UnixEpoch,
|
||||
UpdatedAt = DateTimeOffset.UnixEpoch,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void SyncRemovesMovesAndInsertsWithoutClearing()
|
||||
{
|
||||
GameCardViewModel[] c = [.. Enumerable.Range(1, 5).Select(static i => new GameCardViewModel(new GameCard(Row(i), null)))];
|
||||
var shown = new System.Collections.ObjectModel.ObservableCollection<GameCardViewModel>([c[0], c[1], c[2], c[3]]);
|
||||
int resets = 0;
|
||||
shown.CollectionChanged += (_, e) => resets += e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset ? 1 : 0;
|
||||
|
||||
GamesViewModel.Sync(shown, [c[3], c[0], c[4], c[2]]);
|
||||
|
||||
shown.Should().Equal([c[3], c[0], c[4], c[2]]);
|
||||
resets.Should().Be(0, "never a Reset: the cards that stay keep their elements");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1200, 3)]
|
||||
[InlineData(1248, 4)]
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
||||
|
||||
using FluentAssertions;
|
||||
using FrameLedger.App.Pages;
|
||||
using FrameLedger.App.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Wpf.Ui.Abstractions;
|
||||
|
||||
namespace FrameLedger.App.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// beta.34 (owner request 2026-11-06): the library page is kept by the window that built it and shown again on a later
|
||||
/// visit; every other page is the container's, new each visit; a new window — a language change — builds its own.
|
||||
/// And the shell opens a rebuilt window on the page that was on screen, however it was reached.
|
||||
/// </summary>
|
||||
public sealed class WindowPageCacheTests
|
||||
{
|
||||
private sealed class NewEachTime : INavigationViewPageProvider
|
||||
{
|
||||
public int Built { get; private set; }
|
||||
|
||||
public object? GetPage(Type pageType)
|
||||
{
|
||||
Built++;
|
||||
return new object();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheLibraryIsKeptByItsWindowAndEveryOtherPageIsNewEachVisit()
|
||||
{
|
||||
var container = new NewEachTime();
|
||||
var window = new WindowPageCache(container);
|
||||
|
||||
object games = window.GetPage(typeof(GamesPage))!;
|
||||
window.GetPage(typeof(GamesPage)).Should().BeSameAs(games, "shown again, it is the page already built");
|
||||
window.GetPage(typeof(DashboardPage)).Should().NotBeSameAs(window.GetPage(typeof(DashboardPage)), "transient, as before");
|
||||
container.Built.Should().Be(3);
|
||||
|
||||
new WindowPageCache(container).GetPage(typeof(GamesPage)).Should().NotBeSameAs(games,
|
||||
"a rebuilt window builds its own, in its own language, and never shares one page between two windows");
|
||||
WindowPageCache.Kept.Should().BeEquivalentTo([typeof(GamesPage)]);
|
||||
FluentActions.Invoking(() => window.GetPage(null!)).Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ARebuildOpensOnThePageOnScreenHoweverItWasReached()
|
||||
{
|
||||
var shell = new ShellHost(new ServiceCollection().BuildServiceProvider(), null!, null!, new WindowClosePolicy());
|
||||
shell.Page.Should().Be<DashboardPage>();
|
||||
|
||||
shell.Remember(typeof(GameDetailPage));
|
||||
shell.NoteShown(live: true, page: new SettingsPageStandIn());
|
||||
shell.Page.Should().Be<SettingsPageStandIn>("a page reached by the pane is remembered too");
|
||||
|
||||
shell.NoteShown(live: false, page: new object());
|
||||
shell.Page.Should().Be<SettingsPageStandIn>("the closing window of a rebuild changes nothing");
|
||||
shell.NoteShown(live: true, page: null);
|
||||
shell.Page.Should().Be<SettingsPageStandIn>();
|
||||
}
|
||||
|
||||
private sealed class SettingsPageStandIn;
|
||||
}
|
||||
@@ -7,7 +7,9 @@ WPF UI 4.3.0 (pinned), CommunityToolkit.Mvvm, ScottPlot for charts and Markdig f
|
||||
## How it is put together
|
||||
|
||||
- A .NET Generic Host with dependency injection. Pages and their view models are transient — a page is made again on
|
||||
every navigation, so state lives in the view models' services and the database, never in a page. A view model that
|
||||
every navigation, so state lives in the view models' services and the database, never in a page. The one exception
|
||||
(beta.34): the window keeps the library page it built (`WindowPageCache`) and the page reads the library again each
|
||||
time it is shown. A view model that
|
||||
listens to a service attaches on its page's Loaded and detaches on Unloaded, and is never `IDisposable`: the container
|
||||
keeps every transient disposable it makes until the App exits.
|
||||
- The ledger's reads run on the thread that calls them (Microsoft.Data.Sqlite completes its asynchronous calls
|
||||
|
||||
Reference in new issue
Block a user