close nostrdb and disconnect from relays on logout

This was causing crashing and corruption issues. This should have been
handled by the garbage collector, but for some reason old references
still hang around.

Add a "close" method to DamusState which disconnects from relays and
closes nostrdb.

Changelog-Fixed: Fix crash when logging out and switching accounts
Changelog-Fixed: Fix persistent local notifications even after logout
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-01-10 16:25:07 -08:00
parent 6834367386
commit 4cf92756f1
6 changed files with 30 additions and 7 deletions

View File

@@ -72,7 +72,7 @@ struct ConfigView: View {
Section(NSLocalizedString("Sign Out", comment: "Section title for signing out")) {
Button(action: {
if state.keypair.privkey == nil {
notify(.logout)
logout(state)
} else {
confirm_logout = true
}
@@ -130,7 +130,7 @@ struct ConfigView: View {
return
}
state.postbox.send(ev)
notify(.logout)
logout(state)
}
}
.alert(NSLocalizedString("Logout", comment: "Alert for logging out the user."), isPresented: $confirm_logout) {
@@ -138,7 +138,7 @@ struct ConfigView: View {
confirm_logout = false
}
Button(NSLocalizedString("Logout", comment: "Button for logging out the user."), role: .destructive) {
notify(.logout)
logout(state)
}
} message: {
Text("Make sure your nsec account key is saved before you logout or you will lose access to this account", comment: "Reminder message in alert to get customer to verify that their private security account key is saved saved before logging out.")

View File

@@ -164,7 +164,7 @@ struct SideMenuView: View {
Button(action: {
//ConfigView(state: damus_state)
if damus_state.keypair.privkey == nil {
notify(.logout)
logout(damus_state)
} else {
confirm_logout = true
}
@@ -202,7 +202,7 @@ struct SideMenuView: View {
confirm_logout = false
}
Button(NSLocalizedString("Logout", comment: "Button for logging out the user."), role: .destructive) {
notify(.logout)
logout(damus_state)
}
} message: {
Text("Make sure your nsec account key is saved before you logout or you will lose access to this account", comment: "Reminder message in alert to get customer to verify that their private security account key is saved saved before logging out.")