Skip to content

Commit 6270891

Browse files
committed
fix: reset backgroundedAt correctly
1 parent 5b9154a commit 6270891

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/ios/Ldk.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,14 +532,15 @@ class Ldk: NSObject {
532532
@objc
533533
func restartOnForeground() {
534534
let secondsSinceBackgrounded = Date().timeIntervalSince(backgroundedAt ?? .distantPast)
535+
backgroundedAt = nil
536+
535537
guard secondsSinceBackgrounded > 5 else {
536538
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Skipping restart. App was only backgrounded \(Int(secondsSinceBackgrounded))s ago")
537539
return
538540
}
539541

540542
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Restarting LDK on move to foreground. App was backgrounded \(Int(secondsSinceBackgrounded))s ago")
541543

542-
backgroundedAt = nil
543544
restart { _ in } reject: { _, _, _ in }
544545
}
545546

@@ -729,6 +730,11 @@ class Ldk: NSObject {
729730
func addPeer(_ address: NSString, port: NSInteger, pubKey: NSString, timeout: NSInteger, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
730731
// timeout param not used. Only for android.
731732

733+
if backgroundedAt != nil {
734+
// Give it a second maybe it's just restarting
735+
sleep(1)
736+
}
737+
732738
guard backgroundedAt == nil else {
733739
LdkEventEmitter.shared.send(withEvent: .native_log, body: "App was backgrounded, skipping addPeer()")
734740
return handleResolve(resolve, .add_peer_skipped)

0 commit comments

Comments
 (0)