Skip to content

Commit

Permalink
fix: reset backgroundedAt correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasonvdb committed Sep 23, 2024
1 parent 5b9154a commit 6270891
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ios/Ldk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,15 @@ class Ldk: NSObject {
@objc
func restartOnForeground() {
let secondsSinceBackgrounded = Date().timeIntervalSince(backgroundedAt ?? .distantPast)
backgroundedAt = nil

guard secondsSinceBackgrounded > 5 else {
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Skipping restart. App was only backgrounded \(Int(secondsSinceBackgrounded))s ago")
return
}

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

backgroundedAt = nil
restart { _ in } reject: { _, _, _ in }
}

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

if backgroundedAt != nil {
// Give it a second maybe it's just restarting
sleep(1)
}

guard backgroundedAt == nil else {
LdkEventEmitter.shared.send(withEvent: .native_log, body: "App was backgrounded, skipping addPeer()")
return handleResolve(resolve, .add_peer_skipped)
Expand Down

0 comments on commit 6270891

Please sign in to comment.