I noticed this evening that my song lists look to have stopped syncing – possibly a re-emergence of #240 – but in the process of trying to test things on my end I noticed that the manual sync/repair sync buttons that are available on the web profile don’t exist in the mobile app. Having that available would provide a quicker way of resetting the sync than the other available option of deleting and reinstalling the app.
Formatted title: feat(sync): add manual sync and repair sync controls in mobile settings
Codebase Analysis & Implementation Touchpoints:
Pigeon Native Bridge API Interface ([hfw_native_api.dart](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw_flutter/pigeons/hfw_native_api.dart#L628-L791)):
In [packages/hfw_flutter/pigeons/hfw_native_api.dart](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw_flutter/pigeons/hfw_native_api.dart#L628-L791), declare @async void triggerManualSync() and @async void repairSync() on HfwHeadlessFlutterApi.
Expose sync status flags in NativeAppStateDto (such as isSyncing: bool, isConnected: bool, isRepairingSync: bool, lastSyncRepairMessage: String?) so native UI platforms can render real-time connection status badges mirroring the Jaspr web app.
In [packages/hfw_flutter/lib/src/native_bridge/hfw_headless_coordinator.dart](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw_flutter/lib/src/native_bridge/hfw_headless_coordinator.dart#L988-L1670), implement triggerManualSync() to flush pending ps_crud operations, trigger a PowerSync sync cycle via getIt<PowerSyncDatabase>(), and push updated list/search states.
Implement repairSync() mirroring the web implementation in [packages/hfw_jaspr/lib/services/web_app_store_web.dart](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw_jaspr/lib/services/web_app_store_web.dart#L1408-L1475):
Disconnect and reconnect the local PowerSyncDatabase connector.
Execute _sanitizePsCrudQueue(preserveUserListsAndItems: true) to purge poisonous/stuck non-list crud operations without dropping local user edits.
Re-trigger _migrateGuestListsToUser(userId) and _reconcileLocalListsToServer(userId).
Refresh user authentication credentials via _authService.
In [HfwAccountSettingsSheet](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw_flutter/ios/Runner/HfwListsAndSettingsViews.swift#L3240-L3700), add a “Cloud Sync & Storage” card section displaying sync connection status, a “Sync Now” button, and a “Repair Sync & Clear Cache” option with explanatory subtitle (“Refreshes authentication, cleans stuck sync queues, and reconnects PowerSync without signing out”).
In [HfwAuthSheet](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw_flutter/ios/Runner/HfwSearchViews.swift#L2106-L2210), surface the quick sync trigger in authenticatedProfileSections.
In [HfwSettingsAndAuthComposeViews.kt](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw_flutter/android/app/src/main/kotlin/com/appleeducate/hfw/HfwSettingsAndAuthComposeViews.kt), add the equivalent “Cloud Sync” section in Compose settings with “Sync Now” and “Repair Sync” buttons hooked into HfwStore.
Add unit tests in [packages/hfw_flutter/test/native_bridge/hfw_native_bridge_test.dart](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw_flutter/test/native_bridge/hfw_native_bridge_test.dart) validating that triggerManualSync() and repairSync() execute successfully and broadcast state changes.
In packages/hfw_flutter/lib/src/native_bridge/hfw_headless_coordinator.dart, _reconcileLocalListsToServer(userId) (line 1611) is guarded by _reconciledListUserIds.add(cleanUid), so it only runs once per app process.
Additionally, hfw_headless_coordinator.dart does not subscribe to PowerSyncDatabase.statusStream or trigger _database.connect() on manual retry, leaving users with no way to recover a stalled PowerSync session short of reinstalling.
final String? lastSyncRepairMessage; (Coordinate regeneration with #272’s Pigeon additions to avoid duplicate codegen.)
Mapping Web syncNow() / repairSyncAndClearCache() (hfw_jaspr/.../web_app_store_web.dart:1402-1492) to Mobile (hfw_headless_coordinator.dart):
Subscribe to getIt<PowerSyncDatabase>().statusStream in _ensureInitialized() to keep isConnected / isSyncing updated via _pushAppState().
triggerManualSync():
If authenticated, refresh auth/entitlements (_refreshOfferingsAndEntitlements(refreshAuthSession: true)), migrate guest lists (_migrateGuestListsToUser(uid)), clear _reconciledListUserIds.remove(uid), and run _reconcileLocalListsToServer(uid).
Call _database.connect() (packages/hfw_core/lib/src/services/powersync/database.dart:267-317, which cleanly disconnects and reconnects HttpPowerSyncConnector).
Push refreshed _pushListsExplorerState(), _pushSearchState(), and _pushAppState().
repairSync() (preserves local user lists/edits without signing out):
Guard with _isRepairingSync flag and push state.
Refresh auth token/session & entitlements; run _migrateGuestListsToUser(uid).
Clean transient guest history (DELETE FROM user_hymn_history WHERE LOWER(COALESCE(user_id, '')) = 'local_guest') and run _sanitizePsCrudQueue(preserveUserListsAndItems: _authService.isAuthenticated, targetUserId: uid).
Clear _reconciledListUserIds.clear() and re-run _reconcileLocalListsToServer(uid).
Reconnect PowerSync via _database.connect() and refresh list/search/app state; set lastSyncRepairMessage and emit banner.
Native UI & Tests:
iOS: Add a Cloud Sync card in HfwAccountSettingsSheet (HfwListsAndSettingsViews.swift) with connection badge, Sync Now, and Repair Sync & Clear Stale Cache buttons (plus quick Sync Now in HfwAuthSheet in HfwSearchViews.swift).
Android: Add matching Cloud Sync controls in HfwSettingsAndAuthComposeViews.kt wired through HfwStore.
Tests: Add unit tests in packages/hfw_flutter/test/native_bridge/hfw_native_bridge_test.dart covering triggerManualSync(), repairSync(), and preservation of user_lists/user_list_items in ps_crud.
Landed in commit 101b79e on main: added triggerManualSync() and repairSync() Pigeon RPCs + live PowerSync statusStream fields (isSyncing, isConnected, isRepairingSync, lastSyncRepairMessage) in hfw_headless_coordinator.dart (with forced _reconcileLocalListsToServer and hfw_jaspr repair parity), and wired Cloud Sync controls (status badge, Sync Now, Repair Sync with confirmation, feedback message) in both iOS HfwAccountSettingsSheet and Android HfwSettingsAndAuthComposeViews.kt. Verified across Flutter tests (41/41), iOS xcodebuild, and Android Gradle tests.
Thanks for the suggestion! We’ve added a Cloud Sync section in mobile Settings (iOS & Android) showing live sync status along with Sync Now and Repair Sync controls—matching the web app—plus a fix for song lists stalling on sync. This will be available in the next app update.