Skip to content

feat: sync connection settings across browsers via chrome.storage.sync#9

Merged
mkobayashime merged 5 commits intomainfrom
sync-connections
Feb 5, 2026
Merged

feat: sync connection settings across browsers via chrome.storage.sync#9
mkobayashime merged 5 commits intomainfrom
sync-connections

Conversation

@mkobayashime
Copy link
Copy Markdown
Owner

Summary

  • Split the monolithic Connection type into ConnectionConfig (synced) and ConnectionState (local), keeping the merged type for backward compatibility.
  • Rewrite lib/storage/connections.ts to use chrome.storage.sync for repo settings and chrome.storage.local for per-browser state (folder IDs, sync timestamps).
  • Add lib/storage/orphan-configs.ts to auto-resolve configs that arrive via sync but have no local state yet (recreates the bookmark folder hierarchy at the synced path), and to clean up local state when a connection is deleted on another browser.
  • Wire both routines into App.tsx: run on mount and re-run whenever the sync store changes, keeping the UI up to date without a reload.

Design decisions

  • Last-write-wins for config conflicts — users typically configure on one browser at a time.
  • Orphan resolution is silent (no toast); the next periodic sync (60 min) handles the actual bookmark creation for newly resolved connections.
  • targetFolderPath is included in the synced config specifically so the folder hierarchy can be recreated on other browsers.

Test plan

  • Add a connection on Browser A; verify it appears on Browser B after a short delay (auto-resolved, folder created)
  • Verify no notification is shown on Browser B for the auto-resolved connection
  • Disable a connection on Browser A; verify it becomes disabled on Browser B
  • Delete a connection on Browser A; verify it disappears from Browser B after cleanup
  • Sync on Browser A; verify lastSyncedAt on Browser B remains unchanged (state independence)
  • Verify existing connections still work end-to-end after the storage layout change

- groovy-tumbling-clover.md: detailed implementation plan covering type
  splits, dual-storage layout, orphan resolution, migration, and
  verification steps
- sync-connections.md: original requirement in Japanese
Partition the flat Connection type into two concerns:
- ConnectionConfig: repo settings and enabled flag, intended for
  chrome.storage.sync
- ConnectionState: browser-specific folder ID and sync timestamps, stays
  in chrome.storage.local

The merged Connection = ConnectionConfig & ConnectionState type is
retained so call sites require no changes.  Also add the store-level
Record types (SyncConnectionsStore, LocalConnectionStateStore).
Replace the single chrome.storage.local array with a split layout:
- Connection configs live in chrome.storage.sync under
  "sync:gitmarks_connections" so they propagate across browsers
  automatically.
- Per-browser state (folder IDs, sync timestamps) stays in
  chrome.storage.local under "local:gitmarks_connection_state".

connections.ts changes:
- getConnections merges the two stores, returning only fully-resolved
  entries (both config and state present).
- saveConnection / updateConnection route fields to the correct store;
  updateConnection auto-detects config vs state keys.
- removeConnection deletes from both stores atomically.
- Expose getSyncConfigs / getLocalStates for use by orphan resolution.

New orphan-configs.ts:
- getOrphanConfigs: finds configs synced from another browser that have
  no local state yet.
- autoResolveOrphanConfigs: recreates the bookmark folder hierarchy at
  the synced path and initialises local state, returning the count of
  newly resolved connections.
- cleanupDeletedConnections: removes local state for connections whose
  config has been deleted on another browser.
On mount, run cleanupDeletedConnections (removes stale local state) and
autoResolveOrphanConfigs (creates folders + local state for configs that
arrived via chrome.storage.sync from another browser), then refresh the
connection list.

Also listen to chrome.storage.onChanged: when the sync store changes,
repeat cleanup + resolution and refresh if any new connections were
resolved.  This keeps the UI in sync without a page reload when a
connection is added or removed on another browser.
Document the new cross-browser sync model: ConnectionConfig/
ConnectionState type split, dual chrome.storage layout, orphan-config
resolution flow, and the updated data-flow and storage-architecture
sections.
@mkobayashime mkobayashime merged commit e50b97b into main Feb 5, 2026
1 check passed
@mkobayashime mkobayashime deleted the sync-connections branch February 5, 2026 00:22
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.

1 participant