Skip to content

feat: sync app settings across devices via Matrix account data#515

Merged
7w1 merged 7 commits intoSableClient:devfrom
Just-Insane:feat/settings-sync
Mar 25, 2026
Merged

feat: sync app settings across devices via Matrix account data#515
7w1 merged 7 commits intoSableClient:devfrom
Just-Insane:feat/settings-sync

Conversation

@Just-Insane
Copy link
Contributor

@Just-Insane Just-Insane commented Mar 24, 2026

Description

Adds cross-device settings sync by storing Sable's app settings in a Matrix account data event (moe.sable.app.settings). Change a setting on one device and it propagates to your other sessions automatically.

Fixes #

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

AI disclosure:

  • Partially AI assisted (clarify which code was AI assisted and briefly explain what it does).
  • Fully AI generated (explain what all the generated code does in moderate detail).

What the generated code does:

settingsSync.ts — Serialise/deserialise helpers that convert the settings state to/from the account data wire format. Unknown keys are preserved so older clients don't silently drop data from newer ones.

useSettingsSync.ts — The main sync hook. On mount it reads any existing account data and merges it into local state. It then listens for live updates from other devices via ClientEvent.AccountData. Uploads are debounced by 2 seconds and each one embeds a random synctoken; when the server echoes the event back, the hook recognises its own token and skips re-applying it. Exposes settingsSyncStatusAtom and settingsSyncLastSyncedAtom for UI feedback.

General.tsx — Adds a "Sync settings across devices" toggle and a JSON export/import section for manually backing up and restoring settings.

ClientNonUIFeatures.tsx — Mounts the sync hook once at the client root so it stays active for the whole session.

settings.ts — Adds settingsSyncEnabled: boolean (default false) to the settings atom.

Type files — Registers moe.sable.app.settings in the account data type registry so SDK callbacks are typed correctly.

Tests cover the serialise/deserialise helpers, load-on-mount, merge behaviour, echo-loop skipping, debounced uploads, and error states.

@Just-Insane Just-Insane marked this pull request as ready for review March 24, 2026 16:26
@Just-Insane Just-Insane requested review from 7w1 and hazre as code owners March 24, 2026 16:26
@dozro dozro self-requested a review March 24, 2026 17:32
@dozro
Copy link
Contributor

dozro commented Mar 24, 2026

Syncs Sable application settings across devices using Matrix account data (custom event type app.sable.settings)

shouldn’t the event type be moe.sable.xyz and not app.sable.xyz?

as we don’t have the right to the app.sable namespace, see https://spec.matrix.org/unstable/#namespacing

@Just-Insane
Copy link
Contributor Author

Just-Insane commented Mar 24, 2026

Syncs Sable application settings across devices using Matrix account data (custom event type app.sable.settings)

shouldn’t the event type be moe.sable.xyz and not app.sable.xyz?

Hmm, probably yea - actually, it's correct in the source, just wrong in the description

@Just-Insane
Copy link
Contributor Author

@dozro should be good now for those changes.

- Add SableSettings account data event type (moe.sable.app.settings)
- Add settingsSyncEnabled setting (default off, device-local)
- serializeForSync/deserializeFromSync utilities with versioned schema
- Echo-token loop prevention: own uploads don't re-apply on echo
- Debounced (2 s) upload on settings change
- JSON export (browser download) and import (file picker)
- SettingsSyncSection in General settings with sync toggle, status, and export/import buttons
- 39 new tests covering utilities and hook behaviour
Copy link
Contributor

@dozro dozro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm now :3

@7w1 7w1 added this pull request to the merge queue Mar 25, 2026
Merged via the queue into SableClient:dev with commit b6306c8 Mar 25, 2026
9 checks passed
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.

3 participants