-
Notifications
You must be signed in to change notification settings - Fork 1
fix: avoid showing sync failed immediately when app comes to foreground #359
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
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ovitrif
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.
utAck
maybe 1 little nit:
could use init instead of initialize/ initialization in fn names 🙏🏻
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…m/synonymdev/bitkit-ios into fix/sync-failed-coming-foreground
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ovitrif
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.
re utAck
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Pull request overview
This PR prevents the Lightning node from stopping immediately when the app goes to background and fixes the app status indicator from showing sync failures during app lifecycle transitions.
Changes:
- Adds a 90-second delay before stopping the node when app goes to background
- Introduces a cache layer in LightningService to avoid blocking UI thread with synchronous LDK calls
- Updates test code to use async/await pattern with MainActor isolation
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Bitkit/Utilities/ScenePhase.swift | Implements delayed node stop with cancellation logic for quick foreground returns |
| Bitkit/Services/LightningService.swift | Adds MainActor-isolated cache for node state to prevent blocking UI thread |
| Bitkit/ViewModels/AppViewModel.swift | Renames status initialization flag and adds reset method for background transitions |
| Bitkit/Components/AppStatus.swift | Updates to use renamed status initialization flag |
| Bitkit/Utilities/AppStatusHelper.swift | Changes stopped/stopping states to show pending instead of error |
| Bitkit/Views/Settings/AppStatusView.swift | Switches from syncState to async syncStateAsync |
| Bitkit/ViewModels/WalletViewModel.swift | Adds concurrent start guard and async state sync method |
| Bitkit/Utilities/StateLocker.swift | Converts blocking Thread.sleep to async Task.sleep |
| BitkitTests/StateLockerTests.swift | Updates tests to use async/await pattern |
| BitkitTests/UtxoSelectionTests.swift | Wraps LightningService property access with MainActor.run |
| BitkitTests/ChannelPurchaseFlow.swift | Wraps LightningService property access with MainActor.run |
| BitkitNotification/NotificationService.swift | Wraps channel and peer access with MainActor.run |
| Bitkit/Services/TransferService.swift | Wraps LightningService property access with MainActor.run |
| Bitkit/Services/CoreService.swift | Wraps LightningService property access with MainActor.run |
| Bitkit/Managers/PushNotificationManager.swift | Wraps status check with MainActor.run |
| Bitkit/Managers/BalanceManager.swift | Wraps balance and channel access with MainActor.run |
| Bitkit/AppScene.swift | Calls markAppStatusInit when node reaches running state |
| // Cancel any existing scheduled stop | ||
| stopNodeWorkItem?.cancel() | ||
|
|
||
| let workItem = DispatchWorkItem { [self] in |
Copilot
AI
Jan 19, 2026
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 capture list [self] creates a strong reference which could lead to retain cycles if the work item outlives the view. Use [weak self] instead and add a guard statement to safely unwrap self.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
pwltr
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.
Looks all good to me, briefly tested on simulator
Prevent node from stopping immediately when going to background and fix app getting stuck on app status