Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f7985a644 | ||
|
|
5f19835ce6 | ||
|
|
16dcfb71dc | ||
|
|
5f5e878e0b | ||
|
|
a44b65d86c | ||
|
|
8e374a024e | ||
|
|
cb3ec44693 | ||
|
|
d5706f2dee | ||
|
|
64164b4690 | ||
|
|
0482f718cb |
No files matched your search
@@ -24,12 +24,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0 # full history so MinVer / git describe works later
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
uses: actions/setup-dotnet@v5
|
||||
with:
|
||||
# Honor global.json; avoids drift between local + CI.
|
||||
global-json-file: global.json
|
||||
@@ -48,7 +48,7 @@ jobs:
|
||||
|
||||
- name: Upload test results
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: test-results
|
||||
path: ./TestResults/**/*.trx
|
||||
|
||||
@@ -39,7 +39,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -58,7 +58,7 @@ jobs:
|
||||
"version=$v" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
uses: actions/setup-dotnet@v5
|
||||
with:
|
||||
global-json-file: global.json
|
||||
|
||||
@@ -108,14 +108,14 @@ jobs:
|
||||
Get-Content "$outDir\SHA256SUMS.txt"
|
||||
|
||||
- name: Upload release artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: captureimage-release-${{ steps.version.outputs.version }}
|
||||
path: ./releases/**
|
||||
retention-days: 30
|
||||
|
||||
- name: Create / update GitHub Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
uses: softprops/action-gh-release@v3
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
with:
|
||||
name: CaptureImage v${{ steps.version.outputs.version }}
|
||||
|
||||
+127
@@ -7,6 +7,133 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.1.0] - 2026-04-20
|
||||
|
||||
Second release. Polish + configurability pass on top of v1.0.0 — ships a
|
||||
real hotkey rebinder, live localization fixes across every tab, an
|
||||
architecture overview for contributors, and a visual refresh aligned
|
||||
with 2025/26 Windows 11 conventions. No capture-engine changes; no new
|
||||
backends.
|
||||
|
||||
### M4 — UI/UX polish: live-localization fixes + 2025 modernization
|
||||
|
||||
Polish pass closing seven localization / live-refresh bugs and modernizing
|
||||
the visual system to match 2025/26 Windows 11 conventions. Commit
|
||||
[`5f5e878`](https://github.com/poli0981/captureimg/commit/5f5e878).
|
||||
|
||||
- **Dashboard localization**: title, subtitle, Refresh / Arm / Disarm
|
||||
buttons, "N target(s) visible" line, and the loading hint were all
|
||||
hardcoded English; now bound through `{Binding Localization[Dashboard_*]}`
|
||||
and refresh live on culture switch. `DashboardViewModel` grows
|
||||
`TargetsCountText`, `LoadingText`, `EmptyStateText`, `HasNoTargets` and
|
||||
expands its culture listener to refresh all of them.
|
||||
- **Steam badge tooltip**: `GameTargetViewModel.SteamBadgeTooltip` was a
|
||||
hardcoded mixed EN/VI string; now formats via
|
||||
`Dashboard_SteamBadgeTooltip` with a culture listener. The VM is now
|
||||
`IDisposable` and the dashboard disposes rows on reconcile so the
|
||||
listener doesn't pin dead targets.
|
||||
- **LogViewer Pause/Resume**: the button was pinned to `Log_Pause` and
|
||||
didn't flip on state change. New `TogglePauseLabel` switches between
|
||||
`Log_Pause` / `Log_Resume` on `IsPaused` + culture change. A new
|
||||
culture listener on `LogViewerViewModel` also refreshes
|
||||
`EventsCountText` + `EmptyStateText`.
|
||||
- **Hotkey error message**: `HotkeyBindingViewModel.ErrorMessage` is an
|
||||
indexer-backed computed property; added a culture listener that raises
|
||||
`PropertyChanged` so the Settings error text re-localizes live.
|
||||
- **MainWindow header**: hardcoded `"CaptureImage"` + stale
|
||||
`"v0.1.0 — M3 UX polish"` replaced with `AppTitle` + `AppVersion`
|
||||
pulled from `AssemblyInformationalVersion` / assembly metadata.
|
||||
`App.csproj` now carries a `<Version>` element; release.yml keeps
|
||||
overriding via `/p:Version=<git-tag>`.
|
||||
- **Inter font stack**: `Avalonia.Fonts.Inter` was in the package graph
|
||||
but never applied. `App.axaml` now declares a global Inter style for
|
||||
TextBlock / TextBox / Button / ComboBox / CheckBox (monospace
|
||||
overrides remain for LogViewer entries + HotkeyRecorder display).
|
||||
- **Focus ring**: keyboard-focus `:focus-visible` style on
|
||||
`ListBoxItem` + `Border#BindingField:focus` style on
|
||||
`HotkeyRecorder` — both paint the border in the accent brush so Tab
|
||||
navigation and "waiting for your key" are visually obvious.
|
||||
- **Corner radius**: unified to 8 px on cards / borders across Dashboard,
|
||||
About, Update, Preview, LogViewer, Toast. 4 px kept only on the inline
|
||||
Steam badge pill per the design contract.
|
||||
- **Text contrast**: every `Opacity="0.4"`–`"0.7"` on labels and hints
|
||||
swapped for `Foreground=SystemControlForegroundBaseMediumBrush` so
|
||||
secondary text meets WCAG AA on both light and dark theme variants.
|
||||
- **Accessibility**: `AutomationProperties.Name` + HelpText on the log
|
||||
drawer toggle, HotkeyRecorder BindingField, and Dashboard status
|
||||
card — screen readers now announce meaningful names.
|
||||
- **Empty states**: Dashboard and LogViewer now render a localized hint
|
||||
when no targets / no log events. New keys `Dashboard_EmptyState`,
|
||||
`Dashboard_LogToggle`, `Log_EmptyState`, `Log_EventsCount` added in
|
||||
EN / VI / AR.
|
||||
- **FontSize scale**: snapped outliers to 11/12/13/14/16/22 — page
|
||||
titles 24→22, preview dialog 20→22, nav icon 18→16, Steam badge
|
||||
10→11.
|
||||
|
||||
### M3 — Architecture tour + dogfood screenshots
|
||||
|
||||
Contributor-facing documentation + real README screenshots. Commit
|
||||
[`8e374a0`](https://github.com/poli0981/captureimg/commit/8e374a0).
|
||||
|
||||
- **`docs/ARCHITECTURE.md`** (new) — one-page-per-layer reference with
|
||||
five Mermaid diagrams that GitHub renders inline: project dependency
|
||||
graph, capture state machine, WGC capture pipeline sequence, DI
|
||||
composition sketch, i18n + RTL flow, and Velopack update flow.
|
||||
- **`docs/screenshots/`** (new) — six real app screenshots
|
||||
(Dashboard / Settings / About / Update / LogViewer / RTL Dashboard),
|
||||
captured by dogfooding CaptureImage on itself for the passive views.
|
||||
- **README refresh** — replaces the "coming with first tagged release"
|
||||
placeholder with a 2×3 screenshot table, and adds an Architecture
|
||||
section linking to the new doc.
|
||||
|
||||
### M2 — Dependabot cleanup + Node 24 runners
|
||||
|
||||
Close the dependabot backlog ahead of the Node 20 deprecation deadline
|
||||
(2026-09-16). Commit [`d5706f2`](https://github.com/poli0981/captureimg/commit/d5706f2).
|
||||
|
||||
- **GitHub Actions bumps** (all Node 20 → Node 24 runtime updates; no
|
||||
API changes, `windows-latest` already supports the newer runner):
|
||||
`actions/checkout` 4→6, `actions/setup-dotnet` 4→5,
|
||||
`actions/upload-artifact` 4→7, `softprops/action-gh-release` 2→3.
|
||||
- **Test tooling bumps**: `xunit` 2.9.2→2.9.3 (patch),
|
||||
`coverlet.collector` 6.0.2→8.0.1 (major — requires .NET 8 LTS floor,
|
||||
which we already exceed on .NET 9).
|
||||
- **Release.yml audit**: `upload-artifact` v5/v6/v7 kept `name`,
|
||||
`path`, `retention-days` intact; the v1.1 plan's speculated
|
||||
`overwrite` default flip never happened. No YAML option changes
|
||||
required.
|
||||
|
||||
### M1 — Hotkey rebinder + conflict sniff
|
||||
|
||||
First user-facing feature addition since 1.0.0. Commit
|
||||
[`0482f71`](https://github.com/poli0981/captureimg/commit/0482f71).
|
||||
|
||||
- **`HotkeyRecorder` control** — keyboard-driven recorder in Settings.
|
||||
Click Record, press a combination, Esc cancels. The view maps
|
||||
Avalonia `Key` to Win32 virtual-key codes so the persisted
|
||||
`HotkeyBinding` stays round-trippable against SharpHook's RawCode.
|
||||
- **`HotkeyBindingViewModel`** — bridges recorder → persistence and
|
||||
calls `IHotkeyService.SetBinding` live so an armed capture picks up
|
||||
the new combo without disarm/re-arm.
|
||||
- **`ReservedHotkeys`** (new, `CaptureImage.Core.Validation`) —
|
||||
catalogue of combinations owned by the Windows shell (Win+L,
|
||||
Ctrl+Shift+Esc, Alt+Tab, Alt+F4, Win snap keys, etc.).
|
||||
`HotkeyBinding.Validate()` rejects those plus modifier-only /
|
||||
naked-letter bindings before persistence with a localized error.
|
||||
- **`HotkeyConflictSniffer`** — `RegisterHotKey`/`UnregisterHotKey`
|
||||
probe on `HWND=NULL`. If another process already owns the combo the
|
||||
UI surfaces a non-blocking warning, but the user keeps control and
|
||||
still saves.
|
||||
- **i18n strings** for every recorder surface added in EN / VI / AR.
|
||||
- **Tests**: +24 Core validation (reserved combos + `HotkeyBinding.Validate`),
|
||||
+12 ViewModel flow with NSubstitute fakes. Total 107 pass.
|
||||
|
||||
## [1.0.0] - 2026-04-16
|
||||
|
||||
Initial public release. Screen-capture tool targeting Windows 11 22H2+,
|
||||
built with C# .NET 9 + Avalonia 11, distributed as a Velopack installer
|
||||
via GitHub Releases. Unsigned (SignPath application was declined).
|
||||
|
||||
### M5 — Release infrastructure (1.0.0 cut)
|
||||
|
||||
Everything you need to actually ship the binary. No new product features;
|
||||
|
||||
@@ -76,12 +76,12 @@
|
||||
|
||||
<ItemGroup Label="Tests">
|
||||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageVersion Include="xunit" Version="2.9.2" />
|
||||
<PackageVersion Include="xunit" Version="2.9.3" />
|
||||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||
<PackageVersion Include="FluentAssertions" Version="6.12.2" />
|
||||
<PackageVersion Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageVersion Include="System.IO.Abstractions.TestingHelpers" Version="21.2.1" />
|
||||
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageVersion Include="coverlet.collector" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -53,10 +53,15 @@ tray app, and stays out of your way until you press the hotkey.
|
||||
|
||||
## Screenshots
|
||||
|
||||
<!-- Screenshots land here once the maintainer captures them. The app
|
||||
generates its own screenshots — yes, we eat our own dog food. -->
|
||||
Captured with CaptureImage itself — yes, we eat our own dog food.
|
||||
|
||||
_(coming with the first tagged release)_
|
||||
| Dashboard | Settings | About |
|
||||
|:-:|:-:|:-:|
|
||||
|  |  |  |
|
||||
|
||||
| Update | Log viewer | RTL (Arabic) |
|
||||
|:-:|:-:|:-:|
|
||||
|  |  |  |
|
||||
|
||||
## Requirements
|
||||
|
||||
@@ -155,6 +160,13 @@ docs/
|
||||
THIRD_PARTY_NOTICES.md Full dependency list + licenses.
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
See [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) for a one-page-per-layer
|
||||
tour — layer rules, state-machine diagram, WGC capture pipeline sequence,
|
||||
DI composition sketch, i18n + RTL flow, and Velopack update flow (all with
|
||||
Mermaid diagrams rendered inline on GitHub).
|
||||
|
||||
## Contributing
|
||||
|
||||
See [`docs/CONTRIBUTORS.md`](docs/CONTRIBUTORS.md) for the full
|
||||
|
||||
@@ -0,0 +1,349 @@
|
||||
# Architecture
|
||||
|
||||
This document is a one-page-per-layer tour of CaptureImage for people who
|
||||
want to contribute, audit, or port the code. It is **not** the design
|
||||
intent record — that lives in the per-milestone plan files under
|
||||
`.claude/plans/`. This is the shape of the code as it stands on `main`.
|
||||
|
||||
Diagrams are Mermaid so GitHub renders them inline. Source paths are
|
||||
clickable; line numbers drift, so I link to files rather than lines.
|
||||
|
||||
## 1. Layer rules
|
||||
|
||||
Five projects, four rules:
|
||||
|
||||
- **`CaptureImage.Core`** (net9.0) — pure domain. Models, abstractions,
|
||||
state machine, pipeline. No platform references. **Depends on nothing.**
|
||||
- **`CaptureImage.Infrastructure`** (net9.0-windows10.0.22621.0) — every
|
||||
Windows-specific implementation: WGC capture, D3D11 interop, WMI
|
||||
process watch, `RegisterHotKey` sniff, Velopack updater, Serilog sinks,
|
||||
JSON settings. **Depends on Core.**
|
||||
- **`CaptureImage.ViewModels`** (net9.0) — MVVM layer using
|
||||
CommunityToolkit.Mvvm source generators. Platform-agnostic — these
|
||||
types exist so the UI logic is testable without Avalonia.
|
||||
**Depends on Core only.**
|
||||
- **`CaptureImage.UI`** (net9.0) — Avalonia views, custom controls,
|
||||
converters, resx localization. **Depends on Core + ViewModels.**
|
||||
- **`CaptureImage.App`** (net9.0-windows10.0.22621.0) — the composition
|
||||
root. `Program.cs` + [`CompositionRoot.cs`](../src/CaptureImage.App/CompositionRoot.cs).
|
||||
Single point of DI wiring. **Depends on all four projects.**
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
App[CaptureImage.App<br/>net9.0-windows]
|
||||
UI[CaptureImage.UI<br/>net9.0 · Avalonia]
|
||||
VM[CaptureImage.ViewModels<br/>net9.0 · MVVM]
|
||||
Infra[CaptureImage.Infrastructure<br/>net9.0-windows · P/Invoke]
|
||||
Core[CaptureImage.Core<br/>net9.0 · pure domain]
|
||||
|
||||
App --> UI
|
||||
App --> Infra
|
||||
App --> VM
|
||||
App --> Core
|
||||
UI --> VM
|
||||
UI --> Core
|
||||
VM --> Core
|
||||
Infra --> Core
|
||||
```
|
||||
|
||||
**Why this shape:**
|
||||
|
||||
- `Core` stays portable so the domain logic is trivially testable. The
|
||||
Core test project runs on plain `net9.0`, no Windows 11 SDK needed.
|
||||
- `ViewModels` stays off `net9.0-windows` so Avalonia's designer +
|
||||
hot-reload tooling work without dragging in WinRT projections.
|
||||
- `Infrastructure` is the only project that touches `Windows.*`. If a
|
||||
future milestone ports to another desktop platform, that's the project
|
||||
that gets replaced.
|
||||
|
||||
## 2. Capture state machine
|
||||
|
||||
Every screenshot flows through a single
|
||||
[`CaptureStateMachine`](../src/CaptureImage.Core/StateMachine/CaptureStateMachine.cs)
|
||||
backed by the `Stateless` library. `DashboardViewModel` fires triggers;
|
||||
the machine decides whether the preview step is visited based on a
|
||||
live-checked `Func<bool> previewEnabled`.
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> Idle
|
||||
Idle --> TargetsSelected: SelectTargets
|
||||
TargetsSelected --> Idle: ClearTargets
|
||||
TargetsSelected --> Armed: Arm
|
||||
Armed --> TargetsSelected: Disarm
|
||||
Armed --> Idle: ClearTargets
|
||||
Armed --> Capturing: HotkeyPressed
|
||||
Capturing --> Previewing: FrameCaptured\n(previewEnabled=true)
|
||||
Capturing --> Saving: FrameCaptured\n(previewEnabled=false)
|
||||
Capturing --> Failed: ErrorOccurred
|
||||
Previewing --> Saving: PreviewAccepted
|
||||
Previewing --> Armed: PreviewRejected
|
||||
Saving --> Complete: Saved
|
||||
Saving --> Failed: ErrorOccurred
|
||||
Complete --> Armed: Reset
|
||||
Complete --> Idle: ClearTargets
|
||||
Failed --> Armed: Reset
|
||||
Failed --> Idle: ClearTargets
|
||||
```
|
||||
|
||||
**Rules of the road:**
|
||||
|
||||
- Transitions are driven by explicit triggers, never by timers. The
|
||||
viewmodel is the only thing allowed to call `Fire`.
|
||||
- `Capturing → Saving/Previewing` uses `PermitDynamic` so the preview
|
||||
toggle is consulted at transition time. Changing the toggle while
|
||||
armed affects the *next* capture, not any in-flight one.
|
||||
- `Failed` and `Complete` both route back to `Armed` on `Reset` so the
|
||||
user can fire another shot without re-selecting a target.
|
||||
- `StateChanged` fires on whatever thread drove the trigger.
|
||||
`DashboardViewModel` marshals to the UI thread before touching
|
||||
bindings.
|
||||
|
||||
Tests cover every legal transition and assert illegal ones throw —
|
||||
[`CaptureStateMachineTests`](../tests/CaptureImage.Core.Tests/StateMachine/CaptureStateMachineTests.cs).
|
||||
|
||||
## 3. WGC capture pipeline
|
||||
|
||||
The primary engine is
|
||||
[`WindowsGraphicsCaptureEngine`](../src/CaptureImage.Infrastructure/Capture/WindowsGraphicsCaptureEngine.cs),
|
||||
an on-demand single-frame pipeline. It uses the same
|
||||
`Windows.Graphics.Capture` API that OBS Studio uses for Game Capture.
|
||||
Hardware-accelerated, works with DX11/DX12/Vulkan windowed and
|
||||
borderless-fullscreen titles.
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant VM as DashboardViewModel
|
||||
participant Eng as WindowsGraphicsCaptureEngine
|
||||
participant Interop as CaptureItemInterop
|
||||
participant D3D as D3D11DeviceManager
|
||||
participant WGC as Windows.Graphics.Capture
|
||||
participant Tex as Staging Texture
|
||||
|
||||
VM->>Eng: CaptureAsync(target, ct)
|
||||
Eng->>Interop: CreateForWindow(HWND)
|
||||
Interop-->>Eng: GraphicsCaptureItem
|
||||
Eng->>D3D: Get()
|
||||
D3D-->>Eng: (ID3D11Device, context)
|
||||
Eng->>WGC: CreateFreeThreaded(framePool)
|
||||
Eng->>WGC: CreateCaptureSession(item)
|
||||
Note over Eng,WGC: IsBorderRequired=false<br/>IsCursorCaptureEnabled=false
|
||||
Eng->>WGC: StartCapture()
|
||||
WGC-->>Eng: FrameArrived (async)
|
||||
Eng->>Tex: CreateTexture2D(STAGING + CPU_READ)
|
||||
Eng->>Tex: CopyResource(gpu → staging)
|
||||
Eng->>Tex: Map(READ)
|
||||
Eng-->>VM: CapturedFrame(w, h, stride, bytes)
|
||||
Note over Eng: Dispose session<br/>Dispose framePool<br/>Dispose staging + gpu texture
|
||||
```
|
||||
|
||||
**Invariants:**
|
||||
|
||||
- Exactly one frame per call. The framepool is `numberOfBuffers: 1` and
|
||||
the session is disposed as soon as the first frame arrives.
|
||||
- 2-second `FrameTimeout`. Games that never render (minimized, stalled)
|
||||
surface as `CaptureError.NoFrameArrived`.
|
||||
- BGRA8 only — pixel format is pinned so the encoder layer doesn't need
|
||||
a format negotiation step. The Skia/ImageSharp wrappers accept BGRA
|
||||
directly.
|
||||
- Win11 22H2+ only. That's the minimum OS for the
|
||||
`IsBorderRequired = false` flag to actually hide the yellow capture
|
||||
frame. Older builds still work but show the frame.
|
||||
|
||||
**Fallback path:** if WGC itself fails (legacy GDI-only apps, some
|
||||
emulators), the orchestrator retries with
|
||||
[`PrintWindowFallback`](../src/CaptureImage.Infrastructure/Capture/PrintWindowFallback.cs)
|
||||
which calls `PrintWindow(hwnd, hdc, PW_RENDERFULLCONTENT)`. Slower,
|
||||
subject to HDCP, but wide compatibility.
|
||||
|
||||
## 4. DI composition
|
||||
|
||||
[`CompositionRoot.BuildServices`](../src/CaptureImage.App/CompositionRoot.cs)
|
||||
is the only place DI registrations live. No scanning, no convention, no
|
||||
assembly-level attributes — everything the runtime sees is explicit in
|
||||
one file.
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
subgraph "Cross-cutting"
|
||||
Log[ILogger*]
|
||||
FS[IFileSystem]
|
||||
Dispatcher[IUIThreadDispatcher]
|
||||
Loc[ILocalizationService]
|
||||
end
|
||||
|
||||
subgraph "Domain services"
|
||||
Settings[ISettingsStore]
|
||||
Steam[ISteamDetector]
|
||||
Procs[IProcessWatcher<br/>IProcessDetector]
|
||||
Cap[ICaptureEngine]
|
||||
Encoders[IImageEncoder × 2]
|
||||
Hotkey[IHotkeyService<br/>IHotkeyConflictSniffer]
|
||||
Update[IUpdateService]
|
||||
Orch[CaptureOrchestrator]
|
||||
end
|
||||
|
||||
subgraph "UI services"
|
||||
Toast[IToastService]
|
||||
Preview[IPreviewPresenter]
|
||||
Tray[ITrayIconHost]
|
||||
Nav[INavigationService]
|
||||
end
|
||||
|
||||
subgraph "ViewModels (singletons)"
|
||||
Main[MainWindowViewModel]
|
||||
Dash[DashboardViewModel]
|
||||
Set[SettingsViewModel]
|
||||
Hk[HotkeyBindingViewModel]
|
||||
About[AboutViewModel]
|
||||
Upd[UpdateViewModel]
|
||||
LogVM[LogViewerViewModel]
|
||||
end
|
||||
|
||||
Dash --> Settings
|
||||
Dash --> Procs
|
||||
Dash --> Orch
|
||||
Dash --> Hotkey
|
||||
Orch --> Cap
|
||||
Orch --> Encoders
|
||||
Orch --> FS
|
||||
Set --> Settings
|
||||
Set --> Loc
|
||||
Set --> Hk
|
||||
Hk --> Settings
|
||||
Hk --> Hotkey
|
||||
```
|
||||
|
||||
**Lifetimes:** every service and every viewmodel is a singleton. There
|
||||
is no request scope — the app is one long-running desktop process with
|
||||
a single window. `validateScopes: true` is on so DI misuse fails loudly
|
||||
at startup.
|
||||
|
||||
**Startup order:**
|
||||
|
||||
1. `VelopackApp.Build().Run()` — must be the first line of `Main` so
|
||||
Velopack can handle `--squirrel-install`, `--squirrel-firstrun`, etc.
|
||||
before Avalonia spins up.
|
||||
2. Serilog configured (file sink + in-memory ring buffer for the log
|
||||
drawer).
|
||||
3. `BuildServices(inMemorySink)` — container built.
|
||||
4. `ISettingsStore.LoadAsync()` — settings file read before any VM that
|
||||
depends on them is resolved.
|
||||
5. Avalonia `BuildAvaloniaApp().StartWithClassicDesktopLifetime(args)`.
|
||||
|
||||
## 5. i18n + RTL
|
||||
|
||||
Resources live as three sibling `.resx` files under
|
||||
[`src/CaptureImage.UI/Resources/Strings/`](../src/CaptureImage.UI/Resources/Strings):
|
||||
`Strings.resx` (en-US, neutral), `Strings.vi.resx`, `Strings.ar.resx`.
|
||||
MSBuild compiles them to satellite assemblies at build time. No
|
||||
Designer-generated wrapper — we use `ResourceManager` directly.
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant User
|
||||
participant Settings as SettingsViewModel
|
||||
participant Loc as ResxLocalizationService
|
||||
participant RM as ResourceManager
|
||||
participant XAML as Avalonia bindings
|
||||
|
||||
User->>Settings: Pick "العربية" in Language dropdown
|
||||
Settings->>Loc: SetCulture(ar-SA)
|
||||
Loc->>Loc: CurrentCulture = ar-SA<br/>CurrentFlowDirection = RightToLeft
|
||||
Loc-->>XAML: PropertyChanged("Item[]")
|
||||
XAML->>Loc: this["Settings_Hotkey"]
|
||||
Loc->>RM: GetString(key, ar-SA)
|
||||
RM-->>Loc: "مفتاح اختصار الالتقاط"
|
||||
Loc-->>XAML: string
|
||||
XAML-->>User: window mirrors + text flips
|
||||
```
|
||||
|
||||
**Key properties:**
|
||||
|
||||
- `PropertyChanged("Item[]")` is the magic indexer-binding refresh
|
||||
signal for Avalonia. Firing it once after a culture change refreshes
|
||||
every `{Binding Localization[...]}` in the tree.
|
||||
- `MainWindow.axaml` binds `FlowDirection` to
|
||||
`Localization.CurrentFlowDirection`. Arabic, Hebrew, Farsi, Urdu —
|
||||
any two-letter language code in the RTL set — mirrors the whole tree.
|
||||
- No app restart required. Every VM that stores localized text holds
|
||||
only the key, looks up via the indexer, and refreshes on the
|
||||
`PropertyChanged` broadcast.
|
||||
- Translations for VI and AR are machine-assisted today — see
|
||||
[`docs/legal/DISCLAIMER.md §4`](legal/DISCLAIMER.md). Native-speaker
|
||||
review is the next milestone's ask.
|
||||
|
||||
## 6. Update flow (Velopack)
|
||||
|
||||
[`VelopackUpdateService`](../src/CaptureImage.Infrastructure/Update/VelopackUpdateService.cs)
|
||||
wraps Velopack's `UpdateManager` pointed at the GitHub Releases source.
|
||||
Everything is explicit — no background timer, no silent upgrades. The
|
||||
user clicks **Check for updates**, optionally **Download**, optionally
|
||||
**Install and restart**.
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant Main as Program.Main
|
||||
participant Velo as VelopackApp
|
||||
participant User
|
||||
participant UI as UpdateView
|
||||
participant VM as UpdateViewModel
|
||||
participant Svc as VelopackUpdateService
|
||||
participant GH as GitHub Releases
|
||||
participant Mgr as UpdateManager
|
||||
|
||||
Main->>Velo: Build().Run(args)
|
||||
Note over Velo: Handles --squirrel-install,<br/>--squirrel-firstrun etc.<br/>then returns to caller
|
||||
Main->>Main: BuildAvaloniaApp()
|
||||
|
||||
User->>UI: Click "Check for updates"
|
||||
UI->>VM: CheckCommand
|
||||
VM->>Svc: CheckAsync()
|
||||
Svc->>Mgr: CheckForUpdatesAsync()
|
||||
Mgr->>GH: GET /releases/latest
|
||||
GH-->>Mgr: UpdateInfo (or null)
|
||||
Mgr-->>Svc: UpdateInfo
|
||||
Svc-->>VM: UpdateCheckResult
|
||||
VM-->>UI: Status + version + release notes
|
||||
|
||||
User->>UI: Click "Download"
|
||||
UI->>VM: DownloadCommand
|
||||
VM->>Svc: DownloadAsync(progress)
|
||||
Svc->>Mgr: DownloadUpdatesAsync(IProgress<int>)
|
||||
Mgr->>GH: GET /releases/.../CaptureImage-full.nupkg
|
||||
GH-->>Mgr: stream
|
||||
Mgr-->>Svc: done
|
||||
Svc-->>VM: Status=ReadyToInstall
|
||||
|
||||
User->>UI: Click "Install & restart"
|
||||
UI->>VM: InstallCommand
|
||||
VM->>Svc: ApplyAndRestart()
|
||||
Svc->>Mgr: ApplyUpdatesAndRestart()
|
||||
Note over Mgr: Velopack spawns Update.exe,<br/>kills current process,<br/>swaps files, relaunches
|
||||
```
|
||||
|
||||
**Development-mode caveat:** when the app is launched via
|
||||
`dotnet run` (not from a Velopack-installed location), `UpdateManager`
|
||||
reports `IsInstalled = false` and the service returns
|
||||
`UpdateStatus.Unavailable`. The update tab still renders, it just tells
|
||||
you updates are disabled and why. Release builds installed via `Setup.exe`
|
||||
have `IsInstalled = true` and the full flow works.
|
||||
|
||||
**Unsigned installer today.** Velopack can sign the installer if given a
|
||||
cert; CaptureImage doesn't have one yet (SignPath application was
|
||||
declined for v1.0). Users see Windows SmartScreen's "Unknown publisher"
|
||||
warning on first run. Integrity is still verifiable via the
|
||||
`SHA256SUMS.txt` published alongside every release.
|
||||
|
||||
---
|
||||
|
||||
## See also
|
||||
|
||||
- [`docs/RELEASING.md`](RELEASING.md) — how releases are cut and
|
||||
published.
|
||||
- [`docs/CONTRIBUTORS.md`](CONTRIBUTORS.md) — contribution flow, AI
|
||||
assistance policy, translation hand-off.
|
||||
- [`docs/legal/`](legal) — disclaimers, privacy, third-party notices.
|
||||
- The `Co-Authored-By` commit trailers naming Claude Opus 4.7 — see
|
||||
the git log for per-milestone design notes that influenced this
|
||||
architecture.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 145 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 186 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 54 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
@@ -10,6 +10,9 @@
|
||||
<UseWpf>false</UseWpf>
|
||||
<!-- App icon + manifest are added in M4 -->
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<!-- Release value for v1.1.0; release.yml still overrides via /p:Version=<git-tag>
|
||||
for tag-driven builds. Bump to the next -dev suffix after the release lands. -->
|
||||
<Version>1.1.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -78,6 +78,7 @@ internal static class CompositionRoot
|
||||
|
||||
// --- Hotkeys -----------------------------------------------------------
|
||||
services.AddSingleton<IHotkeyService, SharpHookHotkeyService>();
|
||||
services.AddSingleton<IHotkeyConflictSniffer, HotkeyConflictSniffer>();
|
||||
|
||||
// --- Updates -----------------------------------------------------------
|
||||
services.AddSingleton<IUpdateService, VelopackUpdateService>();
|
||||
@@ -94,6 +95,7 @@ internal static class CompositionRoot
|
||||
services.AddSingleton<MainWindowViewModel>();
|
||||
services.AddSingleton<DashboardViewModel>();
|
||||
services.AddSingleton<UpdateViewModel>();
|
||||
services.AddSingleton<HotkeyBindingViewModel>();
|
||||
services.AddSingleton<SettingsViewModel>();
|
||||
services.AddSingleton<AboutViewModel>();
|
||||
services.AddSingleton<LogViewerViewModel>();
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using CaptureImage.Core.Models;
|
||||
|
||||
namespace CaptureImage.Core.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Platform-neutral test: is this hotkey binding already owned by another process?
|
||||
/// Implementations perform a best-effort check (e.g. Windows <c>RegisterHotKey</c> sniff)
|
||||
/// and immediately release any claim they take — they must never leave the combination
|
||||
/// bound after the call returns.
|
||||
/// </summary>
|
||||
public interface IHotkeyConflictSniffer
|
||||
{
|
||||
/// <summary>
|
||||
/// <c>true</c> if the combination is already registered by another process or the
|
||||
/// shell; <c>false</c> if we successfully (and transiently) claimed it. Returning
|
||||
/// <c>false</c> does not prove the combination will work — the Windows shell has
|
||||
/// higher priority and consumes some combos before <c>RegisterHotKey</c> is consulted
|
||||
/// (see <see cref="Validation.ReservedHotkeys"/>).
|
||||
/// </summary>
|
||||
bool IsConflicted(HotkeyBinding binding);
|
||||
}
|
||||
@@ -2,9 +2,29 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using CaptureImage.Core.Validation;
|
||||
|
||||
namespace CaptureImage.Core.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Outcome of <see cref="HotkeyBinding.Validate"/>. UI inspects this to render the right
|
||||
/// error or warning string; persistence layer only persists bindings whose result is
|
||||
/// <see cref="Ok"/>.
|
||||
/// </summary>
|
||||
public enum HotkeyValidationResult
|
||||
{
|
||||
/// <summary>Binding is acceptable for use.</summary>
|
||||
Ok,
|
||||
/// <summary>No primary (non-modifier) key — e.g. only Ctrl pressed.</summary>
|
||||
NoPrimaryKey,
|
||||
/// <summary><see cref="HotkeyBinding.VirtualKey"/> is itself a modifier VK (Shift/Ctrl/Alt/Win).</summary>
|
||||
ModifierOnlyKey,
|
||||
/// <summary>Plain letter/digit without any modifier — too easy to trigger while typing.</summary>
|
||||
RequiresModifier,
|
||||
/// <summary>Combination is owned by the Windows shell (<see cref="ReservedHotkeys"/>).</summary>
|
||||
ReservedByWindows,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modifier flags for a global hotkey. Values match the common Win32 MOD_* constants
|
||||
/// so Infrastructure can forward to <c>RegisterHotKey</c> without re-mapping.
|
||||
@@ -46,6 +66,41 @@ public readonly record struct HotkeyBinding(HotkeyModifiers Modifiers, uint Virt
|
||||
public static HotkeyBinding Default =>
|
||||
new(HotkeyModifiers.Control | HotkeyModifiers.Shift, 0x7B); // VK_F12 = 0x7B
|
||||
|
||||
/// <summary>
|
||||
/// Classify this binding for use in the UI rebinder. See <see cref="HotkeyValidationResult"/>
|
||||
/// for possible outcomes. Pure function — does not touch Windows state.
|
||||
/// </summary>
|
||||
public HotkeyValidationResult Validate()
|
||||
{
|
||||
if (VirtualKey == 0)
|
||||
return HotkeyValidationResult.NoPrimaryKey;
|
||||
|
||||
if (IsModifierVk(VirtualKey))
|
||||
return HotkeyValidationResult.ModifierOnlyKey;
|
||||
|
||||
if (Modifiers == HotkeyModifiers.None && !IsFunctionOrSpecial(VirtualKey))
|
||||
return HotkeyValidationResult.RequiresModifier;
|
||||
|
||||
if (ReservedHotkeys.IsReserved(this))
|
||||
return HotkeyValidationResult.ReservedByWindows;
|
||||
|
||||
return HotkeyValidationResult.Ok;
|
||||
}
|
||||
|
||||
/// <summary>True when <see cref="Validate"/> returns <see cref="HotkeyValidationResult.Ok"/>.</summary>
|
||||
public bool IsValid() => Validate() == HotkeyValidationResult.Ok;
|
||||
|
||||
private static bool IsModifierVk(uint vk) => vk is
|
||||
0x10 or 0x11 or 0x12 or // VK_SHIFT, VK_CONTROL, VK_MENU (Alt)
|
||||
0x5B or 0x5C or // VK_LWIN, VK_RWIN
|
||||
0xA0 or 0xA1 or // VK_LSHIFT, VK_RSHIFT
|
||||
0xA2 or 0xA3 or // VK_LCONTROL, VK_RCONTROL
|
||||
0xA4 or 0xA5; // VK_LMENU, VK_RMENU
|
||||
|
||||
private static bool IsFunctionOrSpecial(uint vk) =>
|
||||
(vk >= 0x70 && vk <= 0x87) || // F1..F24
|
||||
vk == 0x2C; // VK_SNAPSHOT (PrintScreen)
|
||||
|
||||
/// <summary>
|
||||
/// Short display name for a VK code. Only covers the keys we care about; unknown codes
|
||||
/// fall back to a hex representation so nothing crashes.
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CaptureImage.Core.Models;
|
||||
|
||||
namespace CaptureImage.Core.Validation;
|
||||
|
||||
/// <summary>
|
||||
/// Catalogue of hotkey combinations reserved by the Windows shell. Binding one of these
|
||||
/// still registers on our side, but Windows consumes the key press before our hook sees
|
||||
/// it, so the <see cref="Core.Abstractions.IHotkeyService"/> would silently never fire.
|
||||
/// The Settings UI uses this to warn the user before they persist an unreachable combo.
|
||||
/// </summary>
|
||||
public static class ReservedHotkeys
|
||||
{
|
||||
private static readonly HotkeyBinding[] ReservedList =
|
||||
{
|
||||
// Lock / session
|
||||
new(HotkeyModifiers.Win, 0x4C), // Win+L — lock workstation
|
||||
// Shell navigation
|
||||
new(HotkeyModifiers.Win, 0x44), // Win+D — show desktop
|
||||
new(HotkeyModifiers.Win, 0x45), // Win+E — File Explorer
|
||||
new(HotkeyModifiers.Win, 0x52), // Win+R — Run dialog
|
||||
new(HotkeyModifiers.Win, 0x49), // Win+I — Settings
|
||||
new(HotkeyModifiers.Win, 0x58), // Win+X — power menu
|
||||
new(HotkeyModifiers.Win, 0x4D), // Win+M — minimize all
|
||||
new(HotkeyModifiers.Win, 0x09), // Win+Tab — Task View
|
||||
// Window snapping
|
||||
new(HotkeyModifiers.Win, 0x25), // Win+Left
|
||||
new(HotkeyModifiers.Win, 0x26), // Win+Up
|
||||
new(HotkeyModifiers.Win, 0x27), // Win+Right
|
||||
new(HotkeyModifiers.Win, 0x28), // Win+Down
|
||||
// Task Manager / Security
|
||||
new(HotkeyModifiers.Control | HotkeyModifiers.Shift, 0x1B), // Ctrl+Shift+Esc
|
||||
new(HotkeyModifiers.Control | HotkeyModifiers.Alt, 0x2E), // Ctrl+Alt+Del (also intercepted by kernel)
|
||||
// Window management owned by Alt
|
||||
new(HotkeyModifiers.Alt, 0x09), // Alt+Tab
|
||||
new(HotkeyModifiers.Alt, 0x73), // Alt+F4
|
||||
};
|
||||
|
||||
public static IReadOnlyList<HotkeyBinding> All => ReservedList;
|
||||
|
||||
public static bool IsReserved(HotkeyBinding binding) =>
|
||||
ReservedList.Any(r => r == binding);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Threading;
|
||||
using CaptureImage.Core.Abstractions;
|
||||
using CaptureImage.Core.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CaptureImage.Infrastructure.Hotkeys;
|
||||
|
||||
/// <summary>
|
||||
/// Windows implementation of <see cref="IHotkeyConflictSniffer"/>. Uses
|
||||
/// <c>RegisterHotKey</c> with <c>HWND=NULL</c> — per Win32 docs that posts
|
||||
/// <c>WM_HOTKEY</c> to the calling thread's queue, which is fine here because
|
||||
/// we release the registration immediately.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The <see cref="HotkeyModifiers"/> flag values deliberately match the Win32
|
||||
/// <c>MOD_*</c> constants so no re-mapping is needed. Bindings flagged by
|
||||
/// <see cref="Validation.ReservedHotkeys"/> often still register successfully
|
||||
/// here (Windows gets to eat the keypress first), so both checks are needed.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
[SupportedOSPlatform("windows10.0.22621.0")]
|
||||
public sealed partial class HotkeyConflictSniffer : IHotkeyConflictSniffer
|
||||
{
|
||||
// Start well clear of the 0x0000-0xBFFF range used by application-defined
|
||||
// hotkeys so accidental collision with another part of the process is unlikely.
|
||||
private static int _nextId = 0x7100;
|
||||
|
||||
private readonly ILogger<HotkeyConflictSniffer> _logger;
|
||||
|
||||
public HotkeyConflictSniffer(ILogger<HotkeyConflictSniffer> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public bool IsConflicted(HotkeyBinding binding)
|
||||
{
|
||||
if (!binding.IsValid())
|
||||
{
|
||||
// Invalid bindings can't conflict with anything meaningful.
|
||||
return false;
|
||||
}
|
||||
|
||||
var id = Interlocked.Increment(ref _nextId);
|
||||
var mods = (uint)binding.Modifiers;
|
||||
|
||||
if (RegisterHotKey(IntPtr.Zero, id, mods, binding.VirtualKey))
|
||||
{
|
||||
UnregisterHotKey(IntPtr.Zero, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
var err = Marshal.GetLastWin32Error();
|
||||
_logger.LogDebug(
|
||||
"RegisterHotKey sniff failed for {Binding} (win32 error {Err}); treating as conflicted.",
|
||||
binding, err);
|
||||
return true;
|
||||
}
|
||||
|
||||
[LibraryImport("user32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
|
||||
|
||||
[LibraryImport("user32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool UnregisterHotKey(IntPtr hWnd, int id);
|
||||
}
|
||||
@@ -5,6 +5,48 @@
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme />
|
||||
|
||||
<!--
|
||||
Visual system conventions (enforced through this file + view-level overrides):
|
||||
|
||||
FontFamily : Inter (shipped via Avalonia.Fonts.Inter) with Segoe UI fallback;
|
||||
monospace (Consolas/Courier New) only for log entries + hotkey
|
||||
display where fixed glyph width carries meaning.
|
||||
FontSize : 11 (caption) / 12 (small) / 13 (body) / 14 (body-strong) /
|
||||
16 (subtitle) / 22 (title).
|
||||
CornerRadius: 8 px for cards, borders, containers. 4 px reserved for inline
|
||||
badges/pills (e.g. Dashboard Steam badge).
|
||||
Spacing : 4 / 8 / 12 / 16 / 24 px scale — every Margin, Padding, Spacing
|
||||
value in a view should snap to one of these.
|
||||
Contrast : secondary text uses SystemControlForegroundBaseMediumBrush,
|
||||
not Opacity="0.6" — the theme brush keeps WCAG AA contrast on
|
||||
both light and dark variants.
|
||||
-->
|
||||
|
||||
<!-- Default UI text stack. View-level FontFamily overrides remain for monospace blocks. -->
|
||||
<Style Selector="TextBlock">
|
||||
<Setter Property="FontFamily" Value="Inter, Segoe UI, sans-serif" />
|
||||
</Style>
|
||||
<Style Selector="TextBox">
|
||||
<Setter Property="FontFamily" Value="Inter, Segoe UI, sans-serif" />
|
||||
</Style>
|
||||
<Style Selector="Button">
|
||||
<Setter Property="FontFamily" Value="Inter, Segoe UI, sans-serif" />
|
||||
</Style>
|
||||
<Style Selector="ComboBox">
|
||||
<Setter Property="FontFamily" Value="Inter, Segoe UI, sans-serif" />
|
||||
</Style>
|
||||
<Style Selector="CheckBox">
|
||||
<Setter Property="FontFamily" Value="Inter, Segoe UI, sans-serif" />
|
||||
</Style>
|
||||
|
||||
<!-- Visible focus ring on list items. FluentTheme provides selection state styling
|
||||
but no keyboard-focus outline; this ensures the :focus-visible pseudo-class
|
||||
draws a border in the accent colour when a user tabs through the target list. -->
|
||||
<Style Selector="ListBoxItem:focus-visible">
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource SystemControlHighlightAccentBrush}" />
|
||||
<Setter Property="BorderThickness" Value="2" />
|
||||
</Style>
|
||||
</Application.Styles>
|
||||
|
||||
</Application>
|
||||
@@ -0,0 +1,86 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="clr-namespace:CaptureImage.ViewModels.Settings;assembly=CaptureImage.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
x:Class="CaptureImage.UI.Controls.HotkeyRecorder"
|
||||
x:DataType="vm:HotkeyBindingViewModel">
|
||||
|
||||
<UserControl.Styles>
|
||||
<!-- Keyboard-focus ring on the BindingField. Fluent's default border is a neutral grey;
|
||||
flip it to the accent brush when the control has focus so tab navigation is
|
||||
visible and the recording-mode prompt is clearly "waiting on you". -->
|
||||
<Style Selector="Border#BindingField:focus">
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource SystemControlHighlightAccentBrush}" />
|
||||
<Setter Property="BorderThickness" Value="2" />
|
||||
</Style>
|
||||
</UserControl.Styles>
|
||||
|
||||
<StackPanel Spacing="8">
|
||||
|
||||
<Grid ColumnDefinitions="*,8,Auto,8,Auto">
|
||||
|
||||
<!-- The keyboard-focused surface. Receives KeyDown events while recording; shows the
|
||||
current binding while idle. Focused programmatically from code-behind when
|
||||
IsRecording flips to true. -->
|
||||
<Border Grid.Column="0"
|
||||
Name="BindingField"
|
||||
Focusable="True"
|
||||
MinHeight="34"
|
||||
CornerRadius="8"
|
||||
Padding="12,8"
|
||||
BorderThickness="1"
|
||||
BorderBrush="{DynamicResource SystemControlForegroundBaseMediumLowBrush}"
|
||||
Background="{DynamicResource SystemControlBackgroundChromeMediumLowBrush}"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.Name="{Binding Localization[Settings_Hotkey]}"
|
||||
AutomationProperties.HelpText="{Binding Localization[Settings_HotkeyRecorderPrompt]}">
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding DisplayText}"
|
||||
FontFamily="Consolas, Courier New, monospace"
|
||||
VerticalAlignment="Center"
|
||||
IsVisible="{Binding !IsRecording}" />
|
||||
<TextBlock Text="{Binding Localization[Settings_HotkeyRecorderPrompt]}"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
|
||||
FontStyle="Italic"
|
||||
VerticalAlignment="Center"
|
||||
IsVisible="{Binding IsRecording}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Button Grid.Column="2"
|
||||
Content="{Binding Localization[Settings_HotkeyRecord]}"
|
||||
Command="{Binding StartRecordingCommand}"
|
||||
IsVisible="{Binding !IsRecording}"
|
||||
MinWidth="80" />
|
||||
<Button Grid.Column="2"
|
||||
Content="{Binding Localization[Settings_HotkeyCancel]}"
|
||||
Command="{Binding CancelRecordingCommand}"
|
||||
IsVisible="{Binding IsRecording}"
|
||||
MinWidth="80" />
|
||||
|
||||
<Button Grid.Column="4"
|
||||
Content="{Binding Localization[Settings_HotkeyReset]}"
|
||||
Command="{Binding ResetToDefaultCommand}"
|
||||
IsVisible="{Binding !IsRecording}"
|
||||
MinWidth="80" />
|
||||
</Grid>
|
||||
|
||||
<!-- Validation error — visible only after a rejected commit. -->
|
||||
<TextBlock Text="{Binding ErrorMessage}"
|
||||
Foreground="#D13438"
|
||||
FontSize="11"
|
||||
TextWrapping="Wrap"
|
||||
IsVisible="{Binding HasError}" />
|
||||
|
||||
<!-- Conflict warning — non-blocking, binding already persisted. -->
|
||||
<TextBlock Text="{Binding Localization[Settings_HotkeyConflictWarning]}"
|
||||
Foreground="#C19C00"
|
||||
FontSize="11"
|
||||
TextWrapping="Wrap"
|
||||
IsVisible="{Binding ConflictDetected}" />
|
||||
|
||||
</StackPanel>
|
||||
|
||||
</UserControl>
|
||||
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using CaptureImage.Core.Models;
|
||||
using CaptureImage.ViewModels.Settings;
|
||||
|
||||
namespace CaptureImage.UI.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Keyboard-driven rebinder for <see cref="HotkeyBinding"/>. Owns no state itself —
|
||||
/// it forwards completed combinations to the attached <see cref="HotkeyBindingViewModel"/>
|
||||
/// and reads validation / conflict flags back to drive its own visibility.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// We map <see cref="Key"/> (Avalonia) to the Win32 virtual-key code because the backing
|
||||
/// <c>HotkeyBinding</c> persists VKs. SharpHook would give us VK codes directly but it
|
||||
/// lives in Infrastructure and the whole point of this control is to stay reusable from
|
||||
/// the UI layer without a back-channel to the global hook.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>IME caveat:</b> Ctrl/Alt/Win-qualified combos bypass most IMEs (including VN telex
|
||||
/// and Arabic input), so the recorder should be stable on those layouts. A truly bare
|
||||
/// letter press would route through the IME — we require at least one modifier for all
|
||||
/// non-function keys via <see cref="HotkeyBinding.Validate"/>, so this doesn't matter in
|
||||
/// practice.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public partial class HotkeyRecorder : UserControl
|
||||
{
|
||||
private HotkeyBindingViewModel? _vm;
|
||||
|
||||
public HotkeyRecorder()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContextChanged += OnDataContextChanged;
|
||||
KeyDown += OnKeyDown;
|
||||
}
|
||||
|
||||
private void OnDataContextChanged(object? sender, EventArgs e)
|
||||
{
|
||||
if (_vm is not null)
|
||||
_vm.PropertyChanged -= OnVmPropertyChanged;
|
||||
|
||||
_vm = DataContext as HotkeyBindingViewModel;
|
||||
|
||||
if (_vm is not null)
|
||||
_vm.PropertyChanged += OnVmPropertyChanged;
|
||||
}
|
||||
|
||||
private void OnVmPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(HotkeyBindingViewModel.IsRecording)
|
||||
&& _vm?.IsRecording == true)
|
||||
{
|
||||
// Grab keyboard focus so the next key press lands on our handler. Posted via
|
||||
// the dispatcher so the focus move happens after the current click has fully
|
||||
// settled — calling Focus() inline sometimes races with Avalonia reassigning
|
||||
// focus when the Record button collapses.
|
||||
Avalonia.Threading.Dispatcher.UIThread.Post(() => BindingField.Focus());
|
||||
}
|
||||
}
|
||||
|
||||
private void OnKeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
if (_vm is null || !_vm.IsRecording) return;
|
||||
|
||||
// Esc alone cancels without committing.
|
||||
if (e.Key == Key.Escape && e.KeyModifiers == KeyModifiers.None)
|
||||
{
|
||||
_vm.CancelRecordingCommand.Execute(null);
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var vk = AvaloniaKeyToWin32Vk(e.Key);
|
||||
if (vk is null)
|
||||
{
|
||||
// Pure modifier or an unmapped key — wait for a real combination.
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var mods = HotkeyModifiers.None;
|
||||
if ((e.KeyModifiers & KeyModifiers.Control) != 0) mods |= HotkeyModifiers.Control;
|
||||
if ((e.KeyModifiers & KeyModifiers.Alt) != 0) mods |= HotkeyModifiers.Alt;
|
||||
if ((e.KeyModifiers & KeyModifiers.Shift) != 0) mods |= HotkeyModifiers.Shift;
|
||||
if ((e.KeyModifiers & KeyModifiers.Meta) != 0) mods |= HotkeyModifiers.Win;
|
||||
|
||||
_vm.TryCommitRecorded(new HotkeyBinding(mods, vk.Value));
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Map Avalonia's platform-neutral <see cref="Key"/> enum to Win32 virtual-key codes
|
||||
/// (<c>VK_*</c>). Returns <c>null</c> for pure modifier keys and anything we don't
|
||||
/// bind for a capture hotkey — e.g. media keys, IME-specific modes.
|
||||
/// </summary>
|
||||
private static uint? AvaloniaKeyToWin32Vk(Key key)
|
||||
{
|
||||
// Letters A-Z → 0x41..0x5A. Avalonia keeps these contiguous.
|
||||
if (key >= Key.A && key <= Key.Z)
|
||||
return 0x41u + (uint)(key - Key.A);
|
||||
|
||||
// Top-row digits 0-9 → 0x30..0x39.
|
||||
if (key >= Key.D0 && key <= Key.D9)
|
||||
return 0x30u + (uint)(key - Key.D0);
|
||||
|
||||
// Function keys F1-F24 → 0x70..0x87.
|
||||
if (key >= Key.F1 && key <= Key.F24)
|
||||
return 0x70u + (uint)(key - Key.F1);
|
||||
|
||||
// Numpad 0-9 → 0x60..0x69.
|
||||
if (key >= Key.NumPad0 && key <= Key.NumPad9)
|
||||
return 0x60u + (uint)(key - Key.NumPad0);
|
||||
|
||||
return key switch
|
||||
{
|
||||
Key.Tab => 0x09u,
|
||||
Key.Return => 0x0Du,
|
||||
Key.Space => 0x20u,
|
||||
Key.Back => 0x08u,
|
||||
Key.Escape => 0x1Bu,
|
||||
Key.Insert => 0x2Du,
|
||||
Key.Delete => 0x2Eu,
|
||||
Key.Home => 0x24u,
|
||||
Key.End => 0x23u,
|
||||
Key.PageUp => 0x21u,
|
||||
Key.PageDown => 0x22u,
|
||||
Key.Left => 0x25u,
|
||||
Key.Up => 0x26u,
|
||||
Key.Right => 0x27u,
|
||||
Key.Down => 0x28u,
|
||||
Key.PrintScreen => 0x2Cu,
|
||||
Key.Pause => 0x13u,
|
||||
Key.Multiply => 0x6Au,
|
||||
Key.Add => 0x6Bu,
|
||||
Key.Subtract => 0x6Du,
|
||||
Key.Decimal => 0x6Eu,
|
||||
Key.Divide => 0x6Fu,
|
||||
// Anything else (modifiers, IME modes, media keys) → not bindable.
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="models:ToastItem">
|
||||
<Border CornerRadius="6"
|
||||
<Border CornerRadius="8"
|
||||
Background="{DynamicResource SystemControlBackgroundChromeMediumBrush}"
|
||||
BorderBrush="{Binding Kind, Converter={x:Static conv:ToastKindToBrushConverter.Instance}}"
|
||||
BorderThickness="0,0,0,3"
|
||||
|
||||
@@ -52,6 +52,8 @@
|
||||
<data name="Dashboard_StatusFailed" xml:space="preserve"><value>فشل الالتقاط ({0}): {1}</value></data>
|
||||
<data name="Dashboard_TargetsCount" xml:space="preserve"><value>{0} هدف/أهداف متاح</value></data>
|
||||
<data name="Dashboard_Loading" xml:space="preserve"><value>جاري التحميل…</value></data>
|
||||
<data name="Dashboard_EmptyState" xml:space="preserve"><value>لا توجد نوافذ مرئية للالتقاط — شغّل لعبتك أو تطبيقك، ثم انقر على تحديث.</value></data>
|
||||
<data name="Dashboard_LogToggle" xml:space="preserve"><value>تبديل درج السجل في الوقت الفعلي</value></data>
|
||||
<data name="Dashboard_SteamBadge" xml:space="preserve"><value>STEAM</value></data>
|
||||
<data name="Dashboard_SteamBadgeTooltip" xml:space="preserve"><value>لعبة Steam: {0} (AppId {1}). F12 متاح عبر Steam Overlay. بعض الألعاب المحمية بـ anti-cheat قد تمنع الالتقاط الخارجي.</value></data>
|
||||
|
||||
@@ -60,7 +62,16 @@
|
||||
<data name="Settings_Language" xml:space="preserve"><value>اللغة</value></data>
|
||||
<data name="Settings_Theme" xml:space="preserve"><value>المظهر</value></data>
|
||||
<data name="Settings_Hotkey" xml:space="preserve"><value>مفتاح اختصار الالتقاط</value></data>
|
||||
<data name="Settings_HotkeyHint" xml:space="preserve"><value>افتراضي: Ctrl+Shift+F12. تحرير مفتاح الاختصار في المراحل القادمة.</value></data>
|
||||
<data name="Settings_HotkeyHint" xml:space="preserve"><value>انقر تسجيل ثم اضغط على مجموعة مفاتيح. Esc للإلغاء. إعادة التعيين تستعيد Ctrl+Shift+F12.</value></data>
|
||||
<data name="Settings_HotkeyRecord" xml:space="preserve"><value>تسجيل…</value></data>
|
||||
<data name="Settings_HotkeyCancel" xml:space="preserve"><value>إلغاء</value></data>
|
||||
<data name="Settings_HotkeyReset" xml:space="preserve"><value>إعادة تعيين</value></data>
|
||||
<data name="Settings_HotkeyRecorderPrompt" xml:space="preserve"><value>اضغط على مجموعة مفاتيح (Esc للإلغاء)…</value></data>
|
||||
<data name="Settings_HotkeyErrorNoPrimary" xml:space="preserve"><value>حدد مفتاحًا رئيسيًا (مثل حرف أو مفتاح F).</value></data>
|
||||
<data name="Settings_HotkeyErrorModifierOnly" xml:space="preserve"><value>مفتاح التعديل وحده غير كافٍ — أضف حرفًا أو مفتاح F.</value></data>
|
||||
<data name="Settings_HotkeyErrorNeedsModifier" xml:space="preserve"><value>الحروف والأرقام العادية تحتاج إلى مفتاح تعديل واحد على الأقل (Ctrl/Alt/Shift/Win).</value></data>
|
||||
<data name="Settings_HotkeyErrorReserved" xml:space="preserve"><value>هذه المجموعة محجوزة من قبل Windows ولا يمكن التقاطها.</value></data>
|
||||
<data name="Settings_HotkeyConflictWarning" xml:space="preserve"><value>قد يستخدم تطبيق آخر هذه المجموعة بالفعل — قد لا تعمل أثناء تشغيل ذلك التطبيق.</value></data>
|
||||
<data name="Settings_Format" xml:space="preserve"><value>التنسيق الافتراضي</value></data>
|
||||
<data name="Settings_JpegQuality" xml:space="preserve"><value>جودة JPEG</value></data>
|
||||
<data name="Settings_WebpQuality" xml:space="preserve"><value>جودة WebP</value></data>
|
||||
@@ -112,6 +123,8 @@
|
||||
<data name="Log_Resume" xml:space="preserve"><value>استئناف</value></data>
|
||||
<data name="Log_Clear" xml:space="preserve"><value>مسح</value></data>
|
||||
<data name="Log_Export" xml:space="preserve"><value>تصدير…</value></data>
|
||||
<data name="Log_EventsCount" xml:space="preserve"><value>{0} حدث</value></data>
|
||||
<data name="Log_EmptyState" xml:space="preserve"><value>لا توجد أحداث سجل بعد. ستظهر الأحداث المباشرة من محرك الالتقاط هنا.</value></data>
|
||||
|
||||
<!-- Preview -->
|
||||
<data name="Preview_Title" xml:space="preserve"><value>معاينة</value></data>
|
||||
|
||||
@@ -52,6 +52,8 @@
|
||||
<data name="Dashboard_StatusFailed" xml:space="preserve"><value>Capture failed ({0}): {1}</value></data>
|
||||
<data name="Dashboard_TargetsCount" xml:space="preserve"><value>{0} target(s) visible</value></data>
|
||||
<data name="Dashboard_Loading" xml:space="preserve"><value>Loading…</value></data>
|
||||
<data name="Dashboard_EmptyState" xml:space="preserve"><value>No visible windows to capture — launch your game or app, then click Refresh.</value></data>
|
||||
<data name="Dashboard_LogToggle" xml:space="preserve"><value>Toggle real-time log drawer</value></data>
|
||||
<data name="Dashboard_SteamBadge" xml:space="preserve"><value>STEAM</value></data>
|
||||
<data name="Dashboard_SteamBadgeTooltip" xml:space="preserve"><value>Steam game: {0} (AppId {1}). F12 screenshot is available via Steam Overlay. Some anti-cheat protected games may block external capture.</value></data>
|
||||
|
||||
@@ -60,7 +62,16 @@
|
||||
<data name="Settings_Language" xml:space="preserve"><value>Language</value></data>
|
||||
<data name="Settings_Theme" xml:space="preserve"><value>Theme</value></data>
|
||||
<data name="Settings_Hotkey" xml:space="preserve"><value>Capture hotkey</value></data>
|
||||
<data name="Settings_HotkeyHint" xml:space="preserve"><value>Default: Ctrl+Shift+F12. Hotkey editing lands in a future milestone.</value></data>
|
||||
<data name="Settings_HotkeyHint" xml:space="preserve"><value>Click Record and press a combination. Esc cancels. Reset restores Ctrl+Shift+F12.</value></data>
|
||||
<data name="Settings_HotkeyRecord" xml:space="preserve"><value>Record…</value></data>
|
||||
<data name="Settings_HotkeyCancel" xml:space="preserve"><value>Cancel</value></data>
|
||||
<data name="Settings_HotkeyReset" xml:space="preserve"><value>Reset</value></data>
|
||||
<data name="Settings_HotkeyRecorderPrompt" xml:space="preserve"><value>Press a key combination (Esc to cancel)…</value></data>
|
||||
<data name="Settings_HotkeyErrorNoPrimary" xml:space="preserve"><value>Select a primary key (e.g. a letter or an F-key).</value></data>
|
||||
<data name="Settings_HotkeyErrorModifierOnly" xml:space="preserve"><value>A modifier key alone isn't enough — add a letter or an F-key.</value></data>
|
||||
<data name="Settings_HotkeyErrorNeedsModifier" xml:space="preserve"><value>Plain letters and digits need at least one modifier (Ctrl/Alt/Shift/Win).</value></data>
|
||||
<data name="Settings_HotkeyErrorReserved" xml:space="preserve"><value>This combination is reserved by Windows and cannot be captured.</value></data>
|
||||
<data name="Settings_HotkeyConflictWarning" xml:space="preserve"><value>Another application may already own this combination — it might not fire while that app is running.</value></data>
|
||||
<data name="Settings_Format" xml:space="preserve"><value>Default format</value></data>
|
||||
<data name="Settings_JpegQuality" xml:space="preserve"><value>JPEG quality</value></data>
|
||||
<data name="Settings_WebpQuality" xml:space="preserve"><value>WebP quality</value></data>
|
||||
@@ -112,6 +123,8 @@
|
||||
<data name="Log_Resume" xml:space="preserve"><value>Resume</value></data>
|
||||
<data name="Log_Clear" xml:space="preserve"><value>Clear</value></data>
|
||||
<data name="Log_Export" xml:space="preserve"><value>Export…</value></data>
|
||||
<data name="Log_EventsCount" xml:space="preserve"><value>{0} events</value></data>
|
||||
<data name="Log_EmptyState" xml:space="preserve"><value>No log events yet. Live events from the capture engine will appear here.</value></data>
|
||||
|
||||
<!-- Preview -->
|
||||
<data name="Preview_Title" xml:space="preserve"><value>Preview</value></data>
|
||||
|
||||
@@ -52,6 +52,8 @@
|
||||
<data name="Dashboard_StatusFailed" xml:space="preserve"><value>Chụp lỗi ({0}): {1}</value></data>
|
||||
<data name="Dashboard_TargetsCount" xml:space="preserve"><value>{0} đối tượng khả dụng</value></data>
|
||||
<data name="Dashboard_Loading" xml:space="preserve"><value>Đang tải…</value></data>
|
||||
<data name="Dashboard_EmptyState" xml:space="preserve"><value>Không có cửa sổ nào để chụp — khởi chạy game hoặc ứng dụng của bạn, rồi bấm Làm mới.</value></data>
|
||||
<data name="Dashboard_LogToggle" xml:space="preserve"><value>Bật/tắt khay nhật ký thời gian thực</value></data>
|
||||
<data name="Dashboard_SteamBadge" xml:space="preserve"><value>STEAM</value></data>
|
||||
<data name="Dashboard_SteamBadgeTooltip" xml:space="preserve"><value>Game Steam: {0} (AppId {1}). Phím F12 có sẵn qua Steam Overlay. Một số game có anti-cheat có thể chặn capture từ bên ngoài.</value></data>
|
||||
|
||||
@@ -60,7 +62,16 @@
|
||||
<data name="Settings_Language" xml:space="preserve"><value>Ngôn ngữ</value></data>
|
||||
<data name="Settings_Theme" xml:space="preserve"><value>Giao diện</value></data>
|
||||
<data name="Settings_Hotkey" xml:space="preserve"><value>Hotkey chụp</value></data>
|
||||
<data name="Settings_HotkeyHint" xml:space="preserve"><value>Mặc định: Ctrl+Shift+F12. Chỉnh sửa hotkey sẽ có trong milestone sau.</value></data>
|
||||
<data name="Settings_HotkeyHint" xml:space="preserve"><value>Nhấn Ghi rồi nhấn tổ hợp phím. Esc để huỷ. Đặt lại sẽ khôi phục Ctrl+Shift+F12.</value></data>
|
||||
<data name="Settings_HotkeyRecord" xml:space="preserve"><value>Ghi…</value></data>
|
||||
<data name="Settings_HotkeyCancel" xml:space="preserve"><value>Huỷ</value></data>
|
||||
<data name="Settings_HotkeyReset" xml:space="preserve"><value>Đặt lại</value></data>
|
||||
<data name="Settings_HotkeyRecorderPrompt" xml:space="preserve"><value>Nhấn tổ hợp phím (Esc để huỷ)…</value></data>
|
||||
<data name="Settings_HotkeyErrorNoPrimary" xml:space="preserve"><value>Chọn một phím chính (ví dụ chữ cái hoặc phím F).</value></data>
|
||||
<data name="Settings_HotkeyErrorModifierOnly" xml:space="preserve"><value>Chỉ phím bổ trợ là chưa đủ — hãy thêm chữ cái hoặc phím F.</value></data>
|
||||
<data name="Settings_HotkeyErrorNeedsModifier" xml:space="preserve"><value>Chữ cái hoặc chữ số cần kèm ít nhất một phím bổ trợ (Ctrl/Alt/Shift/Win).</value></data>
|
||||
<data name="Settings_HotkeyErrorReserved" xml:space="preserve"><value>Tổ hợp này bị Windows giữ và không thể chụp được.</value></data>
|
||||
<data name="Settings_HotkeyConflictWarning" xml:space="preserve"><value>Ứng dụng khác có thể đã đăng ký tổ hợp này — nó có thể không kích hoạt khi ứng dụng đó đang chạy.</value></data>
|
||||
<data name="Settings_Format" xml:space="preserve"><value>Định dạng mặc định</value></data>
|
||||
<data name="Settings_JpegQuality" xml:space="preserve"><value>Chất lượng JPEG</value></data>
|
||||
<data name="Settings_WebpQuality" xml:space="preserve"><value>Chất lượng WebP</value></data>
|
||||
@@ -112,6 +123,8 @@
|
||||
<data name="Log_Resume" xml:space="preserve"><value>Tiếp tục</value></data>
|
||||
<data name="Log_Clear" xml:space="preserve"><value>Xoá</value></data>
|
||||
<data name="Log_Export" xml:space="preserve"><value>Xuất…</value></data>
|
||||
<data name="Log_EventsCount" xml:space="preserve"><value>{0} sự kiện</value></data>
|
||||
<data name="Log_EmptyState" xml:space="preserve"><value>Chưa có sự kiện nhật ký nào. Sự kiện thời gian thực từ capture engine sẽ xuất hiện ở đây.</value></data>
|
||||
|
||||
<!-- Preview -->
|
||||
<data name="Preview_Title" xml:space="preserve"><value>Xem trước</value></data>
|
||||
|
||||
@@ -12,29 +12,29 @@
|
||||
|
||||
<!-- Header -->
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock Text="{Binding Localization[About_Title]}" FontSize="24" FontWeight="SemiBold" />
|
||||
<TextBlock Text="{Binding Localization[About_Tagline]}" Opacity="0.7" FontSize="12" />
|
||||
<TextBlock Text="{Binding Localization[About_Title]}" FontSize="22" FontWeight="SemiBold" />
|
||||
<TextBlock Text="{Binding Localization[About_Tagline]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="12" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- App metadata -->
|
||||
<Border Padding="14"
|
||||
CornerRadius="4"
|
||||
<Border Padding="16"
|
||||
CornerRadius="8"
|
||||
BorderThickness="1"
|
||||
BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}">
|
||||
<Grid ColumnDefinitions="140,*" RowDefinitions="Auto,Auto,Auto,Auto,Auto">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Localization[About_AppLabel]}" Opacity="0.6" Margin="0,0,0,6" />
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Localization[About_AppLabel]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" Margin="0,0,0,6" />
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding AppName}" FontWeight="SemiBold" Margin="0,0,0,6" />
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding Localization[About_VersionLabel]}" Opacity="0.6" Margin="0,0,0,6" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding Localization[About_VersionLabel]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" Margin="0,0,0,6" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding AppVersion}" Margin="0,0,0,6" />
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="{Binding Localization[About_LicenseLabel]}" Opacity="0.6" Margin="0,0,0,6" />
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="{Binding Localization[About_LicenseLabel]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" Margin="0,0,0,6" />
|
||||
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding License}" Margin="0,0,0,6" />
|
||||
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" Text="{Binding Localization[About_DeveloperLabel]}" Opacity="0.6" Margin="0,0,0,6" />
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" Text="{Binding Localization[About_DeveloperLabel]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" Margin="0,0,0,6" />
|
||||
<TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding Developer}" Margin="0,0,0,6" />
|
||||
|
||||
<TextBlock Grid.Row="4" Grid.Column="0" Text="{Binding Localization[About_RepositoryLabel]}" Opacity="0.6" />
|
||||
<TextBlock Grid.Row="4" Grid.Column="0" Text="{Binding Localization[About_RepositoryLabel]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" />
|
||||
<Button Grid.Row="4" Grid.Column="1"
|
||||
Content="{Binding RepositoryUrl}"
|
||||
Command="{Binding OpenRepositoryCommand}"
|
||||
@@ -107,7 +107,7 @@
|
||||
<StackPanel Spacing="6">
|
||||
<TextBlock Text="{Binding Localization[About_ThirdPartySection]}" FontWeight="SemiBold" />
|
||||
<Border BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}"
|
||||
BorderThickness="1" CornerRadius="4" Padding="8">
|
||||
BorderThickness="1" CornerRadius="8" Padding="8">
|
||||
<ItemsControl ItemsSource="{Binding ThirdPartyItems}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="vm:ThirdPartyItem">
|
||||
@@ -119,7 +119,7 @@
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding License}"
|
||||
FontSize="11"
|
||||
Opacity="0.6"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
|
||||
Margin="8,0,0,0" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
@@ -128,7 +128,7 @@
|
||||
</Border>
|
||||
<TextBlock Text="{Binding Localization[About_ThirdPartyHint]}"
|
||||
FontSize="11"
|
||||
Opacity="0.5" />
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" />
|
||||
</StackPanel>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
@@ -17,20 +17,21 @@
|
||||
<!-- Header -->
|
||||
<Grid Grid.Row="0" ColumnDefinitions="*,Auto,Auto,Auto" Margin="0,0,0,12">
|
||||
<StackPanel Grid.Column="0" Orientation="Vertical">
|
||||
<TextBlock Text="Dashboard" FontSize="24" FontWeight="SemiBold" />
|
||||
<TextBlock Text="Select a target and arm — press the hotkey to capture."
|
||||
Opacity="0.6" FontSize="12" Margin="0,2,0,0" />
|
||||
<TextBlock Text="{Binding Localization[Dashboard_Title]}" FontSize="22" FontWeight="SemiBold" />
|
||||
<TextBlock Text="{Binding Localization[Dashboard_Subtitle]}"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
|
||||
FontSize="12" Margin="0,4,0,0" />
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Column="1"
|
||||
Content="Refresh"
|
||||
Content="{Binding Localization[Dashboard_Refresh]}"
|
||||
Command="{Binding RefreshCommand}"
|
||||
IsEnabled="{Binding !IsLoading}"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0" />
|
||||
|
||||
<Button Grid.Column="2"
|
||||
Content="Arm"
|
||||
Content="{Binding Localization[Dashboard_Arm]}"
|
||||
Command="{Binding ArmCommand}"
|
||||
IsVisible="{Binding !IsArmed}"
|
||||
VerticalAlignment="Center"
|
||||
@@ -38,7 +39,7 @@
|
||||
Margin="0,0,8,0" />
|
||||
|
||||
<Button Grid.Column="3"
|
||||
Content="Disarm"
|
||||
Content="{Binding Localization[Dashboard_Disarm]}"
|
||||
Command="{Binding DisarmCommand}"
|
||||
IsVisible="{Binding IsArmed}"
|
||||
VerticalAlignment="Center" />
|
||||
@@ -48,12 +49,14 @@
|
||||
<Border Grid.Row="1"
|
||||
BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="4">
|
||||
<ListBox ItemsSource="{Binding Targets}"
|
||||
SelectedItem="{Binding SelectedTarget, Mode=TwoWay}"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Padding="4">
|
||||
CornerRadius="8">
|
||||
<Grid>
|
||||
<ListBox ItemsSource="{Binding Targets}"
|
||||
SelectedItem="{Binding SelectedTarget, Mode=TwoWay}"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Padding="4"
|
||||
IsVisible="{Binding !HasNoTargets}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="vm:GameTargetViewModel">
|
||||
<Grid ColumnDefinitions="32,*,Auto" Height="40" Margin="4,2">
|
||||
@@ -68,37 +71,50 @@
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
<TextBlock Text="{Binding ProcessName}"
|
||||
FontSize="11"
|
||||
Opacity="0.6"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
</StackPanel>
|
||||
|
||||
<Border Grid.Column="2"
|
||||
IsVisible="{Binding IsSteamGame}"
|
||||
Background="#FF6B35"
|
||||
CornerRadius="10"
|
||||
CornerRadius="4"
|
||||
Padding="8,2"
|
||||
VerticalAlignment="Center"
|
||||
ToolTip.Tip="{Binding SteamBadgeTooltip}">
|
||||
<TextBlock Text="STEAM"
|
||||
FontSize="10"
|
||||
FontSize="11"
|
||||
FontWeight="Bold"
|
||||
Foreground="White" />
|
||||
</Border>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</ListBox>
|
||||
|
||||
<!-- Empty state: no top-level windows detected. -->
|
||||
<TextBlock Text="{Binding EmptyStateText}"
|
||||
IsVisible="{Binding HasNoTargets}"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
TextWrapping="Wrap"
|
||||
TextAlignment="Center"
|
||||
Margin="24" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- Armed / capture state -->
|
||||
<Border Grid.Row="2"
|
||||
Margin="0,12,0,0"
|
||||
Padding="12,8"
|
||||
CornerRadius="4"
|
||||
CornerRadius="8"
|
||||
BorderThickness="1"
|
||||
BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}">
|
||||
BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}"
|
||||
AutomationProperties.Name="{Binding StatusMessage}">
|
||||
<Grid ColumnDefinitions="Auto,*">
|
||||
<Grid Grid.Column="0" Width="10" Height="10" VerticalAlignment="Center" Margin="0,0,12,0">
|
||||
<Grid Grid.Column="0" Width="10" Height="10" VerticalAlignment="Center" Margin="0,0,12,0"
|
||||
AutomationProperties.Name="{Binding StatusMessage}">
|
||||
<!-- Idle dot (gray) -->
|
||||
<Border CornerRadius="5" Background="Gray"
|
||||
IsVisible="{Binding !IsArmed}" />
|
||||
@@ -119,12 +135,12 @@
|
||||
<!-- Status bar -->
|
||||
<Grid Grid.Row="3" ColumnDefinitions="*,Auto" Margin="0,8,0,0">
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="{Binding Targets.Count, StringFormat='{}{0} target(s) visible'}"
|
||||
Opacity="0.6"
|
||||
Text="{Binding TargetsCountText}"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="Loading…"
|
||||
Opacity="0.6"
|
||||
Text="{Binding LoadingText}"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
|
||||
IsVisible="{Binding IsLoading}"
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<Border Background="{DynamicResource SystemControlBackgroundChromeMediumBrush}"
|
||||
BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}"
|
||||
BorderThickness="1,1,0,0"
|
||||
CornerRadius="6,0,0,0"
|
||||
CornerRadius="8,0,0,0"
|
||||
Padding="12">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
|
||||
@@ -24,47 +24,61 @@
|
||||
VerticalAlignment="Center" />
|
||||
<Button Grid.Column="1"
|
||||
Command="{Binding TogglePauseCommand}"
|
||||
Content="{Binding Localization[Log_Pause]}"
|
||||
Content="{Binding TogglePauseLabel}"
|
||||
Margin="0,0,8,0" />
|
||||
<Button Grid.Column="2"
|
||||
Command="{Binding ClearCommand}"
|
||||
Content="{Binding Localization[Log_Clear]}"
|
||||
Margin="0,0,8,0" />
|
||||
<TextBlock Grid.Column="3"
|
||||
Text="{Binding Entries.Count, StringFormat='{}{0} events'}"
|
||||
Opacity="0.6"
|
||||
Text="{Binding EventsCountText}"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
|
||||
<!-- Entries list -->
|
||||
<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
|
||||
<ItemsControl ItemsSource="{Binding Entries}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="models:LogEntry">
|
||||
<Grid ColumnDefinitions="Auto,Auto,*" Margin="0,1">
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="{Binding Timestamp, StringFormat='HH:mm:ss.fff'}"
|
||||
FontFamily="Consolas, Courier New, monospace"
|
||||
FontSize="11"
|
||||
Opacity="0.6"
|
||||
Margin="0,0,8,0" />
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding Level}"
|
||||
FontFamily="Consolas, Courier New, monospace"
|
||||
FontSize="11"
|
||||
Width="45"
|
||||
Margin="0,0,8,0" />
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="{Binding Message}"
|
||||
FontFamily="Consolas, Courier New, monospace"
|
||||
FontSize="11"
|
||||
TextWrapping="NoWrap"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
<Grid Grid.Row="1">
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Auto"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
IsVisible="{Binding !HasNoEntries}">
|
||||
<ItemsControl ItemsSource="{Binding Entries}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="models:LogEntry">
|
||||
<Grid ColumnDefinitions="Auto,Auto,*" Margin="0,1">
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="{Binding Timestamp, StringFormat='HH:mm:ss.fff'}"
|
||||
FontFamily="Consolas, Courier New, monospace"
|
||||
FontSize="11"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
|
||||
Margin="0,0,8,0" />
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding Level}"
|
||||
FontFamily="Consolas, Courier New, monospace"
|
||||
FontSize="11"
|
||||
Width="45"
|
||||
Margin="0,0,8,0" />
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="{Binding Message}"
|
||||
FontFamily="Consolas, Courier New, monospace"
|
||||
FontSize="11"
|
||||
TextWrapping="NoWrap"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
|
||||
<!-- Empty state: no log events yet. -->
|
||||
<TextBlock Text="{Binding EmptyStateText}"
|
||||
IsVisible="{Binding HasNoEntries}"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
TextWrapping="Wrap"
|
||||
TextAlignment="Center"
|
||||
Margin="24" />
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
@@ -47,15 +47,15 @@
|
||||
BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}"
|
||||
BorderThickness="0,0,1,0">
|
||||
<DockPanel LastChildFill="True">
|
||||
<StackPanel DockPanel.Dock="Top" Margin="20,24,20,16">
|
||||
<TextBlock Text="CaptureImage"
|
||||
<StackPanel DockPanel.Dock="Top" Margin="16,24,16,16">
|
||||
<TextBlock Text="{Binding AppTitle}"
|
||||
FontSize="22"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseHighBrush}" />
|
||||
<TextBlock Text="v0.1.0 — M3 UX polish"
|
||||
<TextBlock Text="{Binding AppVersion}"
|
||||
FontSize="11"
|
||||
Margin="0,2,0,0"
|
||||
Opacity="0.6" />
|
||||
Margin="0,4,0,0"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Log viewer toggle at the bottom of the nav rail -->
|
||||
@@ -63,9 +63,11 @@
|
||||
Command="{Binding ToggleLogViewerCommand}"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Left"
|
||||
Margin="12,4,12,16"
|
||||
Padding="12,8">
|
||||
<StackPanel Orientation="Horizontal" Spacing="10">
|
||||
Margin="8,4,8,16"
|
||||
Padding="12,8"
|
||||
AutomationProperties.Name="{Binding Localization[Dashboard_LogToggle]}"
|
||||
ToolTip.Tip="{Binding Localization[Dashboard_LogToggle]}">
|
||||
<StackPanel Orientation="Horizontal" Spacing="12">
|
||||
<TextBlock Text=""
|
||||
FontFamily="Segoe Fluent Icons, Segoe MDL2 Assets"
|
||||
FontSize="16"
|
||||
@@ -86,7 +88,7 @@
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="{Binding IconGlyph}"
|
||||
FontFamily="Segoe Fluent Icons, Segoe MDL2 Assets"
|
||||
FontSize="18"
|
||||
FontSize="16"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center" />
|
||||
<TextBlock Grid.Column="1"
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
<!-- Header -->
|
||||
<StackPanel Grid.Row="0" Margin="0,0,0,12">
|
||||
<TextBlock Text="{Binding Localization[Preview_Title]}" FontSize="20" FontWeight="SemiBold" />
|
||||
<TextBlock Margin="0,4,0,0" Opacity="0.7">
|
||||
<TextBlock Text="{Binding Localization[Preview_Title]}" FontSize="22" FontWeight="SemiBold" />
|
||||
<TextBlock Margin="0,4,0,0" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}">
|
||||
<Run Text="{Binding TargetName}" />
|
||||
<Run Text="— " />
|
||||
<Run Text="{Binding Width}" />
|
||||
@@ -30,7 +30,7 @@
|
||||
<Border Grid.Row="1"
|
||||
BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="4"
|
||||
CornerRadius="8"
|
||||
Background="#111">
|
||||
<Image Source="{Binding PngBytes, Converter={x:Static conv:BytesToBitmapConverter.Instance}}"
|
||||
Stretch="Uniform"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="clr-namespace:CaptureImage.ViewModels.Settings;assembly=CaptureImage.ViewModels"
|
||||
xmlns:ctrl="clr-namespace:CaptureImage.UI.Controls"
|
||||
xmlns:sys="clr-namespace:System.Globalization;assembly=System.Runtime"
|
||||
xmlns:models="clr-namespace:CaptureImage.Core.Models;assembly=CaptureImage.Core"
|
||||
mc:Ignorable="d"
|
||||
@@ -12,11 +13,11 @@
|
||||
<ScrollViewer>
|
||||
<StackPanel Margin="24,16" Spacing="18" MaxWidth="620">
|
||||
|
||||
<TextBlock Text="{Binding Localization[Settings_Title]}" FontSize="24" FontWeight="SemiBold" />
|
||||
<TextBlock Text="{Binding Localization[Settings_Title]}" FontSize="22" FontWeight="SemiBold" />
|
||||
|
||||
<!-- Language -->
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock Text="{Binding Localization[Settings_Language]}" Opacity="0.7" FontSize="12" />
|
||||
<TextBlock Text="{Binding Localization[Settings_Language]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="12" />
|
||||
<ComboBox ItemsSource="{Binding SupportedCultures}"
|
||||
SelectedItem="{Binding SelectedCulture, Mode=TwoWay}"
|
||||
HorizontalAlignment="Stretch">
|
||||
@@ -30,14 +31,14 @@
|
||||
|
||||
<!-- Hotkey -->
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock Text="{Binding Localization[Settings_Hotkey]}" Opacity="0.7" FontSize="12" />
|
||||
<TextBlock Text="Ctrl+Shift+F12" FontFamily="Consolas, Courier New, monospace" />
|
||||
<TextBlock Text="{Binding Localization[Settings_HotkeyHint]}" FontSize="11" Opacity="0.5" />
|
||||
<TextBlock Text="{Binding Localization[Settings_Hotkey]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="12" />
|
||||
<ctrl:HotkeyRecorder DataContext="{Binding Hotkey}" />
|
||||
<TextBlock Text="{Binding Localization[Settings_HotkeyHint]}" FontSize="11" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Default format -->
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock Text="{Binding Localization[Settings_Format]}" Opacity="0.7" FontSize="12" />
|
||||
<TextBlock Text="{Binding Localization[Settings_Format]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="12" />
|
||||
<ComboBox ItemsSource="{Binding SupportedFormats}"
|
||||
SelectedItem="{Binding DefaultFormat, Mode=TwoWay}"
|
||||
HorizontalAlignment="Stretch" />
|
||||
@@ -46,27 +47,27 @@
|
||||
<!-- Quality sliders -->
|
||||
<Grid ColumnDefinitions="*,16,*">
|
||||
<StackPanel Grid.Column="0" Spacing="4">
|
||||
<TextBlock Text="{Binding Localization[Settings_JpegQuality]}" Opacity="0.7" FontSize="12" />
|
||||
<TextBlock Text="{Binding Localization[Settings_JpegQuality]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="12" />
|
||||
<Slider Minimum="1" Maximum="100" Value="{Binding JpegQuality, Mode=TwoWay}" TickFrequency="10" />
|
||||
<TextBlock Text="{Binding JpegQuality}" FontSize="11" Opacity="0.6" HorizontalAlignment="Right" />
|
||||
<TextBlock Text="{Binding JpegQuality}" FontSize="11" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" HorizontalAlignment="Right" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="2" Spacing="4">
|
||||
<TextBlock Text="{Binding Localization[Settings_WebpQuality]}" Opacity="0.7" FontSize="12" />
|
||||
<TextBlock Text="{Binding Localization[Settings_WebpQuality]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="12" />
|
||||
<Slider Minimum="1" Maximum="100" Value="{Binding WebpQuality, Mode=TwoWay}" TickFrequency="10" />
|
||||
<TextBlock Text="{Binding WebpQuality}" FontSize="11" Opacity="0.6" HorizontalAlignment="Right" />
|
||||
<TextBlock Text="{Binding WebpQuality}" FontSize="11" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" HorizontalAlignment="Right" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Output folder -->
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock Text="{Binding Localization[Settings_OutputFolder]}" Opacity="0.7" FontSize="12" />
|
||||
<TextBlock Text="{Binding Localization[Settings_OutputFolder]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="12" />
|
||||
<TextBox Text="{Binding OutputDirectory, Mode=TwoWay}"
|
||||
Watermark="{Binding Localization[Settings_OutputFolderDefault]}" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- File name template -->
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock Text="{Binding Localization[Settings_FileNameTemplate]}" Opacity="0.7" FontSize="12" />
|
||||
<TextBlock Text="{Binding Localization[Settings_FileNameTemplate]}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="12" />
|
||||
<TextBox Text="{Binding FileNameTemplate, Mode=TwoWay}"
|
||||
FontFamily="Consolas, Courier New, monospace" />
|
||||
</StackPanel>
|
||||
@@ -89,7 +90,7 @@
|
||||
Command="{Binding OpenSettingsFileCommand}" />
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Text="{Binding SettingsFilePath}" Opacity="0.4" FontSize="11" TextWrapping="Wrap" />
|
||||
<TextBlock Text="{Binding SettingsFilePath}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="11" TextWrapping="Wrap" />
|
||||
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
<!-- Header -->
|
||||
<StackPanel Grid.Row="0" Spacing="4" Margin="0,0,0,16">
|
||||
<TextBlock Text="{Binding Localization[Update_Title]}" FontSize="24" FontWeight="SemiBold" />
|
||||
<TextBlock Opacity="0.7">
|
||||
<TextBlock Text="{Binding Localization[Update_Title]}" FontSize="22" FontWeight="SemiBold" />
|
||||
<TextBlock Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}">
|
||||
<Run Text="{Binding Localization[About_VersionLabel]}" />
|
||||
<Run Text=": " />
|
||||
<Run Text="{Binding CurrentVersion}" />
|
||||
@@ -23,7 +23,7 @@
|
||||
<Border Grid.Row="1"
|
||||
IsVisible="{Binding AvailableVersion, Converter={x:Static ObjectConverters.IsNotNull}}"
|
||||
Padding="12"
|
||||
CornerRadius="4"
|
||||
CornerRadius="8"
|
||||
BorderThickness="1"
|
||||
BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}"
|
||||
Background="{DynamicResource SystemControlBackgroundChromeMediumLowBrush}"
|
||||
@@ -64,7 +64,7 @@
|
||||
<ProgressBar Value="{Binding DownloadProgress}"
|
||||
Minimum="0" Maximum="100"
|
||||
IsVisible="{Binding IsBusy}" />
|
||||
<TextBlock Opacity="0.7" FontSize="12">
|
||||
<TextBlock Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="12">
|
||||
<Run Text="{Binding Localization[Update_Status]}" />
|
||||
<Run Text=": " />
|
||||
<Run Text="{Binding Status}" />
|
||||
@@ -75,7 +75,7 @@
|
||||
<Border Grid.Row="4"
|
||||
BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="4"
|
||||
CornerRadius="8"
|
||||
Padding="10">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<TextBlock Grid.Row="0"
|
||||
|
||||
@@ -58,6 +58,18 @@ public sealed partial class DashboardViewModel : ViewModelBase, IDisposable
|
||||
|
||||
public ObservableCollection<GameTargetViewModel> Targets { get; } = new();
|
||||
|
||||
/// <summary>Localized "{0} target(s) visible" line at the bottom of the dashboard.</summary>
|
||||
public string TargetsCountText =>
|
||||
string.Format(Localization["Dashboard_TargetsCount"], Targets.Count);
|
||||
|
||||
/// <summary>Localized "Loading…" hint shown while the process enumerator is running.</summary>
|
||||
public string LoadingText => Localization["Dashboard_Loading"];
|
||||
|
||||
/// <summary>Localized hint shown when the target list is empty (no visible windows).</summary>
|
||||
public string EmptyStateText => Localization["Dashboard_EmptyState"];
|
||||
|
||||
public bool HasNoTargets => Targets.Count == 0 && !IsLoading;
|
||||
|
||||
public bool IsArmed => CurrentState is CaptureState.Armed or CaptureState.Capturing
|
||||
or CaptureState.Previewing or CaptureState.Saving
|
||||
or CaptureState.Complete or CaptureState.Failed;
|
||||
@@ -105,13 +117,29 @@ public sealed partial class DashboardViewModel : ViewModelBase, IDisposable
|
||||
if (e.PropertyName is "Item[]" or nameof(ILocalizationService.CurrentCulture))
|
||||
{
|
||||
OnPropertyChanged(nameof(StatusMessage));
|
||||
OnPropertyChanged(nameof(TargetsCountText));
|
||||
OnPropertyChanged(nameof(LoadingText));
|
||||
OnPropertyChanged(nameof(EmptyStateText));
|
||||
}
|
||||
};
|
||||
|
||||
// TargetsCountText depends on Targets.Count — refresh whenever the collection changes.
|
||||
Targets.CollectionChanged += (_, _) =>
|
||||
{
|
||||
OnPropertyChanged(nameof(TargetsCountText));
|
||||
OnPropertyChanged(nameof(HasNoTargets));
|
||||
};
|
||||
|
||||
// Fire the first refresh without blocking the constructor.
|
||||
_ = RefreshAsync();
|
||||
}
|
||||
|
||||
// HasNoTargets depends on IsLoading — refresh when the loading flag flips.
|
||||
partial void OnIsLoadingChanged(bool value)
|
||||
{
|
||||
OnPropertyChanged(nameof(HasNoTargets));
|
||||
}
|
||||
|
||||
// -- nav / refresh -------------------------------------------------------
|
||||
|
||||
[RelayCommand]
|
||||
@@ -138,10 +166,14 @@ public sealed partial class DashboardViewModel : ViewModelBase, IDisposable
|
||||
{
|
||||
var previousPid = SelectedTarget?.ProcessId;
|
||||
|
||||
foreach (var stale in Targets)
|
||||
{
|
||||
stale.Dispose();
|
||||
}
|
||||
Targets.Clear();
|
||||
foreach (var target in newTargets)
|
||||
{
|
||||
Targets.Add(new GameTargetViewModel(target));
|
||||
Targets.Add(new GameTargetViewModel(target, Localization));
|
||||
}
|
||||
|
||||
if (previousPid is { } pid)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using CaptureImage.Core.Abstractions;
|
||||
using CaptureImage.Core.Models;
|
||||
|
||||
namespace CaptureImage.ViewModels.Dashboard;
|
||||
@@ -7,11 +10,22 @@ namespace CaptureImage.ViewModels.Dashboard;
|
||||
/// 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>
|
||||
public sealed class GameTargetViewModel : ViewModelBase
|
||||
/// <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
|
||||
{
|
||||
public GameTargetViewModel(GameTarget target)
|
||||
private readonly ILocalizationService _localization;
|
||||
private bool _disposed;
|
||||
|
||||
public GameTargetViewModel(GameTarget target, ILocalizationService localization)
|
||||
{
|
||||
Target = target;
|
||||
_localization = localization;
|
||||
_localization.PropertyChanged += OnLocalizationPropertyChanged;
|
||||
}
|
||||
|
||||
public GameTarget Target { get; }
|
||||
@@ -30,9 +44,36 @@ public sealed class GameTargetViewModel : ViewModelBase
|
||||
|
||||
public string? SteamAppName => Target.SteamInfo?.Name;
|
||||
|
||||
public string SteamBadgeTooltip =>
|
||||
Target.SteamInfo is null
|
||||
? string.Empty
|
||||
: $"Steam game: {Target.SteamInfo.Name} (AppId {Target.SteamInfo.AppId}). " +
|
||||
"F12 screenshot khả dụng qua Steam Overlay. Một số game có anti-cheat có thể chặn capture ngoài.";
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,44 @@ public sealed partial class LogViewerViewModel : ViewModelBase
|
||||
Localization = localization;
|
||||
|
||||
_source.Emitted += OnEmitted;
|
||||
|
||||
Localization.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName is "Item[]" or nameof(ILocalizationService.CurrentCulture))
|
||||
{
|
||||
OnPropertyChanged(nameof(TogglePauseLabel));
|
||||
OnPropertyChanged(nameof(EventsCountText));
|
||||
OnPropertyChanged(nameof(EmptyStateText));
|
||||
}
|
||||
};
|
||||
|
||||
Entries.CollectionChanged += (_, _) =>
|
||||
{
|
||||
OnPropertyChanged(nameof(EventsCountText));
|
||||
OnPropertyChanged(nameof(HasNoEntries));
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Label shown on the Pause/Resume button. Flips on <see cref="IsPaused"/> so one
|
||||
/// button drives both states, and re-localizes on culture change.
|
||||
/// </summary>
|
||||
public string TogglePauseLabel =>
|
||||
IsPaused ? Localization["Log_Resume"] : Localization["Log_Pause"];
|
||||
|
||||
/// <summary>Localized "{0} events" line at the right edge of the log header.</summary>
|
||||
public string EventsCountText =>
|
||||
string.Format(Localization["Log_EventsCount"], Entries.Count);
|
||||
|
||||
/// <summary>Localized hint shown inside the drawer when no log events have fired yet.</summary>
|
||||
public string EmptyStateText => Localization["Log_EmptyState"];
|
||||
|
||||
public bool HasNoEntries => Entries.Count == 0;
|
||||
|
||||
partial void OnIsPausedChanged(bool value)
|
||||
{
|
||||
_source.Paused = value;
|
||||
OnPropertyChanged(nameof(TogglePauseLabel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -62,11 +100,6 @@ public sealed partial class LogViewerViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnIsPausedChanged(bool value)
|
||||
{
|
||||
_source.Paused = value;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Clear()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reflection;
|
||||
using CaptureImage.Core.Abstractions;
|
||||
using CaptureImage.Core.Models;
|
||||
using CaptureImage.ViewModels.About;
|
||||
@@ -39,6 +40,32 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
||||
|
||||
public ObservableCollection<NavItemViewModel> NavItems { get; }
|
||||
|
||||
/// <summary>Brand name shown in the nav rail header. Constant across cultures — brand names do not translate.</summary>
|
||||
public string AppTitle => "CaptureImage";
|
||||
|
||||
/// <summary>
|
||||
/// Short semver pulled from the entry assembly's <c>Version</c> at runtime. Release builds
|
||||
/// set this via <c>/p:Version=<git-tag></c> in release.yml; dev builds fall back to the
|
||||
/// <c><Version></c> element in CaptureImage.App.csproj. Zero-valued versions (a bare
|
||||
/// <c>dotnet build</c> with no version props) render as "dev".
|
||||
/// </summary>
|
||||
public string AppVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
var info = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
|
||||
if (!string.IsNullOrWhiteSpace(info))
|
||||
{
|
||||
// Strip the +commit-sha suffix if present.
|
||||
var plus = info.IndexOf('+');
|
||||
return "v" + (plus >= 0 ? info[..plus] : info);
|
||||
}
|
||||
var v = Assembly.GetEntryAssembly()?.GetName().Version;
|
||||
if (v is null || v.Major == 0 && v.Minor == 0 && v.Build == 0) return "dev";
|
||||
return $"v{v.Major}.{v.Minor}.{v.Build}";
|
||||
}
|
||||
}
|
||||
|
||||
public MainWindowViewModel(
|
||||
INavigationService navigation,
|
||||
ILocalizationService localization,
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using CaptureImage.Core.Abstractions;
|
||||
using CaptureImage.Core.Models;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CaptureImage.ViewModels.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Bridge between the <c>HotkeyRecorder</c> control and persistence. Owns the
|
||||
/// <i>recording-mode</i> flag, the last validation outcome, and the
|
||||
/// <i>conflict-detected</i> warning; handles the commit flow:
|
||||
/// validate → sniff-for-conflict → persist → live-rebind the hotkey service
|
||||
/// (so an armed capture picks up the new combo without disarm/re-arm).
|
||||
/// </summary>
|
||||
public sealed partial class HotkeyBindingViewModel : ViewModelBase, IDisposable
|
||||
{
|
||||
private readonly ISettingsStore _settings;
|
||||
private readonly IHotkeyService _hotkeys;
|
||||
private readonly IHotkeyConflictSniffer _sniffer;
|
||||
private readonly ILogger<HotkeyBindingViewModel> _logger;
|
||||
private bool _disposed;
|
||||
|
||||
/// <summary>Exposed so the <c>HotkeyRecorder</c> control can resolve localized strings.</summary>
|
||||
public ILocalizationService Localization { get; }
|
||||
|
||||
[ObservableProperty]
|
||||
private HotkeyBinding _currentBinding;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isRecording;
|
||||
|
||||
[ObservableProperty]
|
||||
private HotkeyValidationResult _lastValidationResult = HotkeyValidationResult.Ok;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _conflictDetected;
|
||||
|
||||
/// <summary>Human-readable current binding (e.g. <c>"Ctrl+Shift+F12"</c>).</summary>
|
||||
public string DisplayText => CurrentBinding.ToString();
|
||||
|
||||
/// <summary><c>true</c> when <see cref="LastValidationResult"/> is non-Ok — drives UI error styling.</summary>
|
||||
public bool HasError => LastValidationResult != HotkeyValidationResult.Ok;
|
||||
|
||||
/// <summary>Localized error string for <see cref="LastValidationResult"/>, or empty when Ok.</summary>
|
||||
public string ErrorMessage => LastValidationResult switch
|
||||
{
|
||||
HotkeyValidationResult.NoPrimaryKey => Localization["Settings_HotkeyErrorNoPrimary"],
|
||||
HotkeyValidationResult.ModifierOnlyKey => Localization["Settings_HotkeyErrorModifierOnly"],
|
||||
HotkeyValidationResult.RequiresModifier => Localization["Settings_HotkeyErrorNeedsModifier"],
|
||||
HotkeyValidationResult.ReservedByWindows => Localization["Settings_HotkeyErrorReserved"],
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
public HotkeyBindingViewModel(
|
||||
ISettingsStore settings,
|
||||
IHotkeyService hotkeys,
|
||||
IHotkeyConflictSniffer sniffer,
|
||||
ILocalizationService localization,
|
||||
ILogger<HotkeyBindingViewModel> logger)
|
||||
{
|
||||
_settings = settings;
|
||||
_hotkeys = hotkeys;
|
||||
_sniffer = sniffer;
|
||||
_logger = logger;
|
||||
Localization = localization;
|
||||
|
||||
_currentBinding = settings.Current.CaptureHotkey;
|
||||
_settings.Changed += OnSettingsChanged;
|
||||
|
||||
// Localized ErrorMessage + ConflictWarning come from the indexer — push a fresh
|
||||
// PropertyChanged on culture switch so bound TextBlocks re-resolve strings in place.
|
||||
Localization.PropertyChanged += OnLocalizationChanged;
|
||||
}
|
||||
|
||||
private void OnLocalizationChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (_disposed) return;
|
||||
if (e.PropertyName is "Item[]" or nameof(ILocalizationService.CurrentCulture))
|
||||
{
|
||||
OnPropertyChanged(nameof(ErrorMessage));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSettingsChanged(object? sender, EventArgs e)
|
||||
{
|
||||
if (_disposed) return;
|
||||
var binding = _settings.Current.CaptureHotkey;
|
||||
if (binding != CurrentBinding)
|
||||
{
|
||||
CurrentBinding = binding;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void StartRecording()
|
||||
{
|
||||
_logger.LogDebug("HotkeyRecorder StartRecording invoked.");
|
||||
IsRecording = true;
|
||||
LastValidationResult = HotkeyValidationResult.Ok;
|
||||
ConflictDetected = false;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void CancelRecording()
|
||||
{
|
||||
_logger.LogDebug("HotkeyRecorder CancelRecording invoked (was recording={WasRecording}).", IsRecording);
|
||||
IsRecording = false;
|
||||
LastValidationResult = HotkeyValidationResult.Ok;
|
||||
ConflictDetected = false;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ResetToDefault()
|
||||
{
|
||||
_logger.LogDebug("HotkeyRecorder ResetToDefault invoked.");
|
||||
ApplyBinding(HotkeyBinding.Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Offered by the recorder control when the user presses a complete combination.
|
||||
/// Rejects silently when not in recording mode so stray key events outside the
|
||||
/// recorder do not leak into settings.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Flow: <see cref="HotkeyBinding.Validate"/> first. Invalid → keep recording
|
||||
/// so the user sees the error and can try again. Valid → sniff for cross-process
|
||||
/// conflicts (non-blocking; user keeps the combo), persist, and live-rebind.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public void TryCommitRecorded(HotkeyBinding candidate)
|
||||
{
|
||||
if (!IsRecording) return;
|
||||
|
||||
var validation = candidate.Validate();
|
||||
LastValidationResult = validation;
|
||||
|
||||
if (validation != HotkeyValidationResult.Ok)
|
||||
{
|
||||
_logger.LogDebug(
|
||||
"Rejecting recorded hotkey {Binding}: {Reason}.", candidate, validation);
|
||||
return;
|
||||
}
|
||||
|
||||
ConflictDetected = _sniffer.IsConflicted(candidate);
|
||||
if (ConflictDetected)
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"Recorded hotkey {Binding} is already claimed by another process; saving anyway.",
|
||||
candidate);
|
||||
}
|
||||
|
||||
ApplyBinding(candidate);
|
||||
}
|
||||
|
||||
private void ApplyBinding(HotkeyBinding binding)
|
||||
{
|
||||
_settings.Update(s => s with { CaptureHotkey = binding });
|
||||
CurrentBinding = binding;
|
||||
IsRecording = false;
|
||||
LastValidationResult = HotkeyValidationResult.Ok;
|
||||
|
||||
// Live rebind so a currently-armed capture picks the new combo up immediately.
|
||||
// When the service is stopped (disarmed), the next Arm will SetBinding from settings.
|
||||
if (_hotkeys.CurrentBinding is not null)
|
||||
{
|
||||
_hotkeys.SetBinding(binding);
|
||||
_logger.LogInformation("Live-rebound capture hotkey to {Binding}.", binding);
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnCurrentBindingChanged(HotkeyBinding value)
|
||||
{
|
||||
OnPropertyChanged(nameof(DisplayText));
|
||||
}
|
||||
|
||||
partial void OnLastValidationResultChanged(HotkeyValidationResult value)
|
||||
{
|
||||
OnPropertyChanged(nameof(HasError));
|
||||
OnPropertyChanged(nameof(ErrorMessage));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed) return;
|
||||
_disposed = true;
|
||||
_settings.Changed -= OnSettingsChanged;
|
||||
Localization.PropertyChanged -= OnLocalizationChanged;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,9 @@ public sealed partial class SettingsViewModel : ViewModelBase
|
||||
|
||||
public ILocalizationService Localization { get; }
|
||||
|
||||
/// <summary>Child VM driving the Settings → Capture hotkey recorder.</summary>
|
||||
public HotkeyBindingViewModel Hotkey { get; }
|
||||
|
||||
public ObservableCollection<CultureInfo> SupportedCultures { get; }
|
||||
|
||||
public ObservableCollection<ImageFormat> SupportedFormats { get; } =
|
||||
@@ -63,12 +66,14 @@ public sealed partial class SettingsViewModel : ViewModelBase
|
||||
ISettingsStore settings,
|
||||
ILocalizationService localization,
|
||||
IToastService toasts,
|
||||
HotkeyBindingViewModel hotkey,
|
||||
ILogger<SettingsViewModel> logger)
|
||||
{
|
||||
_settings = settings;
|
||||
_toasts = toasts;
|
||||
_logger = logger;
|
||||
Localization = localization;
|
||||
Hotkey = hotkey;
|
||||
|
||||
SupportedCultures = new ObservableCollection<CultureInfo>(localization.SupportedCultures);
|
||||
_selectedCulture = FindCulture(settings.Current.Culture) ?? SupportedCultures[0];
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
using CaptureImage.Core.Models;
|
||||
using CaptureImage.Core.Validation;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace CaptureImage.Core.Tests.Models;
|
||||
|
||||
public class HotkeyBindingValidationTests
|
||||
{
|
||||
// -- acceptance cases -----------------------------------------------------
|
||||
|
||||
[Fact]
|
||||
public void Default_IsValid()
|
||||
{
|
||||
HotkeyBinding.Default.Validate().Should().Be(HotkeyValidationResult.Ok);
|
||||
HotkeyBinding.Default.IsValid().Should().BeTrue();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(HotkeyModifiers.Control | HotkeyModifiers.Shift, 0x7B)] // Ctrl+Shift+F12
|
||||
[InlineData(HotkeyModifiers.Control | HotkeyModifiers.Alt, 0x78)] // Ctrl+Alt+F9
|
||||
[InlineData(HotkeyModifiers.Shift, 0x41)] // Shift+A
|
||||
[InlineData(HotkeyModifiers.Win, 0x74)] // Win+F5
|
||||
public void Validate_ValidModifierCombos_ReturnsOk(HotkeyModifiers mods, uint vk)
|
||||
{
|
||||
new HotkeyBinding(mods, vk).Validate()
|
||||
.Should().Be(HotkeyValidationResult.Ok);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0x70)] // F1
|
||||
[InlineData(0x7B)] // F12
|
||||
[InlineData(0x87)] // F24
|
||||
[InlineData(0x2C)] // PrintScreen
|
||||
public void Validate_FunctionKey_AllowedWithoutModifier(uint vk)
|
||||
{
|
||||
new HotkeyBinding(HotkeyModifiers.None, vk).Validate()
|
||||
.Should().Be(HotkeyValidationResult.Ok);
|
||||
}
|
||||
|
||||
// -- rejection cases ------------------------------------------------------
|
||||
|
||||
[Fact]
|
||||
public void Validate_NoPrimaryKey()
|
||||
{
|
||||
new HotkeyBinding(HotkeyModifiers.Control, 0).Validate()
|
||||
.Should().Be(HotkeyValidationResult.NoPrimaryKey);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0x10)] // VK_SHIFT
|
||||
[InlineData(0x11)] // VK_CONTROL
|
||||
[InlineData(0x12)] // VK_MENU (Alt)
|
||||
[InlineData(0x5B)] // VK_LWIN
|
||||
[InlineData(0x5C)] // VK_RWIN
|
||||
[InlineData(0xA0)] // VK_LSHIFT
|
||||
[InlineData(0xA2)] // VK_LCONTROL
|
||||
[InlineData(0xA4)] // VK_LMENU
|
||||
public void Validate_ModifierAsPrimaryKey_IsRejected(uint vk)
|
||||
{
|
||||
// Even with modifiers pressed, a modifier VK as the "primary" is invalid —
|
||||
// the caller should have waited for a real key.
|
||||
new HotkeyBinding(HotkeyModifiers.Control, vk).Validate()
|
||||
.Should().Be(HotkeyValidationResult.ModifierOnlyKey);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0x41)] // 'A'
|
||||
[InlineData(0x30)] // '0'
|
||||
[InlineData(0x20)] // Space
|
||||
public void Validate_PlainKeyWithoutModifier_RequiresModifier(uint vk)
|
||||
{
|
||||
new HotkeyBinding(HotkeyModifiers.None, vk).Validate()
|
||||
.Should().Be(HotkeyValidationResult.RequiresModifier);
|
||||
}
|
||||
|
||||
// -- Windows-reserved combos ---------------------------------------------
|
||||
|
||||
[Theory]
|
||||
[InlineData(HotkeyModifiers.Win, 0x4C)] // Win+L
|
||||
[InlineData(HotkeyModifiers.Win, 0x44)] // Win+D
|
||||
[InlineData(HotkeyModifiers.Alt, 0x09)] // Alt+Tab
|
||||
[InlineData(HotkeyModifiers.Alt, 0x73)] // Alt+F4
|
||||
[InlineData(HotkeyModifiers.Control | HotkeyModifiers.Shift, 0x1B)] // Ctrl+Shift+Esc
|
||||
public void Validate_ReservedByWindows_IsFlagged(HotkeyModifiers mods, uint vk)
|
||||
{
|
||||
new HotkeyBinding(mods, vk).Validate()
|
||||
.Should().Be(HotkeyValidationResult.ReservedByWindows);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReservedHotkeys_All_IncludesCoreShellCombos()
|
||||
{
|
||||
ReservedHotkeys.All.Should().NotBeEmpty();
|
||||
ReservedHotkeys.IsReserved(new HotkeyBinding(HotkeyModifiers.Win, 0x4C)).Should().BeTrue();
|
||||
ReservedHotkeys.IsReserved(new HotkeyBinding(HotkeyModifiers.Alt, 0x09)).Should().BeTrue();
|
||||
// Something conspicuously NOT on the reserved list:
|
||||
ReservedHotkeys.IsReserved(HotkeyBinding.Default).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CaptureImage.Core.Abstractions;
|
||||
using CaptureImage.Core.Models;
|
||||
using CaptureImage.ViewModels.Settings;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace CaptureImage.ViewModels.Tests.Settings;
|
||||
|
||||
public class HotkeyBindingViewModelTests
|
||||
{
|
||||
private static HotkeyBindingViewModel NewVm(
|
||||
FakeSettingsStore store,
|
||||
IHotkeyService? hotkeys = null,
|
||||
IHotkeyConflictSniffer? sniffer = null) =>
|
||||
new(
|
||||
store,
|
||||
hotkeys ?? Substitute.For<IHotkeyService>(),
|
||||
sniffer ?? Substitute.For<IHotkeyConflictSniffer>(),
|
||||
new NullLocalizationService(),
|
||||
NullLogger<HotkeyBindingViewModel>.Instance);
|
||||
|
||||
[Fact]
|
||||
public void Constructor_SeedsCurrentBinding_FromSettings()
|
||||
{
|
||||
var store = new FakeSettingsStore
|
||||
{
|
||||
Current = new AppSettings { CaptureHotkey = new HotkeyBinding(HotkeyModifiers.Control, 0x7B) },
|
||||
};
|
||||
|
||||
var vm = NewVm(store);
|
||||
|
||||
vm.CurrentBinding.Should().Be(store.Current.CaptureHotkey);
|
||||
vm.IsRecording.Should().BeFalse();
|
||||
vm.LastValidationResult.Should().Be(HotkeyValidationResult.Ok);
|
||||
vm.ConflictDetected.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartRecording_Flips_IsRecording()
|
||||
{
|
||||
var vm = NewVm(new FakeSettingsStore());
|
||||
|
||||
vm.StartRecordingCommand.Execute(null);
|
||||
|
||||
vm.IsRecording.Should().BeTrue();
|
||||
vm.LastValidationResult.Should().Be(HotkeyValidationResult.Ok);
|
||||
vm.ConflictDetected.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CancelRecording_ClearsState()
|
||||
{
|
||||
var vm = NewVm(new FakeSettingsStore());
|
||||
vm.StartRecordingCommand.Execute(null);
|
||||
vm.IsRecording.Should().BeTrue();
|
||||
|
||||
vm.CancelRecordingCommand.Execute(null);
|
||||
|
||||
vm.IsRecording.Should().BeFalse();
|
||||
vm.LastValidationResult.Should().Be(HotkeyValidationResult.Ok);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryCommitRecorded_NotRecording_IsIgnored()
|
||||
{
|
||||
var store = new FakeSettingsStore();
|
||||
var original = store.Current.CaptureHotkey;
|
||||
var vm = NewVm(store);
|
||||
|
||||
vm.TryCommitRecorded(new HotkeyBinding(HotkeyModifiers.Control | HotkeyModifiers.Alt, 0x78));
|
||||
|
||||
store.UpdateCallCount.Should().Be(0);
|
||||
vm.CurrentBinding.Should().Be(original);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryCommitRecorded_ValidNoConflict_PersistsAndClearsRecording()
|
||||
{
|
||||
var store = new FakeSettingsStore();
|
||||
var sniffer = Substitute.For<IHotkeyConflictSniffer>();
|
||||
sniffer.IsConflicted(Arg.Any<HotkeyBinding>()).Returns(false);
|
||||
var vm = NewVm(store, sniffer: sniffer);
|
||||
vm.StartRecordingCommand.Execute(null);
|
||||
|
||||
var candidate = new HotkeyBinding(HotkeyModifiers.Control | HotkeyModifiers.Alt, 0x78);
|
||||
vm.TryCommitRecorded(candidate);
|
||||
|
||||
store.Current.CaptureHotkey.Should().Be(candidate);
|
||||
vm.CurrentBinding.Should().Be(candidate);
|
||||
vm.IsRecording.Should().BeFalse();
|
||||
vm.LastValidationResult.Should().Be(HotkeyValidationResult.Ok);
|
||||
vm.ConflictDetected.Should().BeFalse();
|
||||
sniffer.Received(1).IsConflicted(candidate);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryCommitRecorded_Conflict_SavesButFlagsWarning()
|
||||
{
|
||||
var store = new FakeSettingsStore();
|
||||
var sniffer = Substitute.For<IHotkeyConflictSniffer>();
|
||||
sniffer.IsConflicted(Arg.Any<HotkeyBinding>()).Returns(true);
|
||||
var vm = NewVm(store, sniffer: sniffer);
|
||||
vm.StartRecordingCommand.Execute(null);
|
||||
|
||||
var candidate = new HotkeyBinding(HotkeyModifiers.Control | HotkeyModifiers.Alt, 0x78);
|
||||
vm.TryCommitRecorded(candidate);
|
||||
|
||||
vm.ConflictDetected.Should().BeTrue();
|
||||
vm.CurrentBinding.Should().Be(candidate);
|
||||
store.Current.CaptureHotkey.Should().Be(candidate);
|
||||
vm.IsRecording.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryCommitRecorded_Reserved_KeepsRecordingAndExposesError()
|
||||
{
|
||||
var store = new FakeSettingsStore();
|
||||
var original = store.Current.CaptureHotkey;
|
||||
var vm = NewVm(store);
|
||||
vm.StartRecordingCommand.Execute(null);
|
||||
|
||||
// Win+L — reserved by the Windows shell
|
||||
vm.TryCommitRecorded(new HotkeyBinding(HotkeyModifiers.Win, 0x4C));
|
||||
|
||||
vm.IsRecording.Should().BeTrue();
|
||||
vm.LastValidationResult.Should().Be(HotkeyValidationResult.ReservedByWindows);
|
||||
vm.HasError.Should().BeTrue();
|
||||
store.UpdateCallCount.Should().Be(0);
|
||||
store.Current.CaptureHotkey.Should().Be(original);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryCommitRecorded_ModifierOnly_KeepsRecording()
|
||||
{
|
||||
var store = new FakeSettingsStore();
|
||||
var vm = NewVm(store);
|
||||
vm.StartRecordingCommand.Execute(null);
|
||||
|
||||
// VK_CONTROL as the "primary" — not a real combo
|
||||
vm.TryCommitRecorded(new HotkeyBinding(HotkeyModifiers.Control, 0x11));
|
||||
|
||||
vm.IsRecording.Should().BeTrue();
|
||||
vm.LastValidationResult.Should().Be(HotkeyValidationResult.ModifierOnlyKey);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetToDefault_PersistsDefaultBinding()
|
||||
{
|
||||
var store = new FakeSettingsStore
|
||||
{
|
||||
Current = new AppSettings { CaptureHotkey = new HotkeyBinding(HotkeyModifiers.Alt, 0x77) },
|
||||
};
|
||||
var vm = NewVm(store);
|
||||
|
||||
vm.ResetToDefaultCommand.Execute(null);
|
||||
|
||||
store.Current.CaptureHotkey.Should().Be(HotkeyBinding.Default);
|
||||
vm.CurrentBinding.Should().Be(HotkeyBinding.Default);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExternalSettingsChange_UpdatesCurrentBinding()
|
||||
{
|
||||
var store = new FakeSettingsStore();
|
||||
var vm = NewVm(store);
|
||||
|
||||
var imported = new HotkeyBinding(HotkeyModifiers.Control | HotkeyModifiers.Shift, 0x75);
|
||||
store.Current = store.Current with { CaptureHotkey = imported };
|
||||
store.RaiseChanged();
|
||||
|
||||
vm.CurrentBinding.Should().Be(imported);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryCommitRecorded_WhileHotkeyServiceRunning_LiveRebinds()
|
||||
{
|
||||
var store = new FakeSettingsStore();
|
||||
var hotkeys = Substitute.For<IHotkeyService>();
|
||||
// Service "running" means CurrentBinding is non-null.
|
||||
hotkeys.CurrentBinding.Returns(HotkeyBinding.Default);
|
||||
var vm = NewVm(store, hotkeys: hotkeys);
|
||||
vm.StartRecordingCommand.Execute(null);
|
||||
|
||||
var candidate = new HotkeyBinding(HotkeyModifiers.Control | HotkeyModifiers.Alt, 0x78);
|
||||
vm.TryCommitRecorded(candidate);
|
||||
|
||||
hotkeys.Received(1).SetBinding(candidate);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryCommitRecorded_WhileHotkeyServiceStopped_SkipsLiveRebind()
|
||||
{
|
||||
var store = new FakeSettingsStore();
|
||||
var hotkeys = Substitute.For<IHotkeyService>();
|
||||
hotkeys.CurrentBinding.Returns((HotkeyBinding?)null);
|
||||
var vm = NewVm(store, hotkeys: hotkeys);
|
||||
vm.StartRecordingCommand.Execute(null);
|
||||
|
||||
vm.TryCommitRecorded(new HotkeyBinding(HotkeyModifiers.Control | HotkeyModifiers.Alt, 0x78));
|
||||
|
||||
hotkeys.DidNotReceive().SetBinding(Arg.Any<HotkeyBinding>());
|
||||
}
|
||||
|
||||
// -- helpers --------------------------------------------------------------
|
||||
|
||||
private sealed class FakeSettingsStore : ISettingsStore
|
||||
{
|
||||
public AppSettings Current { get; set; } = new();
|
||||
public int UpdateCallCount { get; private set; }
|
||||
public event EventHandler? Changed;
|
||||
public string SettingsFilePath => "fake://settings.json";
|
||||
|
||||
public Task LoadAsync(CancellationToken ct = default) => Task.CompletedTask;
|
||||
public Task FlushAsync(CancellationToken ct = default) => Task.CompletedTask;
|
||||
public Task ExportAsync(string p, CancellationToken ct = default) => Task.CompletedTask;
|
||||
public Task ImportAsync(string p, CancellationToken ct = default) => Task.CompletedTask;
|
||||
|
||||
public void Update(Func<AppSettings, AppSettings> mutator)
|
||||
{
|
||||
UpdateCallCount++;
|
||||
Current = mutator(Current);
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void RaiseChanged() => Changed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private sealed class NullLocalizationService : ILocalizationService
|
||||
{
|
||||
public CultureInfo CurrentCulture => CultureInfo.InvariantCulture;
|
||||
public TextFlowDirection CurrentFlowDirection => TextFlowDirection.LeftToRight;
|
||||
public IReadOnlyList<CultureInfo> SupportedCultures { get; } = new[] { CultureInfo.InvariantCulture };
|
||||
public string this[string key] => string.Empty;
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged { add { } remove { } }
|
||||
public event EventHandler? CultureChanged { add { } remove { } }
|
||||
|
||||
public void SetCulture(CultureInfo culture) { }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user