Files
captureimg/src/CaptureImage.ViewModels/Dashboard/GameTargetViewModel.cs
T
poli0981andClaude Opus 4.7 5f5e878e0b feat(v1.1-m4): UI/UX polish — live-localization fixes + 2025 modernization
Part A — 7 live-localization / refresh bugs (user-flagged + audit-found):

- Dashboard title, subtitle, Refresh / Arm / Disarm buttons, target count
  line, and loading hint were all hardcoded English; now bound through
  `{Binding Localization[Dashboard_*]}` so they track the culture switch.
- `DashboardViewModel` expands its culture listener to refresh every
  computed string (TargetsCountText, LoadingText, EmptyStateText). The
  new `TargetsCountText` property formats via `Dashboard_TargetsCount`
  so the "N target(s) visible" line picks up plural wording per culture.
- `GameTargetViewModel.SteamBadgeTooltip` was a hardcoded mixed
  English/Vietnamese string; now reads through `ILocalizationService`,
  subscribes to `PropertyChanged`, and formats via
  `Dashboard_SteamBadgeTooltip` (keys {0}=app name, {1}=app id). The
  VM is now IDisposable, and the dashboard disposes rows on reconcile
  so the live listener doesn't pin dead targets.
- LogViewer Pause/Resume button was pinned to `Localization[Log_Pause]`
  and didn't flip on state change. Added `TogglePauseLabel` computed
  property that switches between `Log_Pause` / `Log_Resume` on
  IsPaused, plus a culture listener that also refreshes the events
  count and empty-state text.
- `HotkeyBindingViewModel.ErrorMessage` is an indexer-backed computed
  property; added a culture listener that raises PropertyChanged so
  the Settings error text re-localizes live.
- MainWindow hardcoded `"CaptureImage"` + `"v0.1.0 — M3 UX polish"`
  (stale!) in the nav-rail header. `MainWindowViewModel` now exposes
  `AppTitle` + `AppVersion` (pulled from
  `AssemblyInformationalVersion` / assembly metadata). App.csproj adds
  `<Version>1.1.0-dev</Version>` so dev builds render meaningfully;
  release.yml still overrides via `/p:Version=<git-tag>`.

Part B — 2025/26 visual-system modernization:

- App.axaml grows a small style sheet: global Inter font stack for
  TextBlock / TextBox / Button / ComboBox / CheckBox (Avalonia.Fonts.Inter
  was in the package graph but never referenced); a keyboard focus ring
  on ListBoxItem via :focus-visible + accent brush + 2 px border; plus
  a header comment documenting the visual conventions (fonts, radii,
  spacing, contrast) for future contributors.
- Corner-radius unified to 8 px on cards/borders (Dashboard list,
  status card, About metadata card + third-party card, Update cards,
  Preview image, LogViewer drawer, Toast). 4 px kept only on the inline
  Steam badge pill per the design contract.
- Secondary text sweep: every `Opacity="0.4"`-`"0.7"` on labels and
  hints swapped for `Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"`
  so contrast meets WCAG AA on both light and dark theme variants.
- HotkeyRecorder BindingField grows a `:focus` selector that flips
  the border to accent colour so "waiting for your key" is visually
  obvious; also gains `AutomationProperties.Name` + HelpText for
  screen readers.
- MainWindow log-drawer toggle button gets `AutomationProperties.Name`
  + tooltip via a new `Dashboard_LogToggle` key (EN/VI/AR).
- Dashboard status card gets `AutomationProperties.Name` bound to
  `StatusMessage` so narrators read the current capture state.
- Empty states added: Dashboard ("No visible windows to capture —
  launch your game or app, then click Refresh.") and LogViewer ("No
  log events yet..."). New keys `Dashboard_EmptyState` + `Log_EmptyState`
  + `Log_EventsCount` in all three .resx files.
- FontSize outliers snapped to the 11/12/13/14/16/22 scale (page titles
  24→22, preview dialog 20→22, Steam badge 10→11, nav icon 18→16).

Scope out:
- Mica window effect (needs Win11 composition hooks, not stock Avalonia).
- Dark-mode theme picker (Fluent honours OS setting already).
- 44×44 touch-target resize (desktop app; 32 is sufficient here).

Verification: `dotnet build -c Release` 0/0; `dotnet test -c Release`
107 pass. Manual culture-switch smoke on dev machine confirmed every
fixed surface re-localizes live — Dashboard title/subtitle/buttons,
target count, Steam badge tooltip, LogViewer title + Pause/Resume
label, Hotkey error text, nav labels, tray menu, MainWindow header —
and the RTL mirror still behaves under `ar-SA`.

Closes v1.1-M4. Next: v1.1-M5 release cut.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 11:24:30 +07:00

80 lines
2.6 KiB
C#

using System;
using System.ComponentModel;
using CaptureImage.Core.Abstractions;
using CaptureImage.Core.Models;
namespace CaptureImage.ViewModels.Dashboard;
/// <summary>
/// Thin view-model wrapper around <see cref="GameTarget"/>. Keeps the VM project free of
/// Avalonia — <see cref="IconBytes"/> is raw PNG, and the UI project converts it into
/// an <c>Avalonia.Media.Imaging.Bitmap</c> via a value converter.
/// </summary>
/// <remarks>
/// Holds a reference to <see cref="ILocalizationService"/> so <see cref="SteamBadgeTooltip"/>
/// can refresh on culture changes without reallocating the target row. Disposed indirectly —
/// each target row lives and dies with the <c>ObservableCollection</c> in the dashboard,
/// and the next reconciliation pass replaces it.
/// </remarks>
public sealed class GameTargetViewModel : ViewModelBase, IDisposable
{
private readonly ILocalizationService _localization;
private bool _disposed;
public GameTargetViewModel(GameTarget target, ILocalizationService localization)
{
Target = target;
_localization = localization;
_localization.PropertyChanged += OnLocalizationPropertyChanged;
}
public GameTarget Target { get; }
public uint ProcessId => Target.ProcessId;
public string DisplayName => Target.DisplayName;
public string ProcessName => Target.ProcessName;
public string ExecutablePath => Target.ExecutablePath;
public byte[]? IconBytes => Target.IconBytes;
public bool IsSteamGame => Target.IsSteamGame;
public string? SteamAppName => Target.SteamInfo?.Name;
/// <summary>
/// Tooltip shown on the Steam badge. Localized via
/// <c>Dashboard_SteamBadgeTooltip</c> with <c>{0}=AppName</c> and <c>{1}=AppId</c>;
/// recomputes on culture changes.
/// </summary>
public string SteamBadgeTooltip
{
get
{
if (Target.SteamInfo is null) return string.Empty;
return string.Format(
_localization["Dashboard_SteamBadgeTooltip"],
Target.SteamInfo.Name,
Target.SteamInfo.AppId);
}
}
private void OnLocalizationPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (_disposed) return;
if (e.PropertyName is "Item[]" or nameof(ILocalizationService.CurrentCulture))
{
OnPropertyChanged(nameof(SteamBadgeTooltip));
}
}
public void Dispose()
{
if (_disposed) return;
_disposed = true;
_localization.PropertyChanged -= OnLocalizationPropertyChanged;
}
}