diff --git a/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift b/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift index bebb2427..28591886 100644 --- a/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift @@ -217,9 +217,7 @@ class OrganizerViewController: UITableViewController, TableModelHost { // } tableView.endUpdates() - let _ = service.removeProfile(rowProfile) - splitViewController?.serviceViewController?.hideProfileIfDeleted() - TransientStore.shared.serialize() // delete + service.removeProfile(rowProfile) } private func confirmVpnProfileDeletion() { @@ -453,15 +451,22 @@ extension OrganizerViewController: ConnectionServiceDelegate { } func connectionService(didRemoveProfileWithKey key: ConnectionService.ProfileKey) { - reloadModel() - tableView.reloadData() + TransientStore.shared.serialize() // delete + + splitViewController?.serviceViewController?.hideProfileIfDeleted() } - func connectionService(didDeactivate profile: ConnectionProfile) { + // XXX: deactivate + activate leads to a redundant serialization + + func connectionService(willDeactivate profile: ConnectionProfile) { + TransientStore.shared.serialize() // deactivate + tableView.reloadData() } func connectionService(didActivate profile: ConnectionProfile) { + TransientStore.shared.serialize() // activate + tableView.reloadData() } } diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index 488e0f6f..79fc17ac 100644 --- a/Passepartout-iOS/Scenes/ServiceViewController.swift +++ b/Passepartout-iOS/Scenes/ServiceViewController.swift @@ -186,7 +186,6 @@ class ServiceViewController: UIViewController, TableModelHost { private func activateProfile() { service.activateProfile(uncheckedProfile) - TransientStore.shared.serialize() // activate reloadModel() tableView.reloadData() diff --git a/Passepartout/Sources/Model/ConnectionService.swift b/Passepartout/Sources/Model/ConnectionService.swift index 9e9b5bc8..637ec8f1 100644 --- a/Passepartout/Sources/Model/ConnectionService.swift +++ b/Passepartout/Sources/Model/ConnectionService.swift @@ -37,9 +37,9 @@ protocol ConnectionServiceDelegate: class { func connectionService(didRemoveProfileWithKey key: ConnectionService.ProfileKey) - func connectionService(didActivate profile: ConnectionProfile) + func connectionService(willDeactivate profile: ConnectionProfile) - func connectionService(didDeactivate profile: ConnectionProfile) + func connectionService(didActivate profile: ConnectionProfile) } class ConnectionService: Codable { @@ -120,7 +120,7 @@ class ConnectionService: Codable { private(set) var activeProfileKey: ProfileKey? { willSet { if let oldProfile = activeProfile { - delegate?.connectionService(didDeactivate: oldProfile) + delegate?.connectionService(willDeactivate: oldProfile) } } didSet { @@ -342,13 +342,10 @@ class ConnectionService: Codable { activeProfileKey = key } - // serialize immediately - saveProfiles() - delegate?.connectionService(didAdd: profile) } - func renameProfile(_ key: ProfileKey, to newId: String) -> ConnectionProfile? { + @discardableResult func renameProfile(_ key: ProfileKey, to newId: String) -> ConnectionProfile? { precondition(newId != key.id) // WARNING: can be a placeholder @@ -381,16 +378,13 @@ class ConnectionService: Codable { activeProfileKey = newKey } - // serialize immediately - saveProfiles() - delegate = temporaryDelegate delegate?.connectionService(didRename: oldProfile, to: newProfile) return newProfile } - func renameProfile(_ profile: ConnectionProfile, to id: String) -> ConnectionProfile? { + @discardableResult func renameProfile(_ profile: ConnectionProfile, to id: String) -> ConnectionProfile? { return renameProfile(ProfileKey(profile), to: id) }