Revert "Revert "nostrdb: close database when backgrounded""

This reverts commit 26bd50c948.
This commit is contained in:
William Casarin
2024-01-10 13:19:36 -08:00
parent 909701ce7b
commit 227734d286
3 changed files with 67 additions and 8 deletions
+9 -2
View File
@@ -461,18 +461,25 @@ struct ContentView: View {
.onReceive(handle_notify(.disconnect_relays)) { () in
damus_state.pool.disconnect()
}
.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
}