-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat(mobile): add background cloud sync for mobile app #12138
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
base: master
Are you sure you want to change the base?
Conversation
- Introduce `frontend.mobile.sync-background` namespace to manage cloud sync when the mobile app is backgrounded. - Track app state, network connectivity, and background sync status using atoms. - Provide functions to handle app state and network changes. - Ensure sync only triggers when app is backgrounded, network is connected, and sync is enabled. - Integrate with storage and state modules for sync control. This enables reliable background syncing for mobile users, improving data consistency and user experience. ref: https://discuss.logseq.com/t/logseq-mobile-sync-in-background/17214 Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
…emSynchronizedGroupsEnabled to true in the preferences. Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
- Added iOS background task registration and scheduling in AppDelegate.swift using BGTaskScheduler. - Integrated background sync trigger via JavaScript bridge to webview. - Ensured background sync is scheduled on app launch and when entering background. - Updated Info.plist to support background tasks and required capabilities. - Exposed background sync trigger to JS global in sync_background.cljs for iOS bridge. - This enables Logseq mobile to sync notes in the background, improving reliability and user experience. Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
- Add RECEIVE_BOOT_COMPLETED permission to AndroidManifest.xml - Add MobileSyncService and MobileSyncBootReceiver for background sync - Update MainActivity to support background sync triggers - Enables background sync to run periodically and after device boot Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
|
@tiensonqin and @logseq-cldwalker see if this implementation makes sense for logseq's future |
|
it will make my life better on the mobile app |
|
@logseq-cldwalker @tiensonqin any updates here? |
| (when (should-trigger?) | ||
| (mark-running! true) | ||
| (let [start-ts (.now js/Date)] | ||
| (-> (p/let [_ (fs-sync/<sync-start)] |
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.
The master branch doesn't support file graphs sync on mobile anymore, to start rtc sync, you can call frontend.handler.db-based.rtc/<rtc-start!.
tiensonqin
left a comment
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.
Sorry for the late reply — I wanted to review it thoroughly after some testing, since background sync is critical and I really hope it’s resolved. Unfortunately, I haven’t had time this month because users have been running into bugs like invalid data that prevents them from using Logseq DB (we made some changes to enforce schema validations). So I’ll leave some notes for now.
Overall, the structure looks good! Some parts of the code seem AI-generated 😄
No worries though — we’re not against “vibe coding.” We also use AI quite a bit to generate native code (especially Swift).
We’ve done some research on background sync, and it seems the only truly reliable approach is native sync triggered by push notifications for local refreshes. However, that approach would take significant effort, so we’ve paused it for now.
As far as I know, BGAppRefreshTaskRequest has a hard 30s limit, while BGProcessingTaskRequest runs for around 5–10 minutes. That might actually be enough for our use case, since the DB version only syncs deltas instead of full markdown files.
I’ll run more tests this week.
| print("⚠️ Bridge not ready for background sync") | ||
| return | ||
| } | ||
| bridge.webView?.evaluateJavaScript("window.logseqMobile?.backgroundSync?.trigger?.()") { result, error in |
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.
I don't think we can ensure “sync work is done” when there's no error, is that right?
The web view could be suspended, reloaded or crashed in background, I have no idea how BGTaskScheduler works and how long it can run in background, I'll give it a try later with rtc db graphs.
frontend.mobile.sync-backgroundnamespace to manage cloud sync when the mobile app is backgrounded.This enables reliable background syncing for mobile users, improving data consistency and user experience.
ref: https://discuss.logseq.com/t/logseq-mobile-sync-in-background/17214