nostrdb: close database when backgrounded

Otherwise iOS gets mad because we are holding onto a lockfile in a
shared container which is apparently not allowed.

Fixes: a1e6be214e ("Migrate NostrDB files to shared app group file container")
This commit is contained in:
William Casarin
2023-12-11 12:44:40 -08:00
parent c7cc8df5ba
commit da2bdad18d
3 changed files with 67 additions and 8 deletions

View File

@@ -448,18 +448,25 @@ struct ContentView: View {
break
}
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { obj in
print("📙 DAMUS ACTIVE NOTIFY")
try? damus_state.ndb.reopen()
}
.onChange(of: scenePhase) { (phase: ScenePhase) in
guard let damus_state else { return }
switch phase {
case .background:
print("📙 DAMUS BACKGROUNDED")
Task { @MainActor in
damus_state.ndb.close()
}
break
case .inactive:
print("📙 DAMUS INACTIVE")
break
case .active:
print("📙 DAMUS ACTIVE")
guard let ds = damus_state else { return }
ds.pool.ping()
damus_state.pool.ping()
@unknown default:
break
}