Skip to content

Consolidate repeated App-layer patterns and reduce duplication - #29

Merged
DysektAI merged 2 commits into
masterfrom
devin/deduplicate-quick-wins
Jul 30, 2026
Merged

Consolidate repeated App-layer patterns and reduce duplication#29
DysektAI merged 2 commits into
masterfrom
devin/deduplicate-quick-wins

Conversation

@DysektAI

@DysektAI DysektAI commented Jul 30, 2026

Copy link
Copy Markdown
Member

Summary

This is a focused cleanup pass that removes obvious, low-risk duplication across src/App without changing product behavior.

  • SimpleConfig: replaced six nearly-identical try { parse(...) } catch { return defaultValue; } read methods with one ReadOrDefault<T> helper.
  • TarkovDev/JsonApiModels: extracted Identifiable / Entity / NamedEntity base classes so the id, name, and normalizedName JSON properties are declared once.
  • TarkovDevAPI: offline cache loading now reuses the existing MaterializeCachedArray method (removing six duplicated JsonConvert.DeserializeObject lambdas), and the craft/barter fetch methods now share a generic FetchJObjectListAsync<T> pipeline.
  • ItemExtensions: merged the identical mark and buildWeapon objective branches into a single pattern check.
  • MapDataLoader: replaced four repeated cache-reset assignments with a ResetCache helper.
  • TarkovTrackerDB: extracted the token/endpoint/mode equality check into IsCurrentConfiguration and called it from both Configure and token validation.
  • ActiveHotkey: collapsed four constructor overloads into two constructors plus a shared Initialize method, removing duplicated listener wiring.
  • Logger: ProcessBacklog and Flush now share a single FlushBacklogLocked implementation.
  • UserActivityHelper: added ThrowLastWin32Error and used it for the three identical Marshal.GetLastWin32Error() / new Win32Exception(...) blocks.

All changes were validated with:

dotnet build RatScanner.sln
dotnet test RatScanner.sln
dotnet tool restore && dotnet csharpier check .

(dotnet was not initially on PATH; the .NET 10 SDK was installed via Chocolatey and RatEye submodules were initialized before building.)

Link to Devin session: https://app.devin.ai/sessions/dd0b650ddf6e4ff69c9a1061d1667e5f
Requested by: @DysektAI


Open in Devin Review

Summary by cubic

Consolidates repeated App-layer patterns to reduce duplication and centralize logic. No behavior changes; improves readability and maintenance.

  • Refactors
    • Config: added ReadOrDefault and condensed read methods (string, secure string, int, float, bool, enum lists).
    • API: offline cache now uses MaterializeCachedArray; crafts/barters share FetchJObjectListAsync; simplified TryLoadFromOfflineCache.
    • Models: introduced Identifiable/Entity/NamedEntity base classes to dedupe id/name/normalizedName.
    • Hotkeys: reduced constructors to two and centralized setup via Initialize; tightened nullability.
    • Items: unified mark and buildWeapon objective handling.
    • Maps: added ResetCache helper for repeated cache clears.
    • Tracker DB: extracted IsCurrentConfiguration for token/endpoint/mode checks.
    • Logger: shared FlushBacklogLocked used by backlog processing and flush.
    • User activity: added ThrowLastWin32Error and preserved original Win32 error code during cleanup rollback.

Written for commit 3d5623e. Summary will update on new commits.

Review in cubic

- SimpleConfig: share try/catch fallback via ReadOrDefault<T>
- TarkovDev/JsonApiModels: extract Identifiable/Entity/NamedEntity base classes
- TarkovDevAPI: reuse MaterializeCachedArray for offline cache loading; share craft/barter fetch through FetchJObjectListAsync<T>
- ItemExtensions: combine duplicate mark/buildWeapon handling
- MapDataLoader: add ResetCache helper for repeated cache clears
- TarkovTrackerDB: add IsCurrentConfiguration helper for token/endpoint/mode checks
- ActiveHotkey: collapse four constructor overloads into two plus Initialize
- Logger: share backlog flush between ProcessBacklog and Flush
- UserActivityHelper: add ThrowLastWin32Error helper for hook failures
@DysektAI DysektAI self-assigned this Jul 30, 2026
@devin-ai-integration

This comment was marked as resolved.

@devin-ai-integration

This comment was marked as resolved.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability when keyboard or mouse activity hooks fail to start or stop.
    • Improved handling of missing map data by safely resetting cached map information.
    • Preserved objective progress calculations for marking and weapon-building tasks.
  • Refactor

    • Improved configuration reading with consistent “read or default” behavior.
    • Centralized logging backlog flushing for more consistent log output.
    • Streamlined offline cache loading and API data processing for crafts/barters.
    • Simplified hotkey and event handling setup; improved internal model reuse for JSON parsing.

Walkthrough

The pull request consolidates repeated helper logic across configuration, logging, cache handling, API parsing, input hooks, and JSON models. It also combines mark/build-weapon objective handling and centralizes current-configuration checks.

Changes

Application refactors

Layer / File(s) Summary
JSON models and API data loading
src/App/TarkovDev/JsonApiModels.cs, src/App/TarkovDevAPI.cs
Shared JSON base classes, query-key-based offline cache materialization, and generic craft/barter envelope parsing are introduced.
Configuration and input helpers
src/App/SimpleConfig.cs, src/App/TarkovTrackerDB.cs, src/App/ActiveHotkey.cs, src/App/UserActivityHelper.cs
Configuration reads, configuration comparisons, hotkey initialization, and Win32 error handling are centralized through shared helpers.
Runtime utility consolidation
src/App/Logger.cs, src/App/MapDataLoader.cs, src/App/ItemExtensions.cs
Backlog flushing, map cache reset behavior, and mark/build-weapon objective matching are consolidated.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: size:XXL

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes the PR's main refactor theme and matches the changeset.
Description check ✅ Passed The description closely matches the refactor-focused changes and is on-topic.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch devin/deduplicate-quick-wins

Comment @coderabbitai help to get the list of available commands.

@codeant-ai

This comment was marked as resolved.

@coderabbitai coderabbitai Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files label Jul 30, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

cubic-dev-ai[bot]

This comment was marked as resolved.

@kilo-code-bot

This comment was marked as resolved.

@DysektAI
DysektAI merged commit 0b8a4af into master Jul 30, 2026
15 checks passed
@DysektAI
DysektAI deleted the devin/deduplicate-quick-wins branch July 30, 2026 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant