-
-
Notifications
You must be signed in to change notification settings - Fork 5
Add preferences service for cross-platform user settings storage #2158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR introduces a new IPreferencesService interface and its MAUI implementation to expose device preferences to JavaScript code via JSInterop. The service is registered in the DI container, exposed through TypeScript type definitions, integrated into the frontend service provider, and utilized in the project storage layer with localStorage fallback support. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
8fb8c26 to
878d684
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@frontend/viewer/src/lib/utils/project-storage.svelte.ts`:
- Around line 56-84: Constructor calls load() fire-and-forget which can race
with set() and allow load() to overwrite `#value` with stale backend data; fix by
adding a simple sequencing guard: introduce a private sequence counter (e.g.
`#writeSeq` or `#initSeq`) on the class, increment it at the start of set(), and in
load() capture the current sequence before awaiting the backend and only assign
this.#value if the captured sequence still equals the current sequence; update
references to constructor, load(), set(), and `#value` accordingly so late load()
results no longer overwrite newer writes.
Add PreferencesService to expose MAUI IPreferences to the TypeScript frontend via JSInterop. When running in MAUI, project storage now uses native preferences instead of localStorage. - Add IPreferencesService interface and PreferencesServiceJsInvokable - Register service in FwLiteProvider and FwLiteMauiKernel - Refactor project-storage.svelte.ts with StorageBackend abstraction - Fall back to localStorage when not running in MAUI https://claude.ai/code/session_01XdJtubGvpeSyetSuA3zfFA
Change API from setter to explicit async method: - `current` getter is reactive and read-only - `set()` is async - callers can await or fire-and-forget - Add error logging for load failures Update TasksView to use onValueChange instead of bind:value. https://claude.ai/code/session_01XdJtubGvpeSyetSuA3zfFA
- Remove redundant StorageBackend interface (identical to IPreferencesService) - Remove PreferencesBackend wrapper class (just a passthrough) - LocalStorageBackend now implements IPreferencesService directly - Make load() async without catch - errors hit global handler - Add IPreferencesService to Services barrel export https://claude.ai/code/session_01XdJtubGvpeSyetSuA3zfFA
IPreferences is a MAUI type, so the implementation must live in FwLiteMaui, not FwLiteShared. The interface (IPreferencesService) remains in FwLiteShared. https://claude.ai/code/session_01XdJtubGvpeSyetSuA3zfFA
If set() is called before load() completes, the #hasBeenSet flag prevents load() from overwriting the user's value with stale data. https://claude.ai/code/session_01XdJtubGvpeSyetSuA3zfFA
4903c7f to
16ae6c9
Compare
Summary
This PR introduces a new
IPreferencesServicethat provides a unified interface for storing user preferences across platforms. When running in MAUI, it uses native MAUI Preferences; otherwise, it falls back to localStorage.Key Changes
Backend (.NET)
IPreferencesServiceinterface withGet(),Set(), andRemove()methodsPreferencesServiceJsInvokablewrapper around MAUI'sIPreferenceswith JSInvokable attributes for JavaScript interopFwLiteProviderto expose the service to JavaScriptFrontend (TypeScript/Svelte)
IPreferencesServiceinterfacetryUsePreferencesService()hook to safely access the preferences serviceLexboxServiceRegistryto include the new serviceProject Storage
ProjectStorageto use the preferences service backendLocalStorageBackendclass implementingIPreferencesServiceas a fallbackStorageProp.set()from synchronous to async to support both MAUI and localStorage backendsTasksView.svelteto properly await async storage operationsImplementation Details
tryUsePreferencesService()returnsundefinedif unavailable)LocalStorageBackendwraps localStorage in an async interface for consistencyproject:{projectCode}:{key}for isolationhttps://claude.ai/code/session_01XdJtubGvpeSyetSuA3zfFA