Repository navigation
🔨 persist configuration through Jetpack DataStore with per-key updates - #5174
Open
guiyanakuang wants to merge 4 commits into
Open
guiyanakuang wants to merge 4 commits into
guiyanakuang wants to merge 4 commits into
Conversation
Replace the single-document appConfig.json (DesktopConfigManager over OneFilePersist) with androidx.datastore preferences, keeping the ConfigManager API every caller uses: - app/commonMain: ConfigKey/ConfigSchema (typed, named keys shared with mobile), ConfigStore (one DataStore file with a corruption handler that quarantines the unreadable file to <name>.corrupt before falling back to defaults), ConfigRepository (routes each key to the store owning it), LegacyJsonConfigImporter (ingests appConfig.json on first launch and archives it as appConfig.json.migrated) and DataStoreConfigManager, the common manager base class. - Settings and runtime state (pasteboard change count, dismissed prompts, restore token, last seen changelog) live in separate files, so exit-time bookkeeping no longer rewrites the user's settings. - Every update is a DataStore transaction touching only the given keys; a write that fails leaves file and snapshot unchanged and is reported. The saveBlocked flag is gone: an unreadable file only costs the session its values, later writes re-read it and never overwrite it with defaults. - DesktopAppConfig.copy(key, value) now resolves keys through the schema instead of a hand-written when chain; DesktopConfigKeysTest keeps the data class, the keys and fromPreferences in sync. - The appInstanceId migration also reads the archived legacy config. Closes #5100
The CLI locates cli-endpoint.json through the app's storage path, which it used to read from appConfig.json. That document is now imported into DataStore and archived on the first launch, so CliConfigReader decodes appConfig.preferences_pb instead: the file is DataStore's PreferenceMap proto, mirrored with kotlinx-serialization-protobuf exactly as DataStore's own non-JVM serializer does, so the CLI needs no DataStore dependency. The legacy JSON document remains the fallback while an older app is installed.
guiyanakuang
force-pushed
the
feature/datastore-config-persistence
branch
from
October 8, 2026 12:50
809b26b to
6fe6055
Compare
…fig-persistence # Conflicts: # app/src/desktopMain/kotlin/com/crosspaste/config/DesktopAppConfig.kt # app/src/desktopTest/kotlin/com/crosspaste/i18n/GlobalCopywriterTest.kt
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #5100.
Replaces the single-document
appConfig.json(DesktopConfigManageroverOneFilePersist) withandroidx.datastore:datastore-preferences-corewhile keeping theConfigManagerAPI every caller uses, so none of the ~80updateConfigcall sites change.Persistence (
app/src/commonMain/.../config)ConfigKey/ConfigSchema: typed, named keys (booleanConfigKey("port"), ...). The sharedAppConfigproperties live inAppConfigKeys, desktop-only ones inDesktopConfigKeys.ConfigStore: one DataStore preferences file. Its corruption handler quarantines an unparseable file to<name>.corruptbefore falling back to empty preferences; if even that move fails the read error is surfaced and nothing is written, so a file that can be neither read nor preserved is never replaced.ConfigRepository: routes each key to the store owning it, one transaction per store.LegacyJsonConfigImporter: on first launch imports every known key ofappConfig.jsonand renames it toappConfig.json.migrated; an unparseable document is quarantined to.corruptand ignored.DataStoreConfigManager: the common manager base. Each update is a DataStore transaction touching only the given keys and becomes visible in theStateFlowonce it persisted; a failed write leaves file and snapshot unchanged and is reported (desktop: the existingfailed_to_save_confignotification). ThesaveBlockedflag is gone: a store that cannot be read only costs the session its values, every later write re-reads the file and can never overwrite it with defaults.Separation of settings and runtime state
User settings go to
appConfig.preferences_pb;lastPasteboardChangeCount,lastSeenChangelogVersion,networkBlockingDismissedFingerprintandlinuxRemoteDesktopRestoreTokengo toappState.preferences_pb(ConfigScope.RUNTIME_STATE), so exit-time bookkeeping no longer rewrites the user's settings file.Desktop
DesktopAppConfig.copy(key, value)resolves keys through the schema instead of the 150-line hand-writtenwhenchain; an unknown key now throws instead of being silently ignored.DesktopAppConfig.fromPreferencesis the single mapping from stored values to the snapshot.DesktopConfigManager(configDir, localeUtils)builds both stores and the legacy importer;CrossPaste.bootstrap()passes the user directory.appInstanceIdmigration also reads the archived legacy document, so the identity fallback for a corrupt.metadatakeeps working after the import.CLI
The CLI located
cli-endpoint.jsonthroughappConfig.json, which is now archived after the import.CliConfigReaderdecodesappConfig.preferences_pbinstead: the file is DataStore'sPreferenceMapproto, mirrored withkotlinx-serialization-protobufexactly as DataStore's own non-JVM serializer does, so the CLI needs no DataStore dependency (which does not shipmingwX64). The legacy JSON stays as the fallback while an older app is installed.Deviation from the issue
The issue places the code in
shared/commonMain. DataStore publishes nomingwX64artifact andsharedcompiles itscommonMainfor the Windows CLI target, so the implementation lives inapp/src/commonMain(the directory shared with the mobile apps perCLAUDE.md) with the platform factory indesktopMain.Test plan
./gradlew app:desktopTest—DesktopConfigManagerTest(defaults, per-key and batch updates, persistence across instances, settings/state file separation, corrupt store quarantine, unreadable store never overwritten, legacy JSON import and archive, corrupt legacy JSON, wrong-typed legacy values, durable update and write-failure semantics),DesktopConfigKeysTest(data class, keys andfromPreferencesstay in sync; runtime-state scope),DesktopAppMetadataMigrationTest(archived legacy fallback), updatedDesktopAppConfigTest../gradlew :cli:linuxX64Test(or the host target) —CliConfigReaderTestdecodes a hand-encodedPreferenceMap, falls back to the legacy JSON, and defaults on an unreadable file.appConfig.jsonis imported on first launch, archived asappConfig.json.migrated, settings survive a restart, andcrosspaste statusstill finds the endpoint of an app with a custom storage path.