Skip to content

Share one AppStateStore across the desktop app - #1224

Merged
alexeyzimarev merged 1 commit into
mainfrom
capacitor/agent-b9703ab6b17342
Sep 29, 2026
Merged

alexeyzimarev merged 1 commit into
mainfrom
capacitor/agent-b9703ab6b17342

Conversation

@alexeyzimarev

Copy link
Copy Markdown
Member

Closes #1223 — AI-3333

What & why

App holds the desktop app's one AppStateStore and hands it to the sign-in dialog, the wizard, the main window and the lifecycle wiring. The store's lock is per instance, so separate stores over app-state.json let two updates read the same snapshot, and the later write erases the earlier one's field.

Constructing a store inside the app project is a build error (BannedSymbols.App.txt), with the one field on App exempted. Most of the composition root is private App methods no test reaches, so the ban is what guards them.

Where to look

  • BuildAndShowMainWindow takes the store as a parameter, so a main window rebuilt after a real close reuses the app's store.
  • A branch that constructs its own store fails the build on RS0030 when it merges main; Choose a surface material for the desktop app #1035 does.

Verification

Check Result
New test against a window that builds its own store Expected to be 1552 but found 1400
Ban with sites still constructing a store error RS0030 at each
dotnet build Capacitor.slnx --no-incremental 16 projects, 0 errors, 0 warnings
dotnet run --project test/Capacitor.App.Tests.Unit 2809 passed, 0 failed

🤖 Generated with Claude Code

The store's lock is per instance, so only one shared instance serializes
writers to app-state.json. Constructing a store in the app project is a
build error, which a branch that builds its own hits when it merges main.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T12:48:18.854734Z c188f17 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Share one AppStateStore across the desktop app

🐞 Bug fix 🧪 Tests ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Share one app-state store across windows, sign-in, wizard, and lifecycle flows to prevent lost
 updates.
• Ban additional store construction in the app project at build time.
• Test that the main window restores and saves state through its supplied store.
Diagram

graph TD
  App["App composition"] --> Store["Shared state store"] --> State[("app-state.json")]
  Store --> SignIn["Sign-in dialog"]
  Store --> Wizard["Wizard mode"]
  Store --> Window["Main window"]
  Store --> Lifecycle["Lifecycle wiring"]
Loading
High-Level Assessment

Keeping one store in the existing App composition root fits its manual wiring and preserves the store's per-instance serialization. A DI singleton would add registration and resolution without improving ownership here; the constructor ban guards against new app-project instances.

Files changed (4) +55 / -16

Bug fix (1) +17 / -10
App.axaml.csOwn and distribute one app-state store +17/-10

Own and distribute one app-state store

• App creates one store and passes it to sign-in, wizard, main-window, and lifecycle components. The main-window factory now accepts a store, so rebuilt windows reuse the same instance.

src/Capacitor.App/App.axaml.cs

Tests (1) +34 / -6
AppStartupTests.csVerify main-window use of the supplied store +34/-6

Verify main-window use of the supplied store

• Passes stores to existing main-window tests and adds a test using a separate state path. It verifies that the window restores and saves through the handed store without creating a file at the config root.

test/Capacitor.App.Tests.Unit/AppStartupTests.cs

Other (2) +4 / -0
BannedSymbols.App.txtBan additional app-state store construction +1/-0

Ban additional app-state store construction

• Defines a build-time ban on calling the AppStateStore constructor from the app project, with guidance to use App's shared store.

src/Capacitor.App/BannedSymbols.App.txt

Capacitor.App.csprojEnable the app-specific constructor ban +3/-0

Enable the app-specific constructor ban

• Includes the new banned-symbols file as an analyzer input for the app project.

src/Capacitor.App/Capacitor.App.csproj

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can add REVIEW.md to your repo root and Qodo follows it on every PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@alexeyzimarev
alexeyzimarev merged commit 493b53e into main Sep 29, 2026
7 checks passed
@alexeyzimarev
alexeyzimarev deleted the capacitor/agent-b9703ab6b17342 branch September 29, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop app loses app-state.json updates across its separate stores

1 participant